I'm learning PCA in R language. I met two problems right now that I don't understand.

I am performing a PCA analysis in R on a 318×17 dataset using some custom code. I take eigen function in R to find eigenvalues and eigenvectors. But my 1st and 3rd eigenvectors are of the opposite sign to my handbook. My second eigenvectors is almost the same.

I know that given a square matrix A, the condition that characterizes an eigenvalue, $\lambda$, is the existence of a nonzero vector $x$ such that $Ax=\lambda x$; this equation can be rewritten as follows: $(A - \lambda)x=0$.

Now I calculate covariance of my data and have eigenvalues. I want to solve this linear combination equation to find $x$ and compare with initial eigenvectors. When I take solve function in R, my $x$ vector is always zero.

Here are my questions: Why the sign is different? How to use solve function in R to find a non-zero vector $x$?

$\begingroup$Regarding the first part of your question, I encountered the same wrinkle when working on this post. It came to no surprise that I could have followed through the rest of the derivation with the signs reversed. I don't remember exactly, but it could have amounted to a upper-right quadrant versus lower-left quadrant graphical plotting of the vectors with essentially the same meaning.$\endgroup$
– Antoni ParelladaMay 30 '15 at 13:35

1 Answer
1

1) The definition of eigenvector $Ax = \lambda x$ is ambidextrous. If $x$ is an eigenvector, so is $-x$, for then

$$A(-x) = -Ax = -\lambda x = \lambda (-x)$$

So the definition of an eigenbasis is ambiguous of sign.

2) It's hard to know for sure, but I have a strong suspicion of what is happening here. Your equation

$$ (A - \lambda)x = 0 $$

is technically incorrect. The correct equation is

$$ (A - \lambda I)x$$

The first equation is often used as a shorthand for the second. In general, this is unambiguous, because there is no real mathematical way to subtract a vector from a square matrix, but it is abuse of notation. In R though, you have broadcasting. So if you do

The reason you are getting zero solutions is that the matrix you are starting with $A$ is invertible. More than likely (almost surely), the matrix you get by subtracting the same number from every entry will also be invertible. For invertible matrices, the only solution to $Ax = 0$ is the zero vector.

$\begingroup$Thanks @ Matthew Drry . You're right my equation is used as a shorthand for the second. It's true that if A is invertible, Ax=0 can be written as x=0*A(-1).So x is always zero vector. As I mentioned,the condition that characterizes an eigenvalue, λ, is the existence of a nonzero vector x such that Ax=λx. How R can find a nonzero vector x?Because when i took eigen function, I got nonzero eigenvectors.Does it mean that behind eigen function, R find eigenvectors by another way which is not the solve function?$\endgroup$
– Kroll DUMay 31 '15 at 10:14

2

$\begingroup$@KrollDU You won't be able to use solve to recover the eigenvectors, because solve is designed for non-singular systems, and the eigenvector system is, by design, singular. So no, R does not use solve internally in it's eigen computation. You can check this by looking at the source code for eigen, where you'll find z <- if (!complex.x).Internal(La_rs(x, only.values))$\endgroup$
– Matthew DruryMay 31 '15 at 14:41