<div dir="ltr">Hi, <div><br></div><div>Firstly, I would like to thank you for your previous recommendations, it was greatly appreciated. The solution was not as obvious at first but I persevered. Thank you again because I am moderately new to R.</div><div><br></div><div>Kind regards to this forum</div><div><br></div><div>Kirsty</div><div><br></div><div><div>xval <- xvalDapc(x, grp1$grp, n.pca.max = 2, training.set = 0.7,</div><div> result = "groupMean", center = TRUE, scale = FALSE,</div><div> n.pca = NULL, n.rep = 30, xval.plot = TRUE)</div></div><div><br></div><div><div>$`Cross-Validation Results`</div><div> n.pca success</div><div>1 1 0.6111111</div><div>2 1 0.6666667</div><div>3 1 0.6666667</div><div>4 1 0.6111111</div><div>5 1 0.6190476</div><div>6 1 0.6190476</div><div>7 1 0.6111111</div><div>8 1 0.5634921</div><div>9 1 0.6111111</div><div>10 1 0.6111111</div><div>11 1 0.6190476</div><div>12 1 0.6666667</div><div>13 1 0.5079365</div><div>14 1 0.6190476</div><div>15 1 0.6190476</div><div>16 1 0.6666667</div><div>17 1 0.6111111</div><div>18 1 0.6111111</div><div>19 1 0.4603175</div><div>20 1 0.6111111</div><div>21 1 0.6111111</div><div>22 1 0.6666667</div><div>23 1 0.5634921</div><div>24 1 0.6666667</div><div>25 1 0.6666667</div><div>26 1 0.5079365</div><div>27 1 0.6111111</div><div>28 1 0.6190476</div><div>29 1 0.6111111</div><div>30 1 0.6666667</div><div><br></div><div>$`Median and Confidence Interval for Random Chance`</div><div> 2.5% 50% 97.5% </div><div>0.2411765 0.3303922 0.4377002 </div><div><br></div><div>$`Mean Successful Assignment by Number of PCs of PCA`</div><div> 1 </div><div>0.6124339 </div><div><br></div><div>$`Number of PCs Achieving Highest Mean Success`</div><div>[1] "1"</div><div><br></div><div>$`Root Mean Squared Error by Number of PCs of PCA`</div><div> 1 </div><div>0.3907175 </div><div><br></div><div>$`Number of PCs Achieving Lowest MSE`</div><div>[1] "1"</div><div><br></div><div>$DAPC</div><div><span class="" style="white-space:pre"> </span>#################################################</div><div><span class="" style="white-space:pre"> </span># Discriminant Analysis of Principal Components #</div><div><span class="" style="white-space:pre"> </span>#################################################</div><div>class: dapc</div><div>$call: dapc.data.frame(x = x, grp = grp, n.pca = n.pca, n.da = n.da)</div><div><br></div><div>$n.pca: 1 first PCs of PCA used</div><div>$n.da: 1 discriminant functions saved</div><div>$var (proportion of conserved variance): 0.605</div><div><br></div><div>$eig (eigenvalues): 58.23 vector length content </div><div>1 $eig 1 eigenvalues </div><div>2 $grp 80 prior group assignment </div><div>3 $prior 3 prior group probabilities </div><div>4 $assign 80 posterior group assignment</div><div>5 $pca.cent 12 centring vector of PCA </div><div>6 $pca.norm 12 scaling vector of PCA </div><div>7 $pca.eig 12 eigenvalues of PCA </div><div><br></div><div> data.frame nrow ncol</div><div>1 $tab 80 1 </div><div>2 $means 3 1 </div><div>3 $loadings 1 1 </div><div>4 $ind.coord 80 1 </div><div>5 $grp.coord 3 1 </div><div>6 $posterior 80 3 </div><div>7 $pca.loadings 12 1 </div><div>8 $var.contr 12 1 </div><div> content </div><div>1 retained PCs of PCA </div><div>2 group means </div><div>3 loadings of variables </div><div>4 coordinates of individuals (principal components)</div><div>5 coordinates of groups </div><div>6 posterior membership probabilities </div><div>7 PCA loadings of original variables </div><div>8 contribution of original variables </div><div><br></div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div>Kirsty Medcalf</div><div> </div><div><a href="mailto:kirsty.m.medcalf@gmail.com" target="_blank">kirsty.m.medcalf@gmail.com</a></div><div> </div><div>+447963374030</div><div> </div><div>skype contact: kirsty.medcalf</div></div></div>
<br><div class="gmail_quote">On Tue, Sep 29, 2015 at 9:44 AM, Kirsty Medcalf <span dir="ltr"><<a href="mailto:kirsty.m.medcalf@gmail.com" target="_blank">kirsty.m.medcalf@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hi </span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I am attempting to cross validate my results from DAPC analysis with a 70 % training set using the function xvalDapc (code below). My data frame is called LDA.scores. this is an updated version of a previous post after taking into account the recommendationsbut I am still outputting the same error message. Do I have to change my data frame into a list? If so, what would be the correct format to transform the data frame into this format. If this is possible, I was wondering if anyone had a solution with how to solve this error message (below). I have looked online and through available tutorials and still cannot <span style="font-size:12.8px">solve this issue. Words cannot describe my gratitude if this is possible.</span></div><div style="font-size:12.8px"><br></div><div><div><pre style="font-size:13px;margin-top:0px;padding:5px;border:0px;overflow:auto;width:auto;max-height:600px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;color:rgb(57,51,24);word-wrap:normal;background-color:rgb(238,238,238)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:inherit"><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)"> </span></code><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">#Permute the data</span></pre><pre style="font-size:13px;margin-top:0px;padding:5px;border:0px;overflow:auto;width:auto;max-height:600px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;color:rgb(57,51,24);word-wrap:normal;background-color:rgb(238,238,238)"><span style="white-space:inherit;margin:0px;padding:0px;border:0px;color:rgb(0,0,0)"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">set.seed(999) </span></span></pre><pre style="font-size:13px;margin-top:0px;padding:5px;border:0px;overflow:auto;width:auto;max-height:600px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;color:rgb(57,51,24);word-wrap:normal;background-color:rgb(238,238,238)"><span style="white-space:inherit;margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">x</span><span style="white-space:inherit;margin:0px;padding:0px;border:0px;color:rgb(0,0,0)"><-</span><span style="white-space:inherit;margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">LDA.scores[,2:13]</span></pre><div><pre style="font-size:13px;margin-top:0px;padding:5px;border:0px;overflow:auto;width:auto;max-height:600px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;color:rgb(57,51,24);word-wrap:normal;background-color:rgb(238,238,238)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;white-space:inherit"><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)"> grp1</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)"><-</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">find.clusters</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">(</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">x</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">,</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)"> max.n.clust</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(128,0,0)">12</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">)</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">
dapc1</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)"><-</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">dapc</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">(</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">x</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">,</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)"> grp1</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">$</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">grp</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,0,0)">)</span></code></pre><pre style="margin-top:0px;padding:5px;border:0px;overflow:auto;width:auto;max-height:600px;word-wrap:normal;background-color:rgb(238,238,238)"><code style="margin:0px;padding:0px;border:0px"><span style="margin:0px;padding:0px;border:0px"><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal"><span style="font-size:12.8px">#DAPC analysis</span><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal"><br></div><div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">windows(width=10, height=7)</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">x<-LDA.scores[,2:13]</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">grp1<-find.clusters(x, max.n.clust=12)</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">dapc1<-dapc(x, grp1$grp)</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">dapc1</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">#Loadings plot</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal"><br></div><div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal">contrib <- loadingplot(dapc1$var.contr, axis=2,</span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal"> thres=.07, lab.jitter=1)</span></font></div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">#Cross Validation</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal">windows(width=10, height=7)<br></div></div><div><div><div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal">set.seed(1234)</span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal">x1 <- LDA.scores</span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal">str(x1)</span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal">x1$Matriline<-as.factor(x1$Matriline)</span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal">xval <- xvalDapc(x1, grp1, n.pca.max = 2, training.set = 0.7,</span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal"> result = "groupMean", center = TRUE, scale = FALSE,</span></font></div><div><font face="arial, sans-serif"><span style="font-size:12.8px;white-space:normal"> n.pca = NULL, n.rep = 30, xval.plot = TRUE)</span></font></div></div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;white-space:normal"><div>Error in sort.list(y) : 'x' must be atomic for 'sort.list'</div><div>Have you called 'sort' on a list?</div></div></div></span></code></pre><div style="font-size:12.8px"><span style="font-size:12.8px">During the DAPC analysis, I chose to retain 2 PCs and 2 LD's, and there appears to be 3 clusters. Would n.pca.max=2 be correct? </span><br></div></div></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">My reproducible data, the logical steps that I took to chose the number of PC's and LD's to retain, and the number of chosen clusters is available on stack overflow</div><div style="font-size:12.8px"><br></div><div><a href="http://stackoverflow.com/questions/32704902/discriminant-analysis-of-principal-components-and-how-to-graphically-show-the-di" target="_blank">http://stackoverflow.com/questions/32704902/discriminant-analysis-of-principal-components-and-how-to-graphically-show-the-di</a><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">If it is possible to help me, then thank you</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Best wishes,</div><div style="font-size:12.8px">Kirsty</div><div style="font-size:12.8px"><br></div><div><div><div><br></div><div><br></div><div><br></div><div><br></div></div></div>
</div>
</blockquote></div><br></div>