Question: Issue with phytools phyl.pca and scores() feature
0
gravatar for rd446
13 months ago by
rd44610
East Carolina University
rd44610 wrote:

A recent phytools blog post addresses a question about multiple samples per species in the phylogenetic PCA: http://blog.phytools.org/2019/08/computing-principal-components-scores.html

I'm encountering an issue: phyl.pca won't generate more eigenvectors than the number of samples. In the new scores() update to correct for multiple samples per species, phytools asks if the number of traits are the same as the number of eigenvectors, and throws an error if they aren't. The number of eigenvectors is always the same as the number of traits- if there are fewer traits than samples. But phyl.pca won't generate more eigenvectors than samples, so the number of traits can't equal the number of eigenvectors when there are more traits than samples. Even Dr. Revell's sample data in the blog post throws an error if I manipulate the number of traits.

This leads me to two questions regarding PCAs generally- first, when running PCAs, is it important to always have the same number of eigenvectors as traits? According to the scores() function, the answer is yes. But, I don't understand why the answer is yes. And second question/comment, if it is important to sometimes have more eigenvectors than samples, then this is a general issue with phyl.pca, regardless of the recent scores() blog post. scores() just checks that the number of eigenvectors is the same as the number of traits. Without scores(), phyl.pca runs fine, but still will never generate more eigenvectors than the number of samples. The eigenvector versus trait "check" step in scores() may be noticing a general issue that doesn't throw an error when running phyl.pca. The code in quesiton is here:

if(ncol(newdata)!=ncol(object$Evec))

{ if(nrow(newdata)==ncol(object$Evec)) newdata<-t(newdata)

   else stop("Dimensions of newdata incorrect.")

https://github.com/liamrevell/phytools/commit/bb71dab53f8d0d5b466eceda5e3bba9c50520e77

Thank you so much Biostars community!

phytools phyl.pca • 433 views
ADD COMMENTlink modified 13 months ago • written 13 months ago by rd44610

Have you considered asking Liam directly, since it's his code? Perhaps you should open an issue for clarification.

ADD REPLYlink written 13 months ago by Brice Sarver3.5k

Yes, I have. Now considering if that's the more acceptable way to go about it (not Biostars)

ADD REPLYlink modified 13 months ago • written 13 months ago by rd44610
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 919 users visited in the last hour