Unit 9, lesson 62

Continuous Expectation and Variance

How the mean and variance of a continuous variable become integrals against its density, how the law of the unconscious statistician and mixed distributions fit in, and when a moment is infinite or fails to exist.

  • Video 62
  • Continuous Moments and Uniform Distributions

A measurement XX described by a density on [0,1][0, 1] gives probability 00 to each single value, so its average cannot be found by listing values and their probabilities. Cut the range into narrow strips instead. A strip of width Δx\Delta x near xx has probability close to f(x) Δxf(x)\,\Delta x, and it adds about xf(x) Δxx f(x)\,\Delta x to the weighted average, so letting the strips shrink replaces the sum by an integral. This lesson defines continuous expectation and variance in this way, extends them to functions of XX and to mixed distributions, and shows why a valid density need not have a finite mean.

Key terms

Expected value of a continuous variable

Definition Let XX have density ff. If

∫−∞∞∣x∣f(x) dx<∞,\int_{-\infty}^{\infty} \lvert x \rvert f(x)\,dx < \infty,

the expected value of XX is the finite number

E[X]=∫−∞∞xf(x) dx.E[X] = \int_{-\infty}^{\infty} x f(x)\,dx.

It is also called the mean, often written μ\mu, and it has the units of XX. When ff is 00 outside a bounded interval [a,b][a, b], the condition holds automatically and a≤E[X]≤ba \le E[X] \le b. When f(x)=0f(x) = 0 for all x<0x < 0, the integral of xf(x)x f(x) is either a finite number or +∞+\infty, and in the second case we write E[X]=+∞E[X] = +\infty.

In plain words The mean is the same weighted average as for a discrete variable, with density times a small width in the role of a mass. It is the balance point of the distribution, not a forecast of one observation, and it need not equal the median.

Example Let XX have density f(x)=2xf(x) = 2x for 0≤x≤10 \le x \le 1 and f(x)=0f(x) = 0 otherwise. The total area is ∫012x dx=1\int_0^1 2x\,dx = 1, and

E[X]=∫01x⋅2x dx=[23x3]01=23.\begin{aligned} E[X] &= \int_0^1 x \cdot 2x\,dx \\[0.4em] &= \Bigl[\tfrac23 x^3\Bigr]_0^1 = \frac23. \end{aligned}

The density rises to the right, so the mean lies to the right of 12\tfrac12. The CDF is F(x)=x2F(x) = x^2 on [0,1][0, 1], so P(X≤23)=49P(X \le \tfrac23) = \tfrac49, and the median is 1/2≈0.7071/\sqrt{2} \approx 0.707, not the mean.

Law of the unconscious statistician

Definition Let XX have density ff, and let gg be a function such as a polynomial or a piecewise continuous function. If ∫−∞∞∣g(x)∣f(x) dx<∞\int_{-\infty}^{\infty} \lvert g(x) \rvert f(x)\,dx < \infty, then

E[g(X)]=∫−∞∞g(x)f(x) dx.E[g(X)] = \int_{-\infty}^{\infty} g(x) f(x)\,dx.

If g≥0g \ge 0, the formula holds without that condition, with both sides possibly equal to +∞+\infty. In particular, the kkth moment E[Xk]E[X^k] is the integral of xkf(x)x^k f(x), finite when the integral of ∣x∣kf(x)\lvert x \rvert^k f(x) is finite, and E[X2]E[X^2] is the second moment. The rule is called the law of the unconscious statistician, or LOTUS, because it is easy to use without noticing that it needs proof.

In plain words To average a function of XX, weight the values of the function by the original density. There is no need to find the distribution of g(X)g(X) first. The function is applied inside the integral, not to the answer, so E[g(X)]E[g(X)] is usually different from g(E[X])g(E[X]).

Example For the density 2x2x on [0,1][0, 1],

E[X2]=∫01x2⋅2x dx=[12x4]01=12,\begin{aligned} E[X^2] &= \int_0^1 x^2 \cdot 2x\,dx \\[0.4em] &= \Bigl[\tfrac12 x^4\Bigr]_0^1 = \frac12, \end{aligned}

which is not (E[X])2=49(E[X])^2 = \tfrac49. As a check, Y=X2Y = X^2 has P(Y≤y)=P(X≤y)=yP(Y \le y) = P(X \le \sqrt{y}) = y for 0≤y≤10 \le y \le 1, so Y∼Uniform⁡(0,1)Y \sim \operatorname{Uniform}(0, 1), and its mean is ∫01y dy=12\int_0^1 y\,dy = \tfrac12. LOTUS gave the same answer without that detour.

