Random variables · Definition
Covariance
Before you start you need to know
Variance describes one variable; covariance describes how two of them move together.
Definition
The covariance \(\operatorname{Cov}(X,Y)\) of two variables \(X\) and \(Y\) measures whether they tend to deviate from their expectations \(E\) in the same or opposite directions: it is the expectation of the product of their deviations.
For each outcome, take the deviation of \(X\) from its mean and that of \(Y\) from its own, and multiply them. If both usually have the same sign the product is mostly positive and the covariance is positive; if they usually have opposite signs it is negative; if there is no tendency it stays near 0.
To compute it, use the equivalent form \(\operatorname{Cov}(X,Y)=E[XY]-E[X]E[Y]\). With \(E[X]=2\), \(E[Y]=3\) and \(E[XY]=7\) it equals 1. A typical mistake is forgetting to subtract the product of the means and reporting \(E[XY]\) as the covariance.
It is symmetric, satisfies \(\operatorname{Cov}(X,X)=\operatorname{Var}(X)\) and is linear in each argument, so \(\operatorname{Cov}(aX+b,cY+d)=ac\operatorname{Cov}(X,Y)\). Also, \(\operatorname{Var}(X+Y)=\operatorname{Var}(X)+\operatorname{Var}(Y)+2\operatorname{Cov}(X,Y)\): the cross term separates the variance of a sum from the sum of variances.
If \(X\) and \(Y\) are independent the covariance is 0, but the converse is false: with \(X\) uniform on \(\{-1,0,1\}\) and \(Y=X^2\) the covariance is 0 and yet \(Y\) depends on \(X\). Covariance only detects linear dependence; its size is bounded by \(\sqrt{\operatorname{Var}(X)\operatorname{Var}(Y)}\) and its units are the product of those of \(X\) and \(Y\), so it is usually normalized to obtain the correlation.
Think about it
Why does independence imply zero covariance but not the other way around?
Independence gives \(E[XY]=E[X]E[Y]\), so the covariance vanishes. Zero covariance only rules out a linear relation: \(Y=X^2\) with symmetric \(X\) is dependent and has covariance 0.
What happens to the covariance if \(X\) is measured in centimeters instead of meters?
It is multiplied by 100, since \(\operatorname{Cov}(100X,Y)=100\operatorname{Cov}(X,Y)\); that is why its magnitude cannot be compared directly across scales.
Exercises 10
- \(E[X]=2,\ E[Y]=3\) and \(E[XY]=7\). Compute \(\operatorname{Cov}(X,Y)\).
- If \(\operatorname{Var}(X)=4\), what is \(\operatorname{Cov}(X,X)\)?
- Let \(X\) be uniform on \(\{0,1,2\}\) and \(Y=2X\). Compute \(\operatorname{Cov}(X,Y)\).
- If \(X\) and \(Y\) are independent with \(E[X]=2\) and \(E[Y]=5\), what is \(\operatorname{Cov}(X,Y)\)?
- If \(\operatorname{Cov}(X,Y)=3\), compute \(\operatorname{Cov}(2X+1,\,-3Y+5)\).
- With the joint table \(P(0,0)=0.4,\ P(0,1)=0.1,\ P(1,0)=0.1,\ P(1,1)=0.4\), compute \(\operatorname{Cov}(X,Y)\).
- If \(\operatorname{Var}(X)=4\), \(\operatorname{Var}(Y)=9\) and \(\operatorname{Cov}(X,Y)=-2\), compute \(\operatorname{Var}(X+Y)\).
- If \(\operatorname{Cov}(X,Y)<0\), what can be said?
- Let \(X\) be uniform on \(\{-1,0,1\}\) and \(Y=X^2\). Which statement is correct?
- If \(\operatorname{Var}(X)=1\) and \(\operatorname{Var}(Y)=4\), which value is impossible for \(\operatorname{Cov}(X,Y)\)?
Related
References
- Joseph K. Blitzstein, Jessica Hwang, Introduction to Probability, 2nd edition, CRC Press, 2019. §7.3
- Sheldon Ross, A First Course in Probability, 10th edition, Pearson, 2019. §7.4
- Ronald E. Walpole, Raymond H. Myers, Sharon L. Myers, Keying Ye, Probabilidad y estadística para ingeniería y ciencias, 9.ª edición, Pearson, 2012. §4.3