calculate deviations from mean scaled by covariance

54 Views Asked by At

I would like to calulate the following:

$y_{i} = S^{-1/2}(x_{i}-\bar{x})$

where, $\bar{x}$ and $S$ are the sample mean and the sample covariance matrix of the initial sample $(x_{1}; ... ; x_{n})$.

First question: Is this the same as the following:

$Y = \Sigma^{-1/2}(X-\mu )$

where $E(X)=\mu $ and $D(X)=\Sigma $ (Covariance Matrix)

I used the following matlab code to implement the first calculation.

[m, n] = size(X);
S = cov(X);

%%  Y
Y = zeros(size(X,2));
for j=1:n
    % yi = S^(-1/2)*(xi-x.mean)
    Y(:,j) = (chol(S)')^(-1)*(X(1,:)'-mean(X(:,1)));
end

Second Question: What is the intuition behind the calculation? It has zero mean, but what is the effect of the negative square root of the covariance?

1

There are 1 best solutions below

3
On BEST ANSWER

The answer to your first question is that they are usually not the same. Because the sample mean/covariance are usually different from the 'true' mean/covariance of the distribution. But when the 'true' parameters are not available, then the sample parameters are usually pretty good approximate.

As for your 'intuition' question, this procedure makes the sample with zero mean and uncorrelated. It is quite useful in numerical computation.

One advice for your matlab/octave code, to have the best performance, avoid loops. If a loop is unavoidable, avoid unnecessary repeated calculation in the loop. In your particular case, the code can be replaced with this one line Matlab/Octave code:

Y = (X-repmat(mean(X),size(X,1),1))*inv(chol(S));