3
$\begingroup$

For example, we have an NxP matrix with N rows and P variables. Then we need to calculate a PxP sample covariance matrix. How do I do that?

$\endgroup$
0

2 Answers 2

5
$\begingroup$

Seems you're looking for this Wikipedia page. Here's the relevant excerpt:

The sample covariance of N observations of K variables is the K-by-K matrix $\bar{\bar q}=[[q_{jk}]]$ with the entries
$q_{jk}=\frac{1}{N-1}\sum_{i=1}^{N}\left( x_{ij}-\bar{x}_j \right) \left( x_{ik}-\bar{x}_k \right)$,
which is an estimate of the covariance between variable $j$ and variable $k$.

All I can think to add is that the diagonal entries $q_{jj}$ are equivalent to the variables' variances $(s^2)$.

$\endgroup$
1
$\begingroup$

In addition to @Nick Stauner, I could say that if you use R you can do

cov(yourMatrix)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.