<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style id="owaParaStyle" type="text/css">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
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;"><br>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<div>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">Hi there,
<br>
<br>
please check the current tutorials. scaleGen is no longer used, and has been replaced by tab. Then you should be able to feed the resulting object to dapc without problem.<br>
<br>
Cheers<br>
Thibaut<br>
<div><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>
</div>
</span></font></div>
</div>
</div>
<div style="font-family:Times New Roman; color:#000000; font-size:16px">
<hr tabindex="-1">
<div id="divRpF800675" style="direction:ltr"><font color="#000000" face="Tahoma" size="2"><b>From:</b> D. Magdalena Sorger [dm.sorger@gmail.com]<br>
<b>Sent:</b> 15 October 2015 02:36<br>
<b>To:</b> Jombart, Thibaut<br>
<b>Cc:</b> adegenet-forum@lists.r-forge.r-project.org<br>
<b>Subject:</b> Re: [adegenet-forum] problems with na.replace and values for n.pca & n.da<br>
</font><br>
</div>
<div></div>
<div>
<div dir="ltr">Dear all,
<div><br>
</div>
<div>I updated my adegenet package, however, I still have issues with confirming that it is reading my missing values in correctly. </div>
<div><br>
</div>
<div>I now use this code to read in my genepop file:</div>
<div>
<div><i>msts_m2<-read.genepop("BOR-Od_m2_301w.gen") </i></div>
<div><i><br>
</i></div>
<div>I tried this line of code for replacing NA's with means:</div>
<div>
<div>
<div><i>msts_m2 <- scaleGen(msts_m2, NA.method="mean")</i></div>
</div>
</div>
<div><i><br>
</i></div>
<div>....but this just seems to be appropriate for the regular PCA and my DAPC code (see below) won't work and give me this error: Error in (function (classes, fdef, mtable): unable to find an inherited method for function ‘pop’ for signature ‘"matrix"’</div>
<div><br>
</div>
<div>
<div>Therefore: What is the proper way to treat missing values (denoted as NA in my genepop file) for a DAPC - do they need to be replaced with means (which I assume) and if so what is the proper line of code to do that? </div>
</div>
</div>
<div><br>
</div>
<div>If I don't run the scaleGen line of code and continue with the DAPC code (see below), I still get the same output I had questions about earlier (see below). </div>
<div><br>
</div>
<div>Best,</div>
<div>Magdalena</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Mon, Oct 12, 2015 at 6:21 AM, Jombart, Thibaut <span dir="ltr">
<<a href="mailto:t.jombart@imperial.ac.uk" target="_blank">t.jombart@imperial.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>
<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><font size="2"><span style="font-size:10pt">
<div> <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>
<a href="http://sites.google.com/site/thibautjombart/" target="_blank">http://sites.google.com/site/thibautjombart/</a><br>
<a href="http://sites.google.com/site/therepiproject/" target="_blank">http://sites.google.com/site/therepiproject/</a><br>
<a href="http://adegenet.r-forge.r-project.org/" target="_blank">http://adegenet.r-forge.r-project.org/</a><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>
<div style="direction:ltr"><font color="#000000" face="Tahoma" size="2"><b>From:</b>
<a href="mailto:adegenet-forum-bounces@lists.r-forge.r-project.org" target="_blank">
adegenet-forum-bounces@lists.r-forge.r-project.org</a> [<a href="mailto:adegenet-forum-bounces@lists.r-forge.r-project.org" target="_blank">adegenet-forum-bounces@lists.r-forge.r-project.org</a>] on behalf of D. Magdalena Sorger [<a href="mailto:dm.sorger@gmail.com" target="_blank">dm.sorger@gmail.com</a>]<br>
<b>Sent:</b> 09 October 2015 20:00<br>
<b>To:</b> <a href="mailto:adegenet-forum@lists.r-forge.r-project.org" target="_blank">
adegenet-forum@lists.r-forge.r-project.org</a><br>
<b>Subject:</b> [adegenet-forum] problems with na.replace and values for n.pca & n.da<br>
</font><br>
</div>
<div>
<div class="h5">
<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>
<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>
<div><span style="font-size:12.8px"><i>> na.replace(msts_m2,"mean", quiet=FALSE) </i></span></div>
<div><span style="font-size:12.8px"><br>
</span></div>
<div><span style="font-size:12.8px"><i> Replaced 119 missing values </i></span></div>
<div><span style="font-size:12.8px"><i><br>
</i></span></div>
<div><span style="font-size:12.8px"><i> #####################</i></span></div>
<div><span style="font-size:12.8px"><i> ### Genind object ### </i></span></div>
<div><span style="font-size:12.8px"><i> #####################</i></span></div>
<div><span style="font-size:12.8px"><i>- genotypes of individuals - </i></span></div>
<div><span style="font-size:12.8px"><i><br>
</i></span></div>
<div><span style="font-size:12.8px"><i>S4 class: genind</i></span></div>
<div><span style="font-size:12.8px"><i>@call: read.genepop(file = "BOR-Od_m2_301w.gen", missing = "NA")</i></span></div>
<div><span style="font-size:12.8px"><i><br>
</i></span></div>
<div><span style="font-size:12.8px"><i>@tab: 301 x 93 matrix of genotypes</i></span></div>
<div><span style="font-size:12.8px"><i><br>
</i></span></div>
<div><span style="font-size:12.8px"><i>@ind.names: vector of 301 individual names</i></span></div>
<div><span style="font-size:12.8px"><i>@loc.names: vector of 8 locus names</i></span></div>
<div><span style="font-size:12.8px"><i>@loc.nall: number of alleles per locus</i></span></div>
<div><span style="font-size:12.8px"><i>@loc.fac: locus factor for the 93 columns of @tab</i></span></div>
<div><span style="font-size:12.8px"><i>@all.names: list of 8 components yielding allele names for each locus</i></span></div>
<div><span style="font-size:12.8px"><i>@ploidy: 2</i></span></div>
<div><span style="font-size:12.8px"><i>@type: codom</i></span></div>
<div><span style="font-size:12.8px"><i><br>
</i></span></div>
<div><span style="font-size:12.8px"><i>Optionnal contents: </i></span></div>
<div><span style="font-size:12.8px"><i>@pop: factor giving the population of each individual</i></span></div>
<div><span style="font-size:12.8px"><i>@pop.names: factor giving the population of each individual</i></span></div>
<div><span style="font-size:12.8px"><i><br>
</i></span></div>
<div><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>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div class="gmail_signature">
<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>
# 919-513-7464<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>
</div>
</div>
</div>
</div>
</body>
</html>