Unit 5, lesson 33

Variance

How variance measures spread as the expected squared deviation from the mean, how the second moment gives the computational formula, why variance has squared units, and why a finite variance needs a finite second moment.

  • Video 33
  • Variance and Standard Deviation

Two service desks both keep a caller waiting two minutes on average. At one desk the wait is exactly two minutes every time, while at the other a call is sometimes answered at once and sometimes after four minutes. Knowing only the mean, you cannot tell which desk you are calling. This lesson defines variance, the expected squared distance from the mean, computes it in two ways that must agree, and explains why it is measured in squared units and when it is finite.

Key terms

Deviation from the mean

Definition Let XX have finite expectation μ=E[X]\mu = E[X]. The deviation of XX from its mean is the random variable X−μX - \mu. Its value is positive on outcomes where XX lies above the mean, negative where XX lies below it and zero where X=μX = \mu. By linearity,

E[X−μ]=E[X]−μ=0.E[X - \mu] = E[X] - \mu = 0.

In plain words A deviation says how far one outcome lies from the center and on which side. The signed deviations of any variable with a finite mean balance exactly, so their average cannot measure spread. A measure of spread built by averaging deviations has to remove the signs first.

Example Let a waiting time XX be 00, 22 or 44 minutes with probabilities 14\frac14, 12\frac12 and 14\frac14. Its mean is 0⋅14+2⋅12+4⋅14=20 \cdot \frac14 + 2 \cdot \frac12 + 4 \cdot \frac14 = 2 minutes, and the deviations are −2-2, 00 and 22 minutes. Their weighted average is (−2)⋅14+0⋅12+2⋅14=0(-2) \cdot \frac14 + 0 \cdot \frac12 + 2 \cdot \frac14 = 0, although half of the probability sits away from the mean. The sign describes position relative to the mean, so a deviation of −2-2 minutes is not a negative waiting time.

Variance

Definition Let XX have finite expectation μ\mu. The squared deviation (X−μ)2(X - \mu)^2 is a nonnegative random variable, and the variance of XX is its expectation,

Var⁡(X)=E[(X−μ)2].\operatorname{Var}(X) = E\bigl[(X - \mu)^2\bigr].

For a discrete variable with PMF pXp_X,

Var⁡(X)=∑x(x−μ)2 pX(x).\operatorname{Var}(X) = \sum_x (x - \mu)^2 \, p_X(x).

The variance is either a number in [0,∞)[0, \infty) or +∞+\infty, and it is finite exactly when XX has a finite second moment. It equals 00 exactly when P(X=μ)=1P(X = \mu) = 1, so for a discrete variable exactly when every value with positive probability equals the mean. Variance is a property of a probability model. Estimating an unknown variance from data, with a divisor such as n−1n - 1, is a different task.

In plain words Square each deviation, so that distances above and below the mean count alike and cannot cancel, then average the squares with the probabilities as weights. Squaring also makes large deviations count heavily, since doubling a distance multiplies its square by four.

Example For the waiting time above, the squared deviations are 44, 00 and 44, so Var⁡(X)=4⋅14+0⋅12+4⋅14=2\operatorname{Var}(X) = 4 \cdot \frac14 + 0 \cdot \frac12 + 4 \cdot \frac14 = 2 square minutes. A wait of exactly 22 minutes has the same mean and variance 00. A wait of 00 or 44 minutes with probability 12\frac12 each also has mean 22, but both of its squared deviations are 44, so its variance is 44 square minutes. Moving probability from the center to the ends, with the mean unchanged, raised the variance from 22 to 44.

Second moment

Definition The second moment of XX is E[X2]E[X^2]. For a discrete variable,

E[X2]=∑xx2 pX(x).E[X^2] = \sum_x x^2 \, p_X(x).

All its terms are nonnegative, so it is either a finite number or +∞+\infty, and XX has a finite second moment when E[X2]<∞E[X^2] < \infty. A finite second moment implies a finite expectation, because ∣x∣≤1+x22\lvert x \rvert \le \frac{1 + x^2}{2} for every real xx. For XX with finite expectation μ\mu, the inequalities (x−μ)2≤2x2+2μ2(x - \mu)^2 \le 2x^2 + 2\mu^2 and x2≤2(x−μ)2+2μ2x^2 \le 2(x - \mu)^2 + 2\mu^2 show that the variance is finite exactly when the second moment is finite, and the variance is +∞+\infty when E[X2]=∞E[X^2] = \infty. If XX has no finite expectation, there is no real number μ\mu to center at, and the definition of variance does not apply. Every variable with finitely many values, and more generally every bounded variable, has a finite second moment.

In plain words The second moment averages the squared outcomes themselves, measured from zero rather than from the mean. A distribution with unbounded values can have a finite mean and an infinite second moment, because squaring makes rare large values count heavily enough for the sum to diverge.

Example For the waiting time above, the squared outcomes are 00, 44 and 1616 square minutes, so E[X2]=0⋅14+4⋅12+16⋅14=6E[X^2] = 0 \cdot \frac14 + 4 \cdot \frac12 + 16 \cdot \frac14 = 6 square minutes. For an infinite second moment, let YY take the value 2k2^k with probability 3⋅4−k3 \cdot 4^{-k} for k=1,2,3,…k = 1, 2, 3, \dots. The probabilities 34,316,364,…\frac34, \frac{3}{16}, \frac{3}{64}, \dots add to 11, and

E[Y]=∑k=1∞2k⋅3⋅4−k=3,E[Y2]=∑k=1∞4k⋅3⋅4−k=∞.\begin{aligned} E[Y] &= \sum_{k=1}^{\infty} 2^k \cdot 3 \cdot 4^{-k} = 3, \\[0.4em] E[Y^2] &= \sum_{k=1}^{\infty} 4^k \cdot 3 \cdot 4^{-k} = \infty . \end{aligned}

