think of an ellipsoid in the n-dimensional space defined by $$(x-\mu)'A(x-\mu)=1.$$
I was calculating the volumes of n-dimensional ellipsoids like the one from above for a while, which is straightforward once the eigenvalues of matrix $A$ are retrieved. The volume $V$ is then given by (using the log scale so that it will not create numerical problems for very large $n$) $$ V_{0} = log(1),\\ V_{1} = log(2), $$ and then for any $i>1$ $$ V_{i} = log(\frac{2\pi}{i-1}) + V_{i-2},$$ and finally $$V = V_{n} + \sum\limits_{i=1}^{n} log(\lambda_{i}^{-\frac{1}{2}}),$$ where each $\lambda_{i}$ refers to one of the $n$ eigenvalues of $A$.
Now we know that each eigenvector of $A$ is the orientation of an axis of the ellipsoid and each $\lambda^{-\frac{1}{2}}$ refers to the half length of one of these axes.
Nevertheless, most (all that I know) mathematical routines that calculate the eigenvalues of $A$ will give the result in a meaningless order. Thus, I will know all half length of the axes of the ellipsoid, but I do not know which eigenvalue corresponds to which eigenvector. I can find this out (I guess) when testing for each eigenvector $v_{k}$ if $$ Av_{k}=\lambda_{i}v_{k}$$ and the $\lambda_{i}$ for which the above holds, will then be the eigenvalue corresponding to $v_{k}$. Nevertheless, my software (R) return eigenvectors normalized to length 1, so the above identity never exists.
My question would be if someone could help me to find out how to sort the eigenvalues anyway so that the first eigenvalue corresponds to the first eigenvector and so on...
Every help is highly appreciated, J
PS: my post is somewhat related to this post and this post, but finally could not figure out how to answer my question with these posts.
They are associated in R
I'll concentrate on the
eigenfunction from R, as you mention it in a comment. Quoting from its manual:This implies that the columns of
Vwill match the values inlamin order. The first column ofVwill always be the eigenvector for the first (i.e. maximal) eigenvalue.lam[i]will always correspond toV[,i].Eigenvector scale and normalization
You stated:
But this is not true. Quoting again from the manual:
You can verify this easily: if some $v$ satisfies $Av=\lambda v$, then a multiple $w=\mu v$ for some $\mu\neq0$ also satisfies $Aw=\mu Av=\mu\lambda v=\lambda w$ so it, too, will be an eigenvector. This is one of the reasons why it might make more sense to speak about eigenspaces, which are the linear spaces spanned by an eigenvector. The eigenvector isn't uniquely defined by the eigenvalue, but the eigenspace in general is. Choosing a vector of length one is just a choice which is useful in many situations.
Further concerns
Your comment also states that, if
Ais a covariance matrix, then “the first eigenvector corresponds to the first variable”. I am not sure what you mean by an eigenvector corresponding to a given variable, since these vectors will always have entries for all of the variables. Using some randomized data:I see no indication in that eigenvector matrix which supports the claim that the first column were in some way associated with the variable
x. So I cannot support the assumption you stated in your comment.The statement from the manual can indded be verified on this data:
If you don't trust that formulation, you may prefer a more explicit eigenvector equation like this:
As a link between these views, you can vectorize the latter for all eigenvectors to obtain a reformulation of the former:
The left hand side of the difference is the matrix
Aapplied to all eigenvectors, whereas the right side is the eigenvectors scaled by their eigenvalues. The differences are zero, so the two are equal. This verifies that the order matches as expected.