Covariance Explained with Worked Examples

The covariance of two random variables is . It is positive when the variables tend to move together, negative when they move oppositely, and zero when they are independent (but not conversely).

Write 2x or 2*x to multiply, ^ for powers, and ; between simultaneous equations. You can also type factor, expand, derivative of, integrate … from a to b, limit … as x->0 or 15% of 80.

Try an example

Before you start

This page is easier if you are comfortable with:

What Covariance means

For the data , taken as equally likely: , , , so . For the joint pmf , : , , . The expectations are those of discrete expectation.

Linear relation: if and , then (linear transformations). , and covariance is bilinear. The covariance matrix collects all pairs. Scaling by the standard deviations gives the correlation coefficient, which lies between and 1.

Covariance enters the variance of a sum, (the variance of a sum), the regression slope (the regression line) and portfolio risk.

What is it used for?

Covariance measures whether two quantities tend to rise and fall together.

How to use covariance

  1. Find , and from the joint distribution.
  2. Compute .
  3. Interpret the sign.
  4. Divide by for the correlation.

Graph

Data X = (1, 2, 3), Y = (2, 4, 5) with covariance 1mean of Y: 3.66700.511.522.533.540123456Data X = (1, 2, 3), Y = (2, 4, 5) with covariance 1XYGraph with x from 0 to 4 and y from 0 to 6. Shows data points (3); point mean of Y: 3.667 at (2, 3.667).

The points rise together, so the covariance is positive.

Worked examples

These examples are worked by hand, step by step, so you can compare your own working.

Example 1: data

Find for , (equally likely).

Worked example
Answer
11
  1. E(XY)
  2. E X · E Y

Example 2: a joint pmf

Find the covariance for , .

Worked example
Answer
0.150.15
  1. E(XY)
  2. E X · E Y

Example 3: Y = 2X + 1

Find when and .

Worked example
Answer
88
  1. Formula

Special cases

A few situations come up again and again. Knowing them saves time and helps you spot answers that cannot be right.

E(XY) = 5, E(X) = E(Y) = 2

Cov = 5 − 4

1.

Data x = (1, 2, 3), y = (2, 4, 5)

means 2 and 11/3

Pairs of deviations.

Sum of products of deviations

5/3 + 0 + 4/3

3.

Population covariance

3/3

1.

Word problems

Cov(X, Y) = E(XY) − E(X)E(Y) = E[(X − μ_X)(Y − μ_Y)]. It is positive when the variables rise together and 0 for independent variables.

Shortcut

E(XY) = 5, E(X) = E(Y) = 2. Find Cov.

  1. 5 − 2 × 2
  2. Check: ✓1

Mean of y

Find the mean of y = (2, 4, 5).

  1. 11/3
  2. Check: ✓3.6667

Deviations Higher

Σ(x − 2)(y − 11/3) for the data.

  1. (−1)(−5/3) + 0 + (1)(4/3)
  2. Check: ✓3

Population Cov Higher

Divide by n = 3.

  1. 3 ÷ 3
  2. Check: ✓1

Common mistakes

Cov = E(X)E(Y)

wrong ✗

E(XY) − E(X)E(Y) ✓

Subtract the product of means.

Zero covariance ⇒ independence

always ✗

not in general ✓

Only the converse holds.

Dividing by n−1 vs n

mix ✗

state which ✓

Sample vs population.

Units

unit-free ✗

product of units ✓

Not scale-free.

Exam tips

  1. E(XY) − E(X)E(Y).
  2. Sign shows direction.
  3. Independence ⇒ 0.
  4. Not scale-free.
  5. Cov(X, X) = Var X.

Practice questions

Try each one on paper, then open the answer. Use the solver above to see the full working.

1. E(XY)=12, E(X)=3, E(Y)=3 Foundation

3

2. E(XY)=7, E(X)=2, E(Y)=3 Foundation

1

3. E(XY)=4, E(X)=2, E(Y)=2 Foundation

0

4. Cov(2X, Y) when Cov(X, Y) = 1.5 Higher

3

5. Cov(X+1, Y) when Cov(X, Y) = 3 Higher

3

6. E(XY)=1.5, E(X)=1, E(Y)=1 Higher

0.5

Practice generator

Unlimited fresh questions with instant marking. Choose a level, work it out on paper, then type your answer.

Solve: …

Key terms

Covariance
Joint variability.
Expectation
Mean value.
Independence
No relationship.
Deviation
Value minus mean.
Correlation
Scaled covariance.
Variance
Cov(X, X).

Frequently asked questions

What is covariance?

E(XY) − E(X)E(Y).

What does a positive value mean?

The variables tend to rise together.

Does zero covariance imply independence?

No.

What is Cov(X, X)?

Var X.

Which page covers correlation?

correlation coefficient.

Which page covers variance of a sum?

variance of a sum.

More in Advanced statistics and stochastic processes and the formula sheets.