# Assigning eigenvectors of a covariance matrix to the variables it was generated from

Preface: This is the follow-up question according to the insights I got from MvG on my earlier post.

Think of an ellipsoid in the n-dimensional space defined by $$ell: (x-\mu)'A(x-\mu)=1.$$ Then one could calculate $A$ from the covariance matrix of a data set, such that $$A = cov(dataset)^{-1}.$$ Say, each of the $N$ rows of $dataset$ holds an observation of 3 variables, namely $x_{1}, x_{2},$ and $x_{3}$. Then $dataset$ is a matrix with dimension $N\times3$, and $A$ is then a matrix of $3\times3$.

Refering to the eigenvectors of $A$ by $eVecs$ and the corresponding eigenvalues by $eVals$, the eigenvector with the largest eigenvalue will correspond to the direction along which $dataset$ has the maximum variance see here for details.

What I would like to know: I would be happy to get advise how to sort $eVecs$ and $eVals$ to correspond to the variables $x_{1}, x_{2},$ and $x_{3}$. See the example below for better understanding, there, the variables $X$ are drawn from uniform distributions where the upper limit of the distribution is increases from 1 over 10 to 100. The eigenvalues are then sorted by software R with respect to their magnitude (no option to avoid sorting). Nevertheless, the first eigenvalue (12.7) would correspond to the last variable (limit = 100). Is there an algorithm to resort $eVals$ in less clear situations? Is sorting them according to the variances of the $X$ enough ?(I guess not since "direction" does not mean "variable" when the variables are correlated - right?)

  > dataset = cbind(runif(1000,0,1),runif(1000,0,10),runif(1000,0,100))
> A = solve(cov(dataset))