Variance of a continuous variable

Definition Let XX have density ff and finite mean μ\mu. The variance of XX is

Var⁡(X)=E[(X−μ)2]=∫−∞∞(x−μ)2f(x) dx,\begin{aligned} &\operatorname{Var}(X) = E\bigl[(X - \mu)^2\bigr] \\[0.4em] &\quad = \int_{-\infty}^{\infty} (x - \mu)^2 f(x)\,dx, \end{aligned}

a number in [0,∞)[0, \infty) or +∞+\infty. It is finite exactly when E[X2]<∞E[X^2] < \infty, and then

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

The standard deviation is SD⁡(X)=Var⁡(X)\operatorname{SD}(X) = \sqrt{\operatorname{Var}(X)}. Variance has the squared units of XX, and the standard deviation has the units of XX. When Var⁡(X)\operatorname{Var}(X) is finite, the rules Var⁡(a+bX)=b2Var⁡(X)\operatorname{Var}(a + bX) = b^2 \operatorname{Var}(X) and SD⁡(a+bX)=∣b∣SD⁡(X)\operatorname{SD}(a + bX) = \lvert b \rvert \operatorname{SD}(X) hold for all constants aa and bb. A variable with a density and a finite mean has Var⁡(X)>0\operatorname{Var}(X) > 0, because variance 00 would force P(X=μ)=1P(X = \mu) = 1.

In plain words Variance is the average squared distance from the mean, weighted by the density. Squaring removes signs and stresses large distances, so variance is not the average absolute distance. The shortcut E[X2]−μ2E[X^2] - \mu^2 is convenient when both moments are finite, and it shows that the average of the squares exceeds the square of the average by exactly the variance.

Example For the density 2x2x on [0,1][0, 1],

Var⁡(X)=12−(23)2=12−49=118,\begin{aligned} \operatorname{Var}(X) &= \frac12 - \left(\frac23\right)^2 \\[0.4em] &= \frac12 - \frac49 = \frac{1}{18}, \end{aligned}

and SD⁡(X)=1/18≈0.236\operatorname{SD}(X) = \sqrt{1/18} \approx 0.236. The direct integral ∫01(x−23)2 2x dx\int_0^1 (x - \tfrac23)^2 \, 2x\,dx gives the same 118\tfrac{1}{18}. If XX is measured in hours, the variance is in squared hours and the standard deviation in hours. The recorded quantity Y=10+6XY = 10 + 6X has E[Y]=10+6⋅23=14E[Y] = 10 + 6 \cdot \tfrac23 = 14 and Var⁡(Y)=36⋅118=2\operatorname{Var}(Y) = 36 \cdot \tfrac{1}{18} = 2, so SD⁡(Y)=2≈1.414\operatorname{SD}(Y) = \sqrt{2} \approx 1.414. Adding 1010 moves the mean and leaves the spread alone.

Mean of a mixed distribution

Definition Let XX have a mixed distribution with atoms aia_i of masses mim_i and a continuous part h≥0h \ge 0 whose total area is 1−M1 - M, where M=∑imiM = \sum_i m_i. For a function gg such that ∑i∣g(ai)∣mi\sum_i \lvert g(a_i) \rvert m_i and ∫∣g(x)∣h(x) dx\int \lvert g(x) \rvert h(x)\,dx are finite,

E[g(X)]=∑ig(ai) mi+∫−∞∞g(x)h(x) dx.\begin{aligned} &E[g(X)] = \sum_i g(a_i)\, m_i \\[0.4em] &\quad + \int_{-\infty}^{\infty} g(x) h(x)\,dx. \end{aligned}

In particular, E[X]E[X] is MM times the mean of the discrete part plus 1−M1 - M times the mean of the continuous part, a weighted average of the two conditional means. The variance is E[X2]−(E[X])2E[X^2] - (E[X])^2 with both moments found this way. It is at least the weighted average of the two conditional variances, and larger whenever the two conditional means differ.

In plain words Each piece contributes in proportion to its own weight. The atoms contribute their values times their masses, and the continuous part contributes an integral against hh, whose total area is less than 11. Leaving out an atom, or treating the continuous part as the whole distribution, describes a different model.

Example Let TT equal 00 with probability 0.20.2 and otherwise be uniform on (0,1)(0, 1), so h(t)=0.8h(t) = 0.8 on (0,1)(0, 1). The atom contributes 0⋅0.2=00 \cdot 0.2 = 0 to each moment, so

