Issue with phytools phyl.pca and scores() feature
0
0
Entering edit mode
5.2 years ago
rd446 ▴ 30

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 • 1.6k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1361 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6