Math Atom · M-C10

Covariance and correlation

10 minMath AtomProbability

By the end you will be able to

  1. 1Read covariance as a measure of whether two quantities move together, and calculate it from a small table.
  2. 2Explain why the size of a covariance depends on its units.
  3. 3Calculate a correlation, read it between −1 and 1, and match it to a scatter plot.
  4. 4Explain why correlation is not causation and only measures straight-line co-movement.

Why you need it

The variance tells you how much one thing moves. The next question is: when it moves, does something else move with it? Covariance and correlation answer that.

These Core Path lessons use them:

The idea

Do they move together?

Put two returns side by side, month by month, and ask a simple question each month: was each one above or below its own average? Draw a rectangle from the average point to each month's point. If both were above average, or both below, the rectangle counts as positive (green). If one was up while the other was down, it counts as negative (red).

Rectangles from the average

8 months, returns in % (illustrative)

Two returns that…

both above average: +both below average: +X below, Y above: −X above, Y below: −average Xaverage Y

Month 1

X − average X−2
Y − average Y−1.388
Product (signed area)2.775

All 8 months

Positive / negative areas8 / 0
Sum of products16.9
Covariance = sum ÷ (8 − 1)2.414

Add up the signed areas and take a kind of average: that is the covariance. Lots of green means the two tend to move together; lots of red means they tend to move apart; a mix that cancels out means no clear tendency.

The rules

Covariance. Each rectangle's area is the product of two deviations from the mean.

The units problem, and correlation. A covariance of 3.25 sounds bigger than one of 0.000325, yet they describe exactly the same data. Dividing by the two standard deviations gives a measure on a fixed scale: the correlation.

Here is what different correlations look like on a scatter plot (80 points each).

ρ = −1a falling line
ρ = 0no straight-line pattern
ρ = 0.5a loose upward cloud
ρ = 1a rising line

What correlation does not tell you

Correlation is not causation. Ice-cream sales and sunburn cases rise and fall together through the year, but neither causes the other: sunny weather drives both. A high correlation says two things move together, not why.

It only sees straight lines. Correlation measures linear co-movement. Two quantities can be tightly linked in a curved way and still have a correlation of 0 (worked example 3). Dependence that correlation misses, such as things that only move together in extreme moments, comes later in the course.

The rules, for reference

Cov⁡(X,Y)=E[(X−μX)(Y−μY)]sXY=1n−1∑i=1n(xi−xˉ)(yi−yˉ)\operatorname{Cov}(X,Y) = \mathbb{E}\big[(X-\mu_X)(Y-\mu_Y)\big] \qquad s_{XY} = \frac{1}{n-1}\sum_{i=1}^{n}(x_i-\bar x)(y_i-\bar y)
ρ=Cov⁡(X,Y)σX σY,−1≤ρ≤1,Cov⁡(X,Y)=ρ σX σY\rho = \frac{\operatorname{Cov}(X,Y)}{\sigma_X\,\sigma_Y}, \qquad -1 \le \rho \le 1, \qquad \operatorname{Cov}(X,Y) = \rho\,\sigma_X\,\sigma_Y

Try it

Slide the correlation from −1 to 1 and watch the cloud tilt and tighten. Then change the spread of Y, and switch the units: which readout moves, and which stays put?

Units

40 days of two illustrative returns: X across, Y up. The dashed lines mark the averages.
-8%-4%0%4%8%-3%-2%-1%0%1%2%3%
Sample sd of X1%
Sample sd of Y1.5%
Covariance (%²)0.7511
Correlation = covariance ÷ (sd X × sd Y)0.501

Switch the units: the covariance changes by a factor of 10,000, the correlation stays put. Widen Y: the covariance grows, the correlation does not.

Worked examples

1. Covariance and correlation by hand

Step 1 of 6
  1. 1

    The set-up

    Two shares returned, in % over five months (illustrative): X = 2, -1, 3, -2, 3 and Y = 1, -1, 2, 0, 3.

2. From correlation back to covariance

Step 1 of 3
  1. 1

    The set-up

    A model says X has a standard deviation of 20%, Y of 10%, and their correlation is 0.3. What is their covariance?

3. A perfect link with zero correlation

Step 1 of 3
  1. 1

    The set-up

    Let x = -2, -1, 0, 1, 2 and y = x², so y = 4, 1, 0, 1, 4. Knowing x tells you y exactly.

    y = x²

Common mistakes

Each line below is a tempting slip. Spot what is wrong, then check.

Reaction

Check what stuck

Question 1 · objective 3

Cov(X, Y) = 0.006, X has standard deviation 0.2 and Y has 0.1. What is the correlation ρ?

Question 2 · objective 3

On a scatter plot every point sits exactly on a straight line that falls from left to right. What is ρ?

Question 3 · objective 1

Work out the sample covariance (divide by n − 1) of x = 1, 2, 3 and y = 2, 4, 7.

Question 4 · objective 2

You rewrite two return series from percent (1.5) to decimals (0.015). What happens?

Question 5 · objective 4

Two quantities have correlation 0. What can you conclude?

Glossary

Deviation
How far a value is from its mean: positive above the mean, negative below.
Covariance
The average of the product of two deviations from the mean. Positive when two quantities tend to move together, negative when they tend to move apart.
Correlation (ρ)
The covariance divided by both standard deviations: a number between −1 and 1 with no units, written ρ (rho).
Scatter plot
A chart with one dot for each pair of values: the first value across, the second up.
Linear
Following a straight line: when one goes up by a step, the other goes up (or down) by a fixed amount.
Causation
One thing making another happen. Correlation alone cannot show it.