The first sum is ∑k3⋅2−k=3\sum_k 3 \cdot 2^{-k} = 3, while every term of the second equals 33. So YY has a finite mean and Var⁡(Y)=+∞\operatorname{Var}(Y) = +\infty.

Computational formula for variance

Definition If XX has a finite second moment and μ=E[X]\mu = E[X], then

Var⁡(X)=E[X2]−(E[X])2.\operatorname{Var}(X) = E[X^2] - \bigl(E[X]\bigr)^2 .

To see why, expand the square and apply linearity, which is allowed because X2X^2, XX and the constant μ2\mu^2 all have finite expectations,

E[(X−μ)2]=E[X2]−2μE[X]+μ2=E[X2]−μ2.\begin{aligned} &E\bigl[(X - \mu)^2\bigr] \\[0.4em] &\quad = E[X^2] - 2\mu E[X] + \mu^2 \\[0.4em] &\quad = E[X^2] - \mu^2 . \end{aligned}

Because a variance is never negative, it follows that E[X2]≥(E[X])2E[X^2] \ge (E[X])^2, with equality exactly when XX is constant with probability one.

In plain words The variance is the mean of the squares minus the square of the mean. This route is often quicker by hand, since it avoids subtracting the mean from every value. When the two terms are large and nearly equal, subtracting rounded decimals can lose much of the accuracy, and exact fractions or the centered definition are safer.

Example For the waiting time above, E[X2]=6E[X^2] = 6 and (E[X])2=4(E[X])^2 = 4 square minutes, so Var⁡(X)=6−4=2\operatorname{Var}(X) = 6 - 4 = 2 square minutes, which matches the calculation from squared deviations.

Squared units

Definition If XX is measured in some unit, the deviation X−μX - \mu has the same unit, and Var⁡(X)\operatorname{Var}(X) is measured in the square of that unit, since probabilities carry no unit. The standard deviation SD⁡(X)=Var⁡(X)\operatorname{SD}(X) = \sqrt{\operatorname{Var}(X)} returns to the original unit. It is the root-mean-square deviation, the square root of the mean of the squared deviations. If XX has finite variance and aa and bb are constants, then

Var⁡(aX+b)=a2Var⁡(X),\operatorname{Var}(aX + b) = a^2 \operatorname{Var}(X),

because the deviation of aX+baX + b from its mean aμ+ba\mu + b is a(X−μ)a(X - \mu). A shift leaves the variance unchanged, and a factor aa multiplies it by a2a^2.

In plain words A variance of 22 square minutes is not an average distance of 22 minutes. To compare the spread with the mean or with the outcomes themselves, take the square root. Changing units from minutes to seconds multiplies every deviation by 6060 and the variance by 36003600.

Example The waiting time above has variance 22 square minutes and standard deviation 2≈1.41\sqrt{2} \approx 1.41 minutes. Adding a fixed 55 minutes to every wait gives X+5X + 5, whose mean is 77 minutes and whose variance is still 22 square minutes. Tripling every wait gives 3X3X, with variance 9⋅2=189 \cdot 2 = 18 square minutes and standard deviation 32≈4.243\sqrt{2} \approx 4.24 minutes.

Check yourself

  1. A waiting time is 11, 22 or 66 minutes with probabilities 0.20.2, 0.50.5 and 0.30.3. Find its mean, then its variance, once from the squared deviations and once from the second moment. Give units.
Show the answer

The mean is 1⋅0.2+2⋅0.5+6⋅0.3=0.2+1+1.8=31 \cdot 0.2 + 2 \cdot 0.5 + 6 \cdot 0.3 = 0.2 + 1 + 1.8 = 3 minutes. The deviations are −2-2, −1-1 and 33 minutes, with squares 44, 11 and 99, so the variance is 4⋅0.2+1⋅0.5+9⋅0.3=0.8+0.5+2.7=44 \cdot 0.2 + 1 \cdot 0.5 + 9 \cdot 0.3 = 0.8 + 0.5 + 2.7 = 4 square minutes.

The second moment is 1⋅0.2+4⋅0.5+36⋅0.3=0.2+2+10.8=131 \cdot 0.2 + 4 \cdot 0.5 + 36 \cdot 0.3 = 0.2 + 2 + 10.8 = 13 square minutes, and 13−32=413 - 3^2 = 4 square minutes again. The standard deviation is 22 minutes.

  1. A waiting time has variance 44 square minutes. Someone converts the times to seconds and reports a variance of 240240. What went wrong, and what are the correct variance and standard deviation in seconds?
Show the answer

If XX is the waiting time in minutes, the time in seconds is 60X60X. Every deviation is multiplied by 6060, so every squared deviation, and with them the variance, is multiplied by 602=360060^2 = 3600. The correct variance is 3600⋅4=144003600 \cdot 4 = 14400 square seconds. The reported value multiplies by 6060 only once, as if the variance were measured in minutes. The standard deviation is 60⋅2=12060 \cdot 2 = 120 seconds, in agreement with 14400=120\sqrt{14400} = 120.

  1. Can a random variable have mean 22 and second moment 33? Can it have mean 22 and second moment 55? Give an example where one exists.
Show the answer

With mean 22 and second moment 33, the computational formula would give a variance of 3−22=−13 - 2^2 = -1. A variance is the expectation of a nonnegative variable, so it cannot be negative, and no such random variable exists.

With mean 22 and second moment 55, the variance would be 5−4=15 - 4 = 1, which is possible. For example, let XX be 11 or 33 with probability 12\frac12 each. Then E[X]=2E[X] = 2 and E[X2]=1+92=5E[X^2] = \frac{1 + 9}{2} = 5.

How this lesson connects