user3013464
user3013464

Reputation: 9

R eigenvalues/eigenvectors

I have this correlation matrix

 A
[,1]  1.00000 0.00975 0.97245 0.43887 0.02241
[,2]  0.00975 1.00000 0.15428 0.69141 0.86307
[,3]  0.97245 0.15428 1.00000 0.51472 0.12193
[,4]  0.43887 0.69141 0.51472 1.00000 0.77765
[,5]  0.02241 0.86307 0.12193 0.77765 1.00000

And I need to get the eigenvalues, eigenvectors and loadings in R.

When I use the princomp(A,cor=TRUE) function I get the variances(Eigenvalues) but when I use the eigen(A) function I get the Eigenvalues and Eigenvectors, but the Eigenvalues in this case are different than when I use the Princomp-function..

Which function is the right one to get the Eigenvalues?

Upvotes: 0

Views: 1596

Answers (2)

Raffael
Raffael

Reputation: 20045

eigen(M) gives you the correct eigen values and vectors of M.

princomp() is to be handed the data matrix - you are mistakenly feeding it the correlation matrix!

princomp(A,) will treat A as the data and then come up with a correlation matrix and its eigen vectors and values. So the eigen values of A (in case A holds the data as supposed) are not just irrelevant they are of course different from what princomp() comes up with at the end.

For an illustration of performing a PCA in R see here: http://www.joyofdata.de/blog/illustration-of-principal-component-analysis-pca/

Upvotes: 1

Marc in the box
Marc in the box

Reputation: 11995

I believe you are referring to a PCA analysis when you talk of eigenvalues, eigenvectors and loadings. prcomp is essentially doing the following (when cor=TRUE):

###Step1
#correlation matrix
Acs <- scale(A, center=TRUE, scale=TRUE)
COR <- (t(Acs) %*% Acs) / (nrow(Acs)-1)
COR ; cor(Acs) # equal

###STEP 2
# Decompose matrix using eigen() to derive PC loadings
E <- eigen(COR)
E$vectors # loadings
E$values # eigen values

###Step 3
# Project data on loadings to derive new coordinates (principal components)
B <- Acs %*% E$vectors

Upvotes: 1

Related Questions