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 X and Y is:
Cov(X,Y)=E[(X−E[X])(Y−E[Y])]
Cov(X,Y)=E[XY]−E[X]E[Y]
Proof:
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]
Properties
1. Symmetry
Cov(X,Y)=Cov(Y,X)
2. Variance is Self-Covariance
Cov(X,X)=E[X2]−E[X]2=Var(X)
3. Linearity in Each Argument
Cov(aX+b,Y)=a⋅Cov(X,Y)
Cov(X,Y+Z)=Cov(X,Y)+Cov(X,Z)
4. Variance of Sum
Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y)
General:
Var(∑i=1nXi)=∑i=1nVar(Xi)+2∑i<jCov(Xi,Xj)
5. Independent Variables Have Zero Covariance
If X and Y are independent: Cov(X,Y)=0.
Warning: Cov(X,Y)=0 does NOT imply independence.
Interpretation
| Covariance | Interpretation |
|---|
| Cov(X,Y)>0 | Positive relationship: X and Y tend to move together |
| Cov(X,Y)<0 | Negative relationship: X and Y tend to move oppositely |
| Cov(X,Y)=0 | No linear relationship |
Example
Roll two dice. Let X = first die, Y = second die, S=X+Y.
E[X⋅S]=E[X(X+Y)]=E[X2]+E[XY]=691+449=…
Since X and Y independent: Cov(X,Y)=0.
But Cov(X,S)=Cov(X,X+Y)=Var(X)+Cov(X,Y)=1235+0=1235>0.
X and S are positively correlated: higher X tends to mean higher sum.
Units
Covariance has units of X×Y. If X is in metres and Y in seconds, 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. X = number of hearts in first, Y = number of hearts in second.
Both X and Y are Bernoulli with p=41.
By symmetry: E[X]=E[Y]=5213=41.
E[XY]=P(X=1,Y=1)=P(X=1)P(Y=1∣X=1)=5213⋅5112=2652156
Cov(X,Y)=E[XY]−E[X]E[Y]=2652156−161=171−161=−2721
Negative covariance: drawing a heart first reduces the chance of drawing a heart second.
Summary
| Property | Formula |
|---|
| Definition | Cov(X,Y)=E[(X−E[X])(Y−E[Y])] |
| Computational | Cov(X,Y)=E[XY]−E[X]E[Y] |
| Variance of sum | Var(X+Y)=Var(X)+Var(Y)+2Cov(X,Y) |
| Independent | ⇒Cov(X,Y)=0 |
| Converse | Cov(X,Y)=0⇒ independent |