Arlindo Meque
2013-Mar-14 08:01 UTC
[R] Same eigenvalues but different eigenvectors using 'prcomp' and 'principal' commands
Dear all, I've used the 'prcomp' command to calculate the eigenvalues and eigenvectors of a matrix(gg). Using the command 'principal' from the 'psych' packageĀ I've performed the same exercise. I got the same eigenvalues but different eigenvectors. Is there any reason for that difference? Below are the steps I've followed: 1. PRCOMP #defining the matrix gg=matrix(byrow = TRUE, nrow = 3,data c(1, 0, 1, 1, 4, 2))> gg[,1] [,2] [1,] 1 0 [2,] 1 1 [3,] 4 2 pc=prcomp(gg,center=TRUE,scale=TRUE) # The eigenvectors pc$rotation PC1 PC2 [1,] 0.7071068 0.7071068 [2,] 0.7071068 -0.7071068 # The eigenvalues:> pc$sdev^2[1] 1.8660254 0.1339746 2. PSYCH Package:> pp=principal(gg,nfactors=2)# The eigenvectors> pp$loadingsLoadings: PC1 PC2 [1,] 0.966 -0.259 [2,] 0.966 0.259 # The eigenvalues pp$values 1] 1.8660254 0.1339746 Sincerely, Arlindo [[alternative HTML version deleted]]
Ben Bolker
2013-Mar-14 12:42 UTC
[R] Same eigenvalues but different eigenvectors using 'prcomp' and 'principal' commands
Arlindo Meque <mequitomz <at> yahoo.com.br> writes:> > > Dear all, > > I've used the 'prcomp' command to > calculate the eigenvalues and eigenvectors of a matrix(gg). > > Using the command 'principal' from the > 'psych' package? I've performed the same exercise. I got the same > eigenvalues but different eigenvectors. Is there any reason for that > difference?[snip] eigenvectors are only defined up to a scale factor. prcomp is scaling them so that the sum of squares is 1; I haven't bothered to see how principal() is scaling them (maybe the documention says). (1,1) and (-1,1) , or (1,1) and (1,-1), would have been equally valid choices. Ben Bolker
John Fox
2013-Mar-14 12:47 UTC
[R] Same eigenvalues but different eigenvectors using 'prcomp' and 'principal' commands
Dear Arlindo, When, as here, the eigenvalues are distinct, corresponding eigenvectors are defined only up to multiplication by a nonzero constant. As you can verify, the first set of eigevectors is normalized to length 1 while the second set is normalized to have length equal to the corresponding eigenvalues. I hope this helps, John ------------------------------------------------ John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Thu, 14 Mar 2013 01:01:56 -0700 (PDT) Arlindo Meque <mequitomz at yahoo.com.br> wrote:> > > Dear all, > > I've used the 'prcomp' command to > calculate the eigenvalues and eigenvectors of a matrix(gg). > > Using the command 'principal' from the > 'psych' package? I've performed the same exercise. I got the same > eigenvalues but different eigenvectors. Is there any reason for that > difference? > > Below are the steps I've followed: > > 1. PRCOMP > > #defining the matrix > gg=matrix(byrow = TRUE, nrow = 3,data > c(1, 0, 1, 1, 4, 2)) > > > gg > [,1] [,2] > [1,] 1 0 > [2,] 1 1 > [3,] 4 2 > > pc=prcomp(gg,center=TRUE,scale=TRUE) > > > # The eigenvectors > pc$rotation > PC1 PC2 > [1,] 0.7071068 0.7071068 > [2,] 0.7071068 -0.7071068 > > > # The eigenvalues: > > > pc$sdev^2 > [1] 1.8660254 0.1339746 > > > 2. PSYCH Package: > > > pp=principal(gg,nfactors=2) > > # The eigenvectors > > > > pp$loadings > Loadings: > PC1 PC2 > [1,] 0.966 -0.259 > [2,] 0.966 0.259 > > # The eigenvalues > > pp$values > > > > 1] 1.8660254 0.1339746 > > > > Sincerely, > > Arlindo > [[alternative HTML version deleted]] >