The Covariance of Two Random Variables

Introduces the covariance of two random variables. Covers the definition Cov(X,Y)=E[(XμX)(YμY)]\operatorname{Cov}(X,Y) = E[(X-\mu_X)(Y-\mu_Y)], the shortcut formula Cov(X,Y)=E[XY]E[X]E[Y]\operatorname{Cov}(X,Y) = E[XY] - E[X]E[Y], computation for both discrete and continuous random variables, and the relationship between covariance and independence.

Step 1 of 157%

Tutorial

Definition of Covariance

The covariance of two random variables XX and YY measures how they vary together. It is defined as

Cov(X,Y)=E ⁣[(XμX)(YμY)],\operatorname{Cov}(X,Y) = E\!\left[\,(X-\mu_X)(Y-\mu_Y)\,\right],

where μX=E[X]\mu_X = E[X] and μY=E[Y]\mu_Y = E[Y] denote the means of XX and Y.Y.

Interpretation: When XX tends to be above its mean exactly when YY is above its mean, the product (XμX)(YμY)(X-\mu_X)(Y-\mu_Y) is usually positive and the covariance is positive. When one variable tends to be above its mean while the other is below, the product is usually negative and the covariance is negative. A covariance of zero means there is no such linear tendency.

For discrete random variables with joint pmf p(x,y),p(x,y), the covariance becomes a double sum:

Cov(X,Y)=xy(xμX)(yμY)p(x,y).\operatorname{Cov}(X,Y) = \sum_x \sum_y (x-\mu_X)(y-\mu_Y)\,p(x,y).

For example, suppose X{0,1}X\in\{0,1\} and Y{1,2}Y\in\{1,2\} have joint pmf

p(0,1)=0.2,p(0,2)=0.3,p(1,1)=0.1,p(1,2)=0.4.p(0,1)=0.2,\quad p(0,2)=0.3,\quad p(1,1)=0.1,\quad p(1,2)=0.4.

The marginals give μX=0(0.5)+1(0.5)=0.5\mu_X = 0(0.5)+1(0.5) = 0.5 and μY=1(0.3)+2(0.7)=1.7.\mu_Y = 1(0.3)+2(0.7) = 1.7. Hence

Cov(X,Y)=(0.5)(0.7)(0.2)+(0.5)(0.3)(0.3)+(0.5)(0.7)(0.1)+(0.5)(0.3)(0.4)=0.070.0450.035+0.06=0.05.\begin{align*} \operatorname{Cov}(X,Y) &= (-0.5)(-0.7)(0.2) + (-0.5)(0.3)(0.3) \\ &\quad + (0.5)(-0.7)(0.1) + (0.5)(0.3)(0.4) \\ &= 0.07 - 0.045 - 0.035 + 0.06 \\ &= 0.05. \end{align*}
navigate · Enter open · Esc close · ⌘K/Ctrl K toggle