ProbabilityContinuous Random Variables

Mean and Variance of a Continuous Variable

E[X] = ∫ x f(x) dx and E[g(X)] = ∫ g(x) f(x) dx, and the variance shortcut still holds.

Not started Jump to practice

For a discrete variable the mean is $\sum x\,P(X = x)$. For a density the sum becomes an integral, and every rule from the variance rules carries over unchanged.

Key idea

$$E[X] = \int x\,f(x)\,dx, \qquad E[g(X)] = \int g(x)\,f(x)\,dx, \qquad \operatorname{Var}(X) = E[X^{2}] - (E[X])^{2}.$$

Why it works

Cut the line into thin slices of width $\Delta x$. The slice at $x$ has probability about $f(x)\,\Delta x$, so the discrete formula gives $\sum x\,f(x)\,\Delta x$, a Riemann sum that tends to $\int x\,f(x)\,dx$. Geometrically, $E[X]$ is the balance point of the region under the density, the place where a ruler shaped like the graph would balance on a finger. The same slicing gives $E[g(X)]$, and the algebra behind the variance shortcut only used linearity, which integrals have too.
The density 2x on 0 to 1, with its balance point at two thirds and its median a little higher.

Worked examples

Worked example: Mean and variance

$f(x) = 2x$ on $[0, 1]$. Find $E[X]$ and $\operatorname{Var}(X)$.
  1. $E[X] = \int_{0}^{1} x \cdot 2x\,dx = \frac{2}{3}$.
  2. $E[X^{2}] = \int_{0}^{1} x^{2} \cdot 2x\,dx = \frac{1}{2}$.
  3. $\operatorname{Var}(X) = \frac{1}{2} - \frac{4}{9} = \frac{1}{18}$.

Answer: $\frac{2}{3}$ and $\frac{1}{18}$

Worked example: The uniform distribution

$X$ is uniform on $[a, b]$. Find $E[X]$ and $\operatorname{Var}(X)$.
  1. $f = \frac{1}{b - a}$ on $[a, b]$. $$E[X] = \int_{a}^{b} \frac{x}{b - a}\,dx = \frac{b^{2} - a^{2}}{2(b - a)} = \frac{a + b}{2}$$ the midpoint.
  2. $$E[X^{2}] = \frac{b^{3} - a^{3}}{3(b - a)} = \frac{a^{2} + ab + b^{2}}{3}$$
  3. $$\operatorname{Var}(X) = \frac{a^{2} + ab + b^{2}}{3} - \frac{(a + b)^{2}}{4} = \frac{(b - a)^{2}}{12}$$

Answer: $\frac{a + b}{2}$ and $\frac{(b - a)^{2}}{12}$

Worked example: A function of X

With $f(x) = 2x$ on $[0, 1]$, find $E\left[\frac{1}{X}\right]$.
  1. $$E\left[\frac{1}{X}\right] = \int_{0}^{1} \frac{1}{x} \cdot 2x\,dx = \int_{0}^{1} 2\,dx = 2$$
  2. Compare $\frac{1}{E[X]} = \frac{3}{2}$: as in the discrete case, $E[g(X)] \ne g(E[X])$.

Answer: 2

Any function works the same way. Powers give the moments $E[X^{3}] = \int x^{3}f(x)\,dx$, and so on. A squared distance from a number $c$ can be expanded first, $$E[(X - c)^{2}] = E[X^{2}] - 2cE[X] + c^{2}$$ so two integrals you may already have do the work. And for a curved function such as $e^{x}$, expect the average of the function to exceed the function of the average: for $X$ uniform on $[0, 1]$, $E[e^{X}] = e - 1 \approx 1.72$ while $e^{E[X]} = e^{1/2} \approx 1.65$.

Common mistake

Integrating the density alone, $\int f(x)\,dx$, and reporting the result as the mean. That integral is always 1. Check: the mean must lie inside the range of $X$, and you need the factor $x$ (or $g(x)$) inside the integral.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • Grinstead and Snell, Introduction to Probability (2nd revised edition, American Mathematical Society; free from Dartmouth College), chapter 6 (Expected Value and Variance), section 6.3, continuous random variables
  • MIT OpenCourseWare 18.05, Introduction to Probability and Statistics (Spring 2014), readings on expectation and variance of continuous random variables
@teddyrookbook GitHub