Celeb Glow
updates | April 22, 2026

How to calculate the covariance matrix

$\begingroup$

I tried searching a lot on the net and got the following sources:

  • Source One
  • Source Two
  • The first source seems to be incorrect cause when I calculate it using matlab it comes to be different from what they have given as the answer. As for the second link I cant understand that cause its not completely explaining as to how to calculate. Could anyone please provide me with a sound link or explain how to calculate a co-variance matrix?

    $\endgroup$ 4

    1 Answer

    $\begingroup$

    I finally understood the concept behind co-variance. Co-variance is different for population data and sample data.

    Following is the method I followed:

    Let $A$ be a $n \times m$ matrix where $n$ is the number of rows (observations) and $m$ represents the number of columns (variables).
    Let $\mathbf e$ be the $n \times 1$ column vector composed entirely of ones. Then,$$ X= A - \left(\frac{1}{n}\right)\mathbf e\mathbf e^TA $$Then, denote$$ Y = X^TX. $$

    Next is the step that differs for population data and sample data.

    In case of population data, the covariance matrix $\Sigma$ is given by :$$ \Sigma=\left(\frac{1}{n}\right)Y $$
    and in case of sample data, the covariance matrix $\Sigma$ is given by :$$ \Sigma=\left(\frac{1}{n-1}\right)Y $$Hope it helps anyone stuck on a similar problem.

    $\endgroup$ 1

    Your Answer

    Sign up or log in

    Sign up using Google Sign up using Facebook Sign up using Email and Password

    Post as a guest

    By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy