I use eigenvector decomposition to obtain the two axes of a covariance matrix. When the data are standardized, this is trivially easy. However, I can't make it from the raw data. What is it that I forget?

To generate a sample of data, I used:

μ = {100, 12};
ρ = .80;
Σ = {{15^2, ρ 15 3}, {ρ 15 3, 3^2}};
{X, Y} = RandomVariate[MultinormalDistribution[μ, Σ], 1000]\[Transpose];

To standardized it, I used:

ms = Mean[{X, Y}\[Transpose]] // N
ss = StandardDeviation[{X, Y}\[Transpose]] // N
zs = Map[(# - ms)/ss &, {X, Y}\[Transpose]];

Then covariance and decomposition is straigthforward:

S = Covariance[zs]
ls = Eigenvalues[S]
vs = Eigenvectors[S]

To make the plot to check visually that everything is ok:

origin = {0, 0};
t1 = {origin, origin + 2 Sqrt[ls[[1]]] vs[[1]]}
t2 = {origin, origin + 2 Sqrt[ls[[2]]] vs[[2]]}

ListPlot[zs, AspectRatio -> 1, 
  Epilog -> {Green, PointSize[0.025], Point[ms], Red, Arrow[t1], Blue, Arrow[t2]    

Of course, here everything is perfect. How can the same be done but this time using the raw data, not the standardized data?


Well, I tried a few things, and it turns out that multiplying the eigenvalues by the variances makes the vectors have the correct lengths. Hence, the arrows would be given by

t1 = {ms, ms + 2 ss Sqrt[ lsz[[1]]] vsz[[1]]}
t2 = {ms, ms + 2 ss Sqrt[lsz[[2]]] vsz[[2]]};
ListPlot[{X, Y}\[Transpose], AspectRatio -> 1, 
  Epilog -> {Green, PointSize[0.025], Point[ms], Red, Arrow[t1], Blue, Arrow[t2]

in which ss is a vector of the standard deviations. The results is (left on raw data; right on standardized data):

enter image description here


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.