ContentsChapter 2 · Probability3 of 6

2.3

Expectation, variance, covariance

In this chapter
  1. 2.1Conditional probability and Bayes' rule
  2. 2.2Random variables
  3. 2.3Expectation, variance, covariance
  4. 2.4Bernoulli, binomial and Gaussian
  5. 2.5Change of variables
  6. 2.6Entropy and cross-entropy
Before you readYou record height in metres, then in centimetres. Should a measure of how height and weight move together change with the unit?
Watch: Expected Values, Main Ideas!!! · StatQuest with Josh Starmer

The expectation is the probability-weighted average:

E[X]=∑xx p(x)orE[X]=∫x p(x) dx.E[X] = \sum_x x\,p(x) \quad\text{or}\quad E[X] = \int x\,p(x)\,dx.

It is linear: E[aX+bY+c]=aE[X]+bE[Y]+cE[aX + bY + c] = aE[X] + bE[Y] + c for any X and Y, independent or not.

The variance is the expected squared distance from the mean μ=E[X]\mu = E[X] and the standard deviation σ\sigma is its square root:

Var⁡(X)=E[(X−μ)2]=E[X2]−μ2,Var⁡(aX+b)=a2Var⁡(X).\operatorname{Var}(X) = E[(X - \mu)^2] = E[X^2] - \mu^2, \qquad \operatorname{Var}(aX + b) = a^2 \operatorname{Var}(X).

The covariance measures how two variables move together, and the correlation removes the units:

Cov⁡(X,Y)=E[(X−μX)(Y−μY)]=E[XY]−E[X]E[Y],ρ=Cov⁡(X,Y)σXσY∈[−1,1].\operatorname{Cov}(X, Y) = E[(X - \mu_X)(Y - \mu_Y)] = E[XY] - E[X]E[Y], \qquad \rho = \frac{\operatorname{Cov}(X, Y)}{\sigma_X \sigma_Y} \in [-1, 1].

So covariance changes with the unit and correlation does not. Independent variables have zero covariance, but zero covariance does not mean independent: it only rules out a straight-line relationship. In general Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)+2Cov⁡(X,Y)\operatorname{Var}(X + Y) = \operatorname{Var}(X) + \operatorname{Var}(Y) + 2\operatorname{Cov}(X, Y)

For a random vector xx with mean μ\mu the covariance matrix Σ=E[(x−μ)(x−μ)T]\Sigma = E[(x - \mu)(x - \mu)^T] holds every variance on its diagonal and every covariance off it. It is symmetric, and its eigenvectors are the directions PCA keeps (see Dimensionality reduction).

-4-3-2-101234-3-2-10123
Var(x) = 1Var(y) = 1Cov(x, y) = 0.60Σ = [1, 0.60; 0.60, 1]
Each dot is one sample of (x, y); the purple ring is the mean. Covariance grows with both the tilt and the spread of y, so it depends on units. The correlation ρ = Cov / (σ_x σ_y) only measures the tilt, from −1 to 1.
Recall
When is E[X+Y]=E[X]+E[Y]E[X + Y] = E[X] + E[Y]
Recall
Give the shortcut formula for Var⁡(X)\operatorname{Var}(X)
Recall
Does Cov⁡(X,Y)=0\operatorname{Cov}(X, Y) = 0 mean X and Y are independent?
Exercise
Find E[X]E[X] and Var⁡(X)\operatorname{Var}(X) for a fair six-sided die.
Exercise
Var⁡(X)=1\operatorname{Var}(X) = 1 Var⁡(Y)=2\operatorname{Var}(Y) = 2 and Cov⁡(X,Y)=0.5\operatorname{Cov}(X, Y) = 0.5 Find Var⁡(2X−3Y+1)\operatorname{Var}(2X - 3Y + 1)
Exercise
X is −1-1 00 or 11 with equal probability, and Y=X2Y = X^2 Which is true?