2

The signs of the eigenvectors in the eigen function change depending on the specification of the symmetric argument. Consider the following example:

set.seed(1234)
data <- matrix(rnorm(200),nrow=100)
cov.matrix <- cov(data)
vectors.1 <- eigen(cov.matrix,symmetric=TRUE)$vectors
vectors.2 <- eigen(cov.matrix,symmetric=FALSE)$vectors
#The second and third eigenvectors have opposite sign
all(vectors.1 == vectors.2)
FALSE

This also has implications for principal component analysis as the princomp function appears to calculate the eigenvectors for the covariance matrix using the eigen function with symmetric set to TRUE.

pca <- princomp(data)
#princomp uses vectors.1
pca$loadings
Loadings:
       Comp.1 Comp.2
 [1,] -0.366 -0.931
 [2,]  0.931 -0.366

               Comp.1 Comp.2
SS loadings       1.0    1.0
Proportion Var    0.5    0.5
Cumulative Var    0.5    1.0
vectors.1
           [,1]       [,2]
[1,] -0.3659208 -0.9306460
[2,]  0.9306460 -0.3659208

Can someone please explain the source or reasoning behind the discrepancy?

2
  • 1
    The signs of the eigenvectors are arbitrary. You can flip them without changing the meaning of ther result; only their direction matters.
    – Hong Ooi
    Aug 1, 2013 at 15:39
  • "princomp function appears to calculate the eigenvectors for the covariance matrix using the eigen function with symmetric set to TRUE." Not that it matters much, but your statement here is correct. Look at methods(princomp) then getAnywhere(princomp.default) and we observe edc <- eigen(cv, symmetric = TRUE)
    – Silverfish
    Jan 3, 2015 at 1:01

3 Answers 3

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

5

Eigenvectors remain eigenvectors after multiplication by a scalar (including -1).

The proof is simple:

If v is an eigenvector of matrix A with matching eigenvalue c, then by definition Av=cv.

Then, A(-v) = -(Av) = -(cv) = c(-v). So -v is also an eigenvector with the same eigenvalue.

The bottom line is that this does not matter and does not change anything.

2
  • 1
    Yeah, I knew that this was just a transformation, but I was just wondering why the two methods yielded different results.
    – chandler
    Aug 1, 2013 at 15:53
  • 1
    @chandler it just depends on the specifics of the method used for finding the eigenvectors. Real symmetric matrices have special mathematical properties that allow them to be solved using specialized algorithms. In general, methods for eigen decomposition tend to be iterative numerical algorithms, so the solution would be a result of the specifics of the how algorithm and how it is initialized.
    – Bitwise
    Aug 1, 2013 at 18:07
3

Linear algebra libraries like LAPACK contain multiple subroutines for carrying out operations like eigendecompositions. The particular subroutine used in any given case may depend on the type of matrix being decomposed, and the pieces of that decomposition needed by the user.

As you can see in this snippet from eigen's code, it dispatches different LAPACK subroutines depending on whether symmetric=TRUE or symmetric=FALSE (and also, on whether the matrix is real or complex).

if (symmetric) {
    z <- if (!complex.x) 
        .Internal(La_rs(x, only.values))
    else .Internal(La_rs_cmplx(x, only.values))
    ord <- rev(seq_along(z$values))
}
else {
    z <- if (!complex.x) 
        .Internal(La_rg(x, only.values))
    else .Internal(La_rg_cmplx(x, only.values))
    ord <- sort.list(Mod(z$values), decreasing = TRUE)
}

Based on pointers in ?eigen, La_rs() (used when symmetric=TRUE) appears to refer to dsyevr while La_rg() refers to dgeev.

To learn exactly why those two algorithms switch some of the signs of the eigenvectors of the matrix you've handed to eigen(), you'd have to dig into the FORTRAN code used to implement them. (Since, as others have noted, the sign is irrelevant, I'm guessing you won't want to dig quite that deep ;).

2
  • (A tiny typo: it's dsyevr not dseyvr)
    – Silverfish
    Jan 3, 2015 at 1:38
  • 1
    @Silverfish -- Thanks -- fixed it. Jan 3, 2015 at 1:44
3

If you want to change the sign of eigenvector elements, then simply ensure $\mathbf{1}^T\mathbf{e}>1$. In other words, sum all the elements in each eigenvector, and ensure the sum is greater than one. If not, change the sign of each element to the opposite sign. This is the trick to get the sign of eigenvector elements, principal components, and loadings in PCA to come out the same as most statistical software.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.