Example of a Covariance Matrix?

$\begingroup$

Can someone provide an example of a covariance matrix for any set of data? For example, if given:

2 3 4

5 1 8

9 7 6

how would I take this 3x3 matrix and convert it to the covariance matrix? I see the formula involves taking the means, but I'm not quite sure how that works in this case...

$\endgroup$

1 Answer

$\begingroup$

Here is a session from R statistical software with means and variances of three variables similar to yours, and then a variance-covariance matrix of all three.

x1 = c(2,3,4)
x2 = c(5,8,1)
x3 = c(9,7,5)
mean(x1); mean(x2); mean(x3)
## 3 # sample mean of x1
## 4.666667
## 7
var(x1); var(x2); var(x3)
## 1 # sample variance of x1
## 12.33333
## 4
cbind(x1, x2, x3) # puts 3 column vectors into matrix x1 x2 x3
##[1,] 2 5 9
##[2,] 3 8 7
##[3,] 4 1 5
cov(cbind(x1,x2,x3)) # makes covariance matrix from data matrix
## x1 x2 x3
## x1 1 -2.00000 -2
## x2 -2 12.33333 4
## x3 -2 4.00000 4

Notice that the variance $1$ of data vector $x_1$ is in the upper-left corner of the variance-covariance matrix. And that the other two variances 12.3333 and 4 are also on the principal diagonal of the matrix.

The covariance of $x_1$ and $x_3$ is computed as $$S_{13} = \frac{(2-3)(9-7)+(3-3)(7-7)+(4-3)(5-7)}{2} = \frac{-2+0-2}{2} -4/2 = -2,$$ which is shown at the top of right-hand column of the variance-covariance matrix. (Also again, at the left of the bottom row.)

You do not show the formula for the covariance as given in your book so I have shown the arithmetic without trying to guess the notation. I will leave it to you to match my arithmetic with the formula in your book.

$\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

You Might Also Like