This note covers the variance of a random variable, continuous random variables described by a probability density function, and what happens to the mean and variance when a variable is transformed linearly. These tools describe spread as well as average, for example in waiting times, measurement errors and profit forecasts.
Key ideas
Variance of a discrete variable. The mean \(\mu = E(X)\) gives the centre. The variance measures the spread: it is the expected squared distance from the mean,
\[ \mathrm{Var}(X) = E\big[(X - \mu)^2\big] = E(X^2) - \mu^2, \]where \(E(X^2) = \sum x^2 P(X=x)\). The second form is usually quicker. The standard deviation is \(\sqrt{\mathrm{Var}(X)}\).
Continuous random variables. A continuous variable can take any value in an interval, such as a time or a length. Its probabilities come from a probability density function (pdf) \(f(x)\):
- \(f(x) \ge 0\) for all \(x\);
- the total area under the curve is 1, so \(\displaystyle\int f(x)\,dx = 1\) over the whole range;
- \(P(a \lt X \lt b) = \displaystyle\int_a^b f(x)\,dx\), which is the area between \(a\) and \(b\);
- \(P(X = a) = 0\), so it makes no difference whether an inequality is strict.
The unknown constant in a pdf is found by setting the total area equal to 1.
Mean, median and mode.
- Mean: \(E(X) = \displaystyle\int x f(x)\,dx\).
- Median \(m\): the value that splits the area in half, so \(\displaystyle\int_{-\infty}^{m} f(x)\,dx = 0.5\). Equivalently, integrate from the lower limit of the range.
- Mode: the value of \(x\) where \(f(x)\) is greatest. Look for a turning point with \(f'(x) = 0\), or check the end points if the function is increasing or decreasing.
Expected value of a function. \(E(g(X)) = \displaystyle\int g(x) f(x)\,dx\). In particular \(E(X^2) = \displaystyle\int x^2 f(x)\,dx\), so \(\mathrm{Var}(X) = E(X^2) - [E(X)]^2\) works for continuous variables too. Integrals over the range of \(X\) can be done by hand or with the calculator's integration feature.
Linear transformations. If \(a\) and \(b\) are constants, then
\[ E(aX + b) = aE(X) + b, \qquad \mathrm{Var}(aX + b) = a^2\,\mathrm{Var}(X). \]Adding \(b\) shifts every value, so the mean moves by \(b\), but the spread does not change. Multiplying by \(a\) stretches the spread: the standard deviation is multiplied by \(|a|\), so the variance is multiplied by \(a^2\).
Interpreting the results. A large variance means the values are widely spread around the mean, and a small variance means they are bunched close to it. The variance is measured in squared units, so for a time in hours it is in hours squared. The standard deviation returns to the original units, which makes it easier to interpret. A variance can never be negative, and it is zero only if the variable always takes the same value.
For a continuous variable the pdf itself is not a probability: its height can be greater than 1 if the range is narrow. Only the area under it is a probability. This is why we integrate, and why we check that the total area is exactly 1.
Definitions and formulae
| Term or formula | Meaning / when to use |
|---|---|
| \(\mathrm{Var}(X) = E(X^2) - [E(X)]^2\) | Variance for discrete or continuous \(X\). Standard deviation is the square root. |
| \(E(X^2) = \sum x^2 P(X=x)\) or \(\displaystyle\int x^2 f(x)\,dx\) | Expected value of \(X^2\), needed for the variance. |
| \(\displaystyle\int f(x)\,dx = 1\) | Total area under a pdf is 1. Used to find unknown constants. |
| \(P(a \lt X \lt b) = \displaystyle\int_a^b f(x)\,dx\) | Probability as area under the pdf. |
| \(E(X) = \displaystyle\int x f(x)\,dx\) | Mean of a continuous variable. |
| \(\displaystyle\int_{-\infty}^m f(x)\,dx = 0.5\) | Defines the median \(m\). Start the integral at the lower end of the range. |
| \(E(aX+b) = aE(X)+b\) | Mean after a linear transformation. |
| \(\mathrm{Var}(aX+b) = a^2\mathrm{Var}(X)\) | Variance after a linear transformation. The constant \(b\) has no effect. |
Worked examples
Example 1 The time \(X\) (in hours) that a machine runs before a reset has pdf \(f(x) = kx^2\) for \(0 \le x \le 3\), and \(f(x) = 0\) otherwise. Find \(k\), \(E(X)\), \(\mathrm{Var}(X)\), the median, and \(P(1 \lt X \lt 2)\).
Total area: \(\displaystyle\int_0^3 kx^2\,dx = k\left[\dfrac{x^3}{3}\right]_0^3 = 9k = 1\), so \(k = \dfrac{1}{9}\).
Mean: \(E(X) = \displaystyle\int_0^3 \dfrac{x^3}{9}\,dx = \dfrac{1}{9}\left[\dfrac{x^4}{4}\right]_0^3 = \dfrac{81}{36} = \dfrac{9}{4} = 2.25\).
\(E(X^2) = \displaystyle\int_0^3 \dfrac{x^4}{9}\,dx = \dfrac{1}{9}\left[\dfrac{x^5}{5}\right]_0^3 = \dfrac{243}{45} = \dfrac{27}{5} = 5.4\).
\(\mathrm{Var}(X) = 5.4 - 2.25^2 = 5.4 - 5.0625 = 0.3375\).
Median \(m\): \(\displaystyle\int_0^m \dfrac{x^2}{9}\,dx = \dfrac{m^3}{27} = 0.5\), so \(m^3 = 13.5\) and \(m = 2.381\dots\).
\(P(1 \lt X \lt 2) = \displaystyle\int_1^2 \dfrac{x^2}{9}\,dx = \dfrac{8 - 1}{27} = \dfrac{7}{27} = 0.259\dots\).
Answer: \(k = \dfrac{1}{9}\); \(E(X) = 2.25\); \(\mathrm{Var}(X) = 0.3375\); median \(2.38\) hours; \(P(1 \lt X \lt 2) = 0.259\).
Example 2 A game awards \(X\) points, where \(X = 1, 2, 3, 4\) with probabilities \(0.1, 0.4, 0.3, 0.2\). A player's score is \(Y = 5X + 3\). Find \(E(X)\) and \(\mathrm{Var}(X)\), and then \(E(Y)\), \(\mathrm{Var}(Y)\) and the standard deviation of \(Y\).
\(E(X) = 1(0.1) + 2(0.4) + 3(0.3) + 4(0.2) = 0.1 + 0.8 + 0.9 + 0.8 = 2.6\).
\(E(X^2) = 1(0.1) + 4(0.4) + 9(0.3) + 16(0.2) = 0.1 + 1.6 + 2.7 + 3.2 = 7.6\).
\(\mathrm{Var}(X) = 7.6 - 2.6^2 = 7.6 - 6.76 = 0.84\).
\(E(Y) = 5(2.6) + 3 = 16\).
\(\mathrm{Var}(Y) = 5^2 \times 0.84 = 21\), so the standard deviation is \(\sqrt{21} = 4.58\dots\).
Answer: \(E(X) = 2.6\), \(\mathrm{Var}(X) = 0.84\), \(E(Y) = 16\), \(\mathrm{Var}(Y) = 21\), standard deviation \(4.58\).
Example 3 A continuous variable has pdf \(f(x) = \dfrac{3}{32}x(4 - x)\) for \(0 \le x \le 4\), and 0 otherwise. Find the mode, verify that \(E(X) = 2\), and find \(\mathrm{Var}(X)\).
Write \(f(x) = \dfrac{3}{32}(4x - x^2)\). Then \(f'(x) = \dfrac{3}{32}(4 - 2x) = 0\) gives \(x = 2\). The graph is a downward parabola, so this is the maximum. Mode \(= 2\).
\(E(X) = \displaystyle\int_0^4 \dfrac{3}{32}(4x^2 - x^3)\,dx = \dfrac{3}{32}\left[\dfrac{4x^3}{3} - \dfrac{x^4}{4}\right]_0^4 = \dfrac{3}{32}\left(\dfrac{256}{3} - 64\right) = \dfrac{3}{32}\times\dfrac{64}{3} = 2\). Verified.
\(E(X^2) = \displaystyle\int_0^4 \dfrac{3}{32}(4x^3 - x^4)\,dx = \dfrac{3}{32}\left[x^4 - \dfrac{x^5}{5}\right]_0^4 = \dfrac{3}{32}\left(256 - 204.8\right) = \dfrac{3}{32}\times 51.2 = 4.8\).
\(\mathrm{Var}(X) = 4.8 - 2^2 = 0.8\).
Answer: mode \(2\); \(E(X) = 2\); \(\mathrm{Var}(X) = 0.8\).
Common errors
- Common error: forgetting to subtract the square of the mean, and giving \(E(X^2)\) as the variance.
- Common error: writing \(\mathrm{Var}(aX + b) = a\,\mathrm{Var}(X) + b\). The correct result is \(a^2\,\mathrm{Var}(X)\), and \(b\) disappears.
- Common error: squaring the mean wrongly, using \(E(X^2) = [E(X)]^2\). These are different unless the variance is zero.
- Common error: finding the median by integrating to 1 instead of 0.5, or by taking the middle of the range.
- Common error: skipping the check that a pdf integrates to 1 before using it, so an arithmetic slip in \(k\) spreads through the whole question.
Exam tip: Keep \(E(X)\) and \(E(X^2)\) as two separate lines, then combine them in a third. Showing each step makes slips easy to spot, and the variance can never be negative, so a negative answer means you should recheck.
Check yourself
- A pdf is \(f(x) = kx\) for \(0 \le x \le 4\). Find \(k\) and \(P(X \gt 2)\).
Answer
\(\displaystyle\int_0^4 kx\,dx = 8k = 1\), so \(k = \dfrac{1}{8}\). \(P(X \gt 2) = \displaystyle\int_2^4 \dfrac{x}{8}\,dx = \dfrac{16 - 4}{16} = 0.75\). - For the pdf in question 1, find \(E(X)\).
Answer
\(E(X) = \displaystyle\int_0^4 \dfrac{x^2}{8}\,dx = \dfrac{1}{8}\times\dfrac{64}{3} = \dfrac{8}{3} \approx 2.67\). - \(E(X) = 5\) and \(\mathrm{Var}(X) = 4\). Find \(E(Y)\), \(\mathrm{Var}(Y)\) and the standard deviation of \(Y\) for \(Y = 3X - 7\).
Answer
\(E(Y) = 3(5) - 7 = 8\). \(\mathrm{Var}(Y) = 3^2 \times 4 = 36\). Standard deviation \(= 6\). - \(X = 0, 1, 2\) with probabilities \(0.5, 0.3, 0.2\). Find \(\mathrm{Var}(X)\).
Answer
\(E(X) = 0 + 0.3 + 0.4 = 0.7\). \(E(X^2) = 0 + 0.3 + 0.8 = 1.1\). \(\mathrm{Var}(X) = 1.1 - 0.49 = 0.61\).