2
votes

I am to do as follows: I have a set of Vektors v1-vn For these, I need the covariance matrix (which I get while doing a pca). I also need the eigenvalues and eigenvectors of the covariance matrix. The eigenvalues I sort in descending order and then I sort the eigenvectors according to their corresponding eigenvalues. After that I multiply v1 with the first of the eigenvectors, v2 with the second and so on. I return the skalar which I get in this way.

Is there any simple way in R to see which eigenvalue corresponds to which eigenvector?

1
adding a reproducible example would be more helpful - liuminzhao
Have you tried princomp? It does everything for you. - flodel
I have tried princomp, it does the pca for me (so does prcomp) but it seems to be a bit more tricky to get the eigenvectors, let alone the corresponding eigenvalues. - user1862770
What I mean is, as far as I know: sdev returns the eigenvalues while rotation returns the eigenvectors, but how do I know which eigenvalue belongs to which eigenvector? - user1862770

1 Answers

5
votes

Use the result of prcomp directly. It sorts the eigenvalues from biggest to smallest.

 p <- prcomp(USArrests, scale=T)

For appropriate values of i, the eigenvalue is p$sdev[i]^2, with eigenvector p$rotation[,i]