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
Why it works
Worked examples
Worked example: Mean and variance
- $E[X] = \int_{0}^{1} x \cdot 2x\,dx = \frac{2}{3}$.
- $E[X^{2}] = \int_{0}^{1} x^{2} \cdot 2x\,dx = \frac{1}{2}$.
- $\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
- $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.
- $$E[X^{2}] = \frac{b^{3} - a^{3}}{3(b - a)} = \frac{a^{2} + ab + b^{2}}{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
- $$E\left[\frac{1}{X}\right] = \int_{0}^{1} \frac{1}{x} \cdot 2x\,dx = \int_{0}^{1} 2\,dx = 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