E[T]=∫01t⋅0.8 dt=25,E[T2]=∫01t2⋅0.8 dt=415.\begin{gathered} E[T] = \int_0^1 t \cdot 0.8\,dt = \frac25, \\[0.4em] E[T^2] = \int_0^1 t^2 \cdot 0.8\,dt = \frac{4}{15}. \end{gathered}

Then Var⁡(T)=415−425=875≈0.107\operatorname{Var}(T) = \tfrac{4}{15} - \tfrac{4}{25} = \tfrac{8}{75} \approx 0.107. Ignoring the atom would give the mean 12\tfrac12 and the variance 112≈0.083\tfrac{1}{12} \approx 0.083 of the continuous part alone. The atom pulls the mean down, and the gap between the conditional means 00 and 12\tfrac12 adds spread.

Infinite mean

Definition Let XX have a density ff with f(x)=0f(x) = 0 for all x<0x < 0. If the integral of xf(x)x f(x) over [0,∞)[0, \infty) diverges, then XX has infinite mean, written E[X]=+∞E[X] = +\infty. The density still has total area 11. Normalization fixes the area under ff and says nothing about the integral of xf(x)x f(x). An infinite mean requires XX to be unbounded, meaning P(X>t)>0P(X > t) > 0 for every tt.

In plain words Every single value of XX is finite, but large values keep so much probability that the weighted average grows without bound as more of the range is included. The mean is then not some very large number. No finite number serves as the balance point.

Example Let f(x)=1/x2f(x) = 1/x^2 for x≥1x \ge 1 and f(x)=0f(x) = 0 for x<1x < 1. For b>1b > 1, ∫1bx−2 dx=1−1/b\int_1^b x^{-2}\,dx = 1 - 1/b, which tends to 11, so ff is a density. But

∫1bx⋅1x2 dx=∫1bdxx=ln⁡b,\begin{aligned} \int_1^b x \cdot \frac{1}{x^2}\,dx &= \int_1^b \frac{dx}{x} \\[0.4em] &= \ln b, \end{aligned}

which grows without bound. Without logarithms, on each interval from 2k2^k to 2k+12^{k+1} the integrand 1/x1/x is at least 1/2k+11/2^{k+1} over a width 2k2^k, so each such interval adds at least 12\tfrac12, and infinitely many halves have no finite sum. Hence E[X]=+∞E[X] = +\infty, even though P(X>t)=1/tP(X > t) = 1/t for t≥1t \ge 1, which tends to 00, and the median is 22.

Moment existence

Definition Let XX have density ff. The kkth moment E[Xk]E[X^k] exists as a finite number when

∫−∞∞∣x∣kf(x) dx<∞.\int_{-\infty}^{\infty} \lvert x \rvert^k f(x)\,dx < \infty.

For k=1k = 1 this condition is called absolute integrability, and it is exactly what makes E[X]E[X] a finite number. If the positive part ∫0∞xf(x) dx\int_0^\infty x f(x)\,dx and the negative part ∫−∞0∣x∣f(x) dx\int_{-\infty}^0 \lvert x \rvert f(x)\,dx are both infinite, E[X]E[X] is undefined. If exactly one of them is infinite, E[X]E[X] is +∞+\infty or −∞-\infty. A finite second moment gives a finite mean, because ∣x∣≤1+x2\lvert x \rvert \le 1 + x^2, and the variance is finite exactly when the second moment is. A density that is 00 outside a bounded interval has finite moments of every order.

In plain words Before using a moment, check that the integral of its absolute size is finite. Symmetry alone does not supply a mean. When both tails carry infinite weight, canceling them against each other over [−R,R][-R, R] produces a number that depends on how the limits are taken, so it is not an expectation.

Example The density f(x)=1/(2x2)f(x) = 1/(2x^2) for ∣x∣≥1\lvert x \rvert \ge 1, and 00 for ∣x∣<1\lvert x \rvert < 1, has total area 11 and is symmetric about 00. Every symmetric integral ∫−RRxf(x) dx\int_{-R}^{R} x f(x)\,dx is 00, but

∫−∞∞∣x∣f(x) dx=∫1∞dxx=∞,\begin{aligned} \int_{-\infty}^{\infty} \lvert x \rvert f(x)\,dx &= \int_1^\infty \frac{dx}{x} \\[0.4em] &= \infty, \end{aligned}

and integrating over [−R,2R][-R, 2R] instead gives 12ln⁡2\tfrac12 \ln 2 for every R≥1R \ge 1. So E[X]E[X] is undefined, although 00 is the center of symmetry and a median. For a finite mean with infinite variance, take f(x)=2/x3f(x) = 2/x^3 for x≥1x \ge 1 and 00 otherwise. Its total area is 11, its mean is ∫1∞2x−2 dx=2\int_1^\infty 2x^{-2}\,dx = 2, and its second moment is ∫1∞2x−1 dx=+∞\int_1^\infty 2x^{-1}\,dx = +\infty, so Var⁡(X)=+∞\operatorname{Var}(X) = +\infty.

Check yourself

  1. Let XX have density f(x)=3x2f(x) = 3x^2 for 0≤x≤10 \le x \le 1 and 00 otherwise. Find E[X]E[X], E[X2]E[X^2], Var⁡(X)\operatorname{Var}(X) and SD⁡(X)\operatorname{SD}(X).
Show the answer

The total area is ∫013x2 dx=1\int_0^1 3x^2\,dx = 1, and the support is bounded, so every moment is finite. By LOTUS,

E[X]=∫013x3 dx=34,E[X2]=∫013x4 dx=35.\begin{gathered} E[X] = \int_0^1 3x^3\,dx = \frac34, \\[0.4em] E[X^2] = \int_0^1 3x^4\,dx = \frac35. \end{gathered}

With the common denominator 8080,

Var⁡(X)=35−916=4880−4580=380,\begin{aligned} \operatorname{Var}(X) &= \frac35 - \frac{9}{16} \\[0.4em] &= \frac{48}{80} - \frac{45}{80} = \frac{3}{80}, \end{aligned}

and SD⁡(X)=3/80≈0.194\operatorname{SD}(X) = \sqrt{3/80} \approx 0.194.

  1. For the same XX, find the mean, variance and standard deviation of Y=5−2XY = 5 - 2X. A classmate writes Var⁡(Y)=−2Var⁡(X)\operatorname{Var}(Y) = -2 \operatorname{Var}(X). What went wrong?
Show the answer

By linearity, E[Y]=5−2⋅34=72E[Y] = 5 - 2 \cdot \tfrac34 = \tfrac72. Adding 55 does not change the spread, and multiplying by −2-2 multiplies the variance by (−2)2=4(-2)^2 = 4, so

Var⁡(Y)=4⋅380=320,\operatorname{Var}(Y) = 4 \cdot \frac{3}{80} = \frac{3}{20},

and SD⁡(Y)=∣−2∣SD⁡(X)=3/20≈0.387\operatorname{SD}(Y) = \lvert -2 \rvert \operatorname{SD}(X) = \sqrt{3/20} \approx 0.387. The classmate’s value −2⋅380=−340-2 \cdot \tfrac{3}{80} = -\tfrac{3}{40} is negative, which no average of squared distances can be. The factor −2-2 reverses the direction of the scale, but distances from the mean are doubled and their squares are multiplied by 44.

  1. Let XX have density f(x)=3x−4f(x) = 3x^{-4} for x≥1x \ge 1 and 00 for x<1x < 1. Check that ff is a density, find E[X]E[X] and Var⁡(X)\operatorname{Var}(X), and decide whether E[X3]E[X^3] is finite.
Show the answer

The function is nonnegative, and for b>1b > 1, ∫1b3x−4 dx=1−b−3\int_1^b 3x^{-4}\,dx = 1 - b^{-3}, which tends to 11. So ff is a density. Since X≥1X \ge 1, every moment integral has a nonnegative integrand and is either finite or +∞+\infty. Here

E[X]=∫1∞3x−3 dx=32,E[X2]=∫1∞3x−2 dx=3,\begin{gathered} E[X] = \int_1^\infty 3x^{-3}\,dx = \frac32, \\[0.4em] E[X^2] = \int_1^\infty 3x^{-2}\,dx = 3, \end{gathered}

so Var⁡(X)=3−94=34\operatorname{Var}(X) = 3 - \tfrac94 = \tfrac34. The third moment is ∫1∞3x−1 dx\int_1^\infty 3x^{-1}\,dx, and since ∫1b3x−1 dx=3ln⁡b\int_1^b 3x^{-1}\,dx = 3 \ln b grows without bound, E[X3]=+∞E[X^3] = +\infty. This variable has a finite mean and a finite variance but an infinite third moment, so finite lower moments do not guarantee a finite higher one.

How this lesson connects

It also uses integrals over an unbounded interval.