<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi there,
<br>
<br>
your post suggests you are using an outdated version of adegenet - na.replace and some  arguments you are using have been removed from the package since version 2.0.0. This means you have been consulting an outdated version of the tutorials.. where did you
 find it? If there is outdated doc around I need to get rid of it.<br>
<br>
Please update to the devel version (2.0.1) from github:<br>
<a href="https://github.com/thibautjombart/adegenet" target="_blank">https://github.com/thibautjombart/adegenet</a><br>
<br>
Current tutorials should answer your first question. Missing data are detected automatically if the right format is used. Let's wait to make sure your data were imported fine for the others.<br>
<div><br>
Cheers<br>
Thibaut<br>
<div style="font-family:Tahoma; font-size:13px">
<div class="BodyFragment"><font size="2"><span style="font-size:10pt">
<div class="PlainText">                <br>
==============================<br>
Dr Thibaut Jombart<br>
MRC Centre for Outbreak Analysis and Modelling<br>
Department of Infectious Disease Epidemiology<br>
Imperial College - School of Public Health<br>
Norfolk Place, London W2 1PG, UK<br>
Tel. : 0044 (0)20 7594 3658<br>
http://sites.google.com/site/thibautjombart/<br>
http://sites.google.com/site/therepiproject/<br>
http://adegenet.r-forge.r-project.org/<br>
Twitter: @thibautjombart<br>
<br>
<br>
</div>
</span></font></div>
</div>
</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF997167"><font color="#000000" face="Tahoma" size="2"><b>From:</b> adegenet-forum-bounces@lists.r-forge.r-project.org [adegenet-forum-bounces@lists.r-forge.r-project.org] on behalf of D. Magdalena Sorger [dm.sorger@gmail.com]<br>
<b>Sent:</b> 09 October 2015 20:00<br>
<b>To:</b> adegenet-forum@lists.r-forge.r-project.org<br>
<b>Subject:</b> [adegenet-forum] problems with na.replace and values for n.pca & n.da<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">
<div style="font-size:12.8px"><span style="font-size:12.8px">Dear all, </span></div>
<div style="font-size:12.8px"><span style="font-size:12.8px"><br>
</span></div>
<div style="font-size:12.8px"><span style="font-size:12.8px">I am trying to constuct a DAPC scatterplot with adegenet and have three questions that after consulting online resources, tutorials, etc. still haven't been answered definitively. </span><br>
</div>
<div style="font-size:12.8px"><span style="font-size:12.8px"><br>
</span></div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px">My data set consists of (diploid) microsatellite data (8 markers) for 20 ant colonies of 9-28 workers each (mean=15), 301 workers total. I have missing data in 7 spots (i.e. individuals with missing data at one or more loci). My
 first question is about reading in the genepop file:</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px"><b>1) What is the proper command for reading in my file in regards to missing data? </b></div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px">I had replaced all missing data ("0000") with "NA" in the genepop file and used the below code assuming that it would recognize my missing data as NA (first line of code) and replace missing values with means (second line):</div>
<br style="font-size:12.8px">
<i style="font-size:12.8px">msts_m2<-read.genepop("BOR-Od_m2_301w.gen",missing="NA")<br>
na.replace(msts_m2,"mean", quiet=FALSE)</i>
<div style="">
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px">However, when I run this code, it informs me that it replaced 119 missing values. This obviously seems too much as it should have only replaced 7. I'm not sure why this isn't working, see output below</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px"><b>OUTPUT:</b></div>
<div style="">
<div style=""><span style="font-size:12.8px"><i>> na.replace(msts_m2,"mean", quiet=FALSE) </i></span></div>
<div style=""><span style="font-size:12.8px"><br>
</span></div>
<div style=""><span style="font-size:12.8px"><i> Replaced 119 missing values </i></span></div>
<div style=""><span style="font-size:12.8px"><i><br>
</i></span></div>
<div style=""><span style="font-size:12.8px"><i>   #####################</i></span></div>
<div style=""><span style="font-size:12.8px"><i>   ### Genind object ### </i></span></div>
<div style=""><span style="font-size:12.8px"><i>   #####################</i></span></div>
<div style=""><span style="font-size:12.8px"><i>- genotypes of individuals - </i></span></div>
<div style=""><span style="font-size:12.8px"><i><br>
</i></span></div>
<div style=""><span style="font-size:12.8px"><i>S4 class:  genind</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@call: read.genepop(file = "BOR-Od_m2_301w.gen", missing = "NA")</i></span></div>
<div style=""><span style="font-size:12.8px"><i><br>
</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@tab:  301 x 93 matrix of genotypes</i></span></div>
<div style=""><span style="font-size:12.8px"><i><br>
</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@ind.names: vector of  301 individual names</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@loc.names: vector of  8 locus names</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@loc.nall: number of alleles per locus</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@loc.fac: locus factor for the  93 columns of @tab</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@all.names: list of  8 components yielding allele names for each locus</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@ploidy:  2</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@type:  codom</i></span></div>
<div style=""><span style="font-size:12.8px"><i><br>
</i></span></div>
<div style=""><span style="font-size:12.8px"><i>Optionnal contents: </i></span></div>
<div style=""><span style="font-size:12.8px"><i>@pop:  factor giving the population of each individual</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@pop.names:  factor giving the population of each individual</i></span></div>
<div style=""><span style="font-size:12.8px"><i><br>
</i></span></div>
<div style=""><span style="font-size:12.8px"><i>@other: - empty -</i></span></div>
</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px">My second and third questions relate to the selection of the # of PCs and the # of discriminant functions to retain. It seems that each time I make slight changes to these numbers, the output changes vastly and so I want to make
 sure I input the proper numbers. </div>
</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px">First I use the find.clusters function, I designate 20 for n.pca here since I have 20 colonies:</div>
<div style="font-size:12.8px">
<div><br>
</div>
<div><i>clusters<-find.clusters(msts_m2,max.n.pca=20)</i></div>
<div><br>
</div>
<div>When asked for the number of PCs to retain I select 30 which is the level at which the points seem to level off. The BIC graph looks nothing like the graph in the vignette (it does not level off but below a certain level shows a downward zigzag pattern)
 so I choose 20 given that I have 20 colonies. </div>
<div><i><br>
</i></div>
<div><i>dapc_m2<-dapc(msts_m2,clusters$grp)</i><i><br>
</i></div>
<div><img src="cid:ii_1504daedf8025696" alt="Inline image 1" style="margin-right:0px" height="214" width="223"><img src="cid:ii_1504daf4b898e88b" alt="Inline image 2" style="font-size:12.8px; margin-right:0px" height="205" width="211"><i><br>
</i></div>
<div>Next, when asked for PCs to retain I again choose the level at which the points start to level off (30) but when asked for discriminant functions to retain, I'm at a loss. I have about 18 relatively constantly decreasing bars. I usually choose the point
 between the first few ones and the rest where there is some kind of bigger (sometimes arbitrary) break and use that number (in this case: 4):</div>
<div><br>
</div>
<div><b>2) How to choose the appropriate number for PCs to retain and discr. functions to retain?</b></div>
<div><b><br>
</b></div>
<div><b><img src="cid:ii_1504db017166e9eb" alt="Inline image 3" style="margin-right:0px" height="193" width="197"><img src="cid:ii_1504db084b5f29b4" alt="Inline image 4" style="margin-right:0px" height="222" width="229"><br>
</b></div>
<div><b><br>
</b></div>
<div><br>
</div>
<div><br>
</div>
<div><i>best.n.pca<-a.score(dapc_m2)</i></div>
<div><i>temp<-optim.a.score(dapc_m2)</i></div>
<div><i><br>
</i></div>
<div>After running the optim.a.score function I receive a graph that tells me at the top "optimal number of PCs". This is the number I put into my last line of code (below) for n.pca, and for n.da I choose the number I used when prompted earlier: </div>
<div><br>
</div>
<div><b>3) Are these the correct numbers to use for this last line of code? </b></div>
<div><br>
</div>
<div><i>dapc_m2<-dapc(msts_m2,n.pca=7,n.da=4)</i></div>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
-- <br>
<div>
<div dir="ltr">
<div>
<div dir="ltr">Magdalena Sorger<br>
____________<br>
Department of Applied Ecology<br>
North Carolina State University<br>
127 David Clark Labs, Box 7617<br>
100 Eugene Brooks Ave.<br>
Raleigh, NC 27695, USA<br>
# <a href="tel:919-513-7464" value="+19195137464" target="_blank">919-513-7464</a><br>
<a href="mailto:dmsorger@ncsu.edu" target="_blank">dmsorger@ncsu.edu</a>
<div><a href="http://www.theantlife.com" target="_blank"><b>www.theantlife.com</b></a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>