# Drawing major and minor axis of the covariance of a non-centered data set

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[]] vs[]}
t2 = {origin, origin + 2 Sqrt[ls[]] vs[]}

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?

## 1 Answer

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[]] vsz[]}
t2 = {ms, ms + 2 ss Sqrt[lsz[]] vsz[]};
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): 