prcomp eigenvalues
On Tue, 2005-08-02 at 19:06 -0700, Rebecca Young wrote:
Hello, Can you get eigenvalues in addition to eigevectors using prcomp? If so how? I am unable to use princomp due to small sample sizes. Thank you in advance for your help! Rebecca Young
Rebecca, This answer is similar as some others, but this is simpler. You have two separate problems: running PCA and getting eigenvalues. The first is easy to solve: use prcomp instead of princomp (which only exists for historic reasons). Function prcomp can handle cases with more columns than rows. pc <- prcomp(x) Above I assumed that your data are called x (or you can first make x, say: x <- rcauchy(200); dim(x) <- c(20,10) -- which puts a funny twist to comments on variances and standard deviations below). This saves something that are called 'sdev' or standard deviations, and you can get values that are (proportional to) eigenvalues simply by taking their squares: ev <- pc$sdev^2 These may be good enough for you (they would be good enough for me). However, if you want to exactly replicate the numbers in some other piece of software, you may need to multiply these by some constant. If you don't need this, you may stop reading here. The eigenvalues above are related to usual 'unbiased' variance so that the following results are approximately equal: sum(ev) sum(apply(x, 2, var)) If you want to get eigenvalues related to biased estimate of variance, you can do eb <- (1-1/nrow(x))*ev Function princomp uses these, as do some other software, but prcomp works hard and carefully to get the eigenvalues it uses instead of biased values (that would come naturally and directly in the algorithm it uses). Some programs relate their eigenvalues to the sum of squares, and you can get these by es <- (nrow(x) - 1) * ev Finally, some popular programs in ecology (your affiliation) use proportional eigenvalues which you can get with: ev/sum(ev) cheers, jari oksanen
Jari Oksanen -- Dept Biology, Univ Oulu, 90014 Oulu, Finland email jari.oksanen at oulu.fi, homepage http://cc.oulu.fi/~jarioksa/