Skip to content
Part IA Easter Term

Covariance

Motivation

Variance measures spread. But how do we measure the joint variability of two random variables? Do they tend to move together or in opposite directions?

Definition

The covariance of XX and YY is:

Cov(X,Y)=E[(XE[X])(YE[Y])]\text{Cov}(X, Y) = E[(X - E[X])(Y - E[Y])]

Computational Formula

Cov(X,Y)=E[XY]E[X]E[Y]\text{Cov}(X, Y) = E[XY] - E[X]E[Y]

Proof:

E[(XE[X])(YE[Y])]=E[XYXE[Y]E[X]Y+E[X]E[Y]]E[(X - E[X])(Y - E[Y])] = E[XY - XE[Y] - E[X]Y + E[X]E[Y]] =E[XY]E[X]E[Y]E[X]E[Y]+E[X]E[Y]=E[XY]E[X]E[Y]= E[XY] - E[X]E[Y] - E[X]E[Y] + E[X]E[Y] = E[XY] - E[X]E[Y]

Properties

1. Symmetry

Cov(X,Y)=Cov(Y,X)\text{Cov}(X, Y) = \text{Cov}(Y, X)

2. Variance is Self-Covariance

Cov(X,X)=E[X2]E[X]2=Var(X)\text{Cov}(X, X) = E[X^2] - E[X]^2 = \text{Var}(X)

3. Linearity in Each Argument

Cov(aX+b,Y)=aCov(X,Y)\text{Cov}(aX + b, Y) = a \cdot \text{Cov}(X, Y)

Cov(X,Y+Z)=Cov(X,Y)+Cov(X,Z)\text{Cov}(X, Y + Z) = \text{Cov}(X, Y) + \text{Cov}(X, Z)

4. Variance of Sum

Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y)\text{Var}(X + Y) = \text{Var}(X) + \text{Var}(Y) + 2\text{Cov}(X, Y)

General:

Var(i=1nXi)=i=1nVar(Xi)+2i<jCov(Xi,Xj)\text{Var}\left(\sum_{i=1}^n X_i\right) = \sum_{i=1}^n \text{Var}(X_i) + 2\sum_{i < j} \text{Cov}(X_i, X_j)

5. Independent Variables Have Zero Covariance

If XX and YY are independent: Cov(X,Y)=0\text{Cov}(X, Y) = 0.

Warning: Cov(X,Y)=0\text{Cov}(X, Y) = 0 does NOT imply independence.

Interpretation

CovarianceInterpretation
Cov(X,Y)>0\text{Cov}(X, Y) > 0Positive relationship: XX and YY tend to move together
Cov(X,Y)<0\text{Cov}(X, Y) < 0Negative relationship: XX and YY tend to move oppositely
Cov(X,Y)=0\text{Cov}(X, Y) = 0No linear relationship

Example

Roll two dice. Let XX = first die, YY = second die, S=X+YS = X + Y.

E[XS]=E[X(X+Y)]=E[X2]+E[XY]=916+494=E[X \cdot S] = E[X(X+Y)] = E[X^2] + E[XY] = \frac{91}{6} + \frac{49}{4} = \dots

Since XX and YY independent: Cov(X,Y)=0\text{Cov}(X, Y) = 0.

But Cov(X,S)=Cov(X,X+Y)=Var(X)+Cov(X,Y)=3512+0=3512>0\text{Cov}(X, S) = \text{Cov}(X, X + Y) = \text{Var}(X) + \text{Cov}(X, Y) = \frac{35}{12} + 0 = \frac{35}{12} > 0.

XX and SS are positively correlated: higher XX tends to mean higher sum.

Units

Covariance has units of X×YX \times Y. If XX is in metres and YY in seconds, Cov(X,Y)\text{Cov}(X,Y) is in metre-seconds.

This makes interpretation difficult. Correlation (below) normalises to be unitless.

Example: Pair from Deck

Draw two cards without replacement. XX = number of hearts in first, YY = number of hearts in second.

Both XX and YY are Bernoulli with p=14p = \frac{1}{4}.

By symmetry: E[X]=E[Y]=1352=14E[X] = E[Y] = \frac{13}{52} = \frac{1}{4}.

E[XY]=P(X=1,Y=1)=P(X=1)P(Y=1X=1)=13521251=1562652E[XY] = P(X = 1, Y = 1) = P(X = 1) P(Y = 1 \mid X = 1) = \frac{13}{52} \cdot \frac{12}{51} = \frac{156}{2652}

Cov(X,Y)=E[XY]E[X]E[Y]=1562652116=117116=1272\text{Cov}(X, Y) = E[XY] - E[X]E[Y] = \frac{156}{2652} - \frac{1}{16} = \frac{1}{17} - \frac{1}{16} = -\frac{1}{272}

Negative covariance: drawing a heart first reduces the chance of drawing a heart second.

Summary

PropertyFormula
DefinitionCov(X,Y)=E[(XE[X])(YE[Y])]\text{Cov}(X,Y) = E[(X-E[X])(Y-E[Y])]
ComputationalCov(X,Y)=E[XY]E[X]E[Y]\text{Cov}(X,Y) = E[XY] - E[X]E[Y]
Variance of sumVar(X+Y)=Var(X)+Var(Y)+2Cov(X,Y)\text{Var}(X+Y) = \text{Var}(X) + \text{Var}(Y) + 2\text{Cov}(X,Y)
IndependentCov(X,Y)=0\Rightarrow \text{Cov}(X,Y) = 0
ConverseCov(X,Y)=0⇏\text{Cov}(X,Y) = 0 \not\Rightarrow independent