TITLE: How to calculate the covariance matrix
QUESTION [6 upvotes]: 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?

REPLY [13 votes]: 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.