Sub topic 5
Variance and Standard Deviation as Spread
Assume you know how to calculate a mean and basic probabilities. This chapter uses the expected value, which is the probability-weighted mean of a random variable.
Why spread matters
A mean describes the center of a distribution, but it does not describe how far values usually lie from that center. Two tests can have the same mean score while one has scores tightly grouped and the other has scores spread widely.
Variance and standard deviation measure this spread.
- Variance is the probability-weighted average of squared distances from the mean.
- Standard deviation is the square root of the variance.
- A small standard deviation means values tend to stay close to the mean.
- A large standard deviation means values tend to be farther from the mean.
For a random variable \(X\) with mean \(\mu\), the variance is
\[ \operatorname{Var}(X)=E[(X-\mu)^2]. \]
The standard deviation is
\[ \sigma=\sqrt{\operatorname{Var}(X)}. \]
Squaring the distances prevents positive and negative deviations from canceling. It also means that variance has squared units. If scores are measured in points, variance is measured in points squared. Standard deviation returns to the original unit, points, so it is usually easier to interpret.
Computing variance for a discrete variable
For possible values \(xi\) with probabilities \(pi\),
\[ \mu=\sum xi pi \]
and
\[ \operatorname{Var}(X)=\sum (xi-\mu)^2pi. \]
Consider this distribution:
| Value \(x\) | Probability \(P(X=x)\) |
|---|---|
| 1 | 0.10 |
| 2 | 0.20 |
| 3 | 0.30 |
| 4 | 0.40 |
The expected value is
\[ \mu=1(0.10)+2(0.20)+3(0.30)+4(0.40)=3. \]
Now calculate the weighted squared distances:
\[ \begin{aligned} \operatorname{Var}(X) &=(1-3)^2(0.10)+(2-3)^2(0.20)\\ &\quad +(3-3)^2(0.30)+(4-3)^2(0.40)\\ &=0.40+0.20+0+0.40=1. \end{aligned} \]
Therefore,
\[ \sigma=\sqrt{1}=1. \]
The typical distance from the mean is about 1 unit.
from fractions import Fraction
values = [1, 2, 3, 4]
probs = [Fraction(1, 10), Fraction(2, 10),
Fraction(3, 10), Fraction(4, 10)]
mean = sum(v * p for v, p in zip(values, probs))
variance = sum((v - mean) ** 2 * p
for v, p in zip(values, probs))
standard_deviation = variance ** Fraction(1, 2)
print(mean, variance) # 3 1For exact arithmetic, the variance calculation is more useful than the final square-root line. In general, use a calculator for the square root when the variance is not a perfect square.
A reliable calculation process
Use this order:
- Find the mean.
- Subtract the mean from each possible value.
- Square each difference.
- Multiply each square by its probability.
- Add the weighted squares.
- Take the square root if standard deviation is requested.
A shortcut is
\[ \operatorname{Var}(X)=E[X^2]-\mu^2. \]
This can save time, but it is easier to misuse. Compute \(E[X^2]\) by squaring each value before multiplying by its probability. Do not square the mean first and call that \(E[X^2]\).
GRE pitfalls
- Do not confuse variance with standard deviation. If variance is 25, the standard deviation is 5.
- Do not forget probabilities. Each squared deviation must be multiplied by its probability.
- Adding a constant to every value changes the mean but does not change the standard deviation.
- Multiplying every value by \(c\) multiplies the standard deviation by \(|c|\) and the variance by \(c^2\).
- A standard deviation cannot be negative, although an individual deviation from the mean can be negative.
- A variance of zero means every possible value equals the mean.
Exercise
A random variable has mean 10 and variance 16. What are its standard deviation and the variance after adding 5 to every value?
Show answer
The standard deviation is √16 = 4. Adding 5 changes the mean but leaves the variance unchanged, so the new variance is 16.