The spread of a random variable · Statistics & Data… | StemPy Lab
Course 4.1·Lesson 3 of 3
The spread of a random variable
Two random variables can have the same mean and very different spreads. The variance σ2 is the mean squared distance from the mean, and the standard deviation σ
Lesson 3 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
find the variance and the standard deviation of a random variable from its table;
use the shortcut E(X2)−μ2;
say which of the n and n−1 formulas a distribution uses, and why a simulated sample comes close.
Two bus routes
Two made-up bus routes go to the same school. The delay of each bus, in minutes, follows these tables.
Route A:
delay (min)
2
3
4
P
0.25
0.5
0.25
Route B:
delay (min)
0
2
6
8
P
0.4
0.2
0.3
0.1
Both have a mean delay of 3 minutes. Check route B: 0+0.4+1.8+0.8=3. Yet route A is always within a minute of 3, while route B is often on time and sometimes 8 minutes late. If you must not be late, the mean does not tell you enough.
Two bar charts side by side for the delay of two made-up bus routes, in minutes. Route A has bars at 2, 3 and 4 minutes with heights 0.25, 0.5 and 0.25. Route B has bars at 0, 2, 6 and 8 minutes with heights 0.4, 0.2, 0.3 and 0.1. A dashed line marks the mean of 3 minutes on both.
Variance and standard deviation
For data, you measured spread by the distance of each value from the mean. A random variable works the same way, with each squared distance weighted by its probability. The variance is
σ2=∑(x−μ)2P(X=x).
The standard deviation is its square root, σ. It has the same unit as X. The variance has the unit squared.
For route A: (2−3)2×0.25+0+(4−3)2×0.25=0.5min2. So σ≈0.707min.
For route B: 9×0.4+1×0.2+9×0.3+25×0.1=9min2. So σ=3min.
Route B spreads about four times as widely. That is the number a careful traveller wants.
A shortcut
Expanding the squares gives an equal formula that is often quicker:
σ2=E(X2)−μ2,E(X2)=∑x2P(X=x).
For route B, E(X2)=0+4×0.2+36×0.3+64×0.1=18. So σ2=18−32=9, as before.
The n formula or the n−1 formula?
In the chapter on describing distributions you met two standard deviations of data. One divides by n (the population formula). The other divides by n−1 (the sample formula). The σ of a random variable is the population kind: the probabilities already add up to 1, so nothing more is divided.
A long simulation is a sample. Its standard deviation, by either formula, comes close to σ. With thousands of values the two formulas give almost the same number.
You should find that the standard deviation grows in step with d, but only with the square root of w. Doubling d doubles σ. Doubling w multiplies σ by about 1.41.
Changing the units
What if every bus on route B ran 5 minutes later? Every value moves up by 5min, so the mean becomes 8min. The distances from the mean do not change, so σ stays 3min. What if we measure in seconds? Every value is multiplied by 60. The mean becomes 180s and σ becomes 180s too.
Try it in Python
The program finds the mean, the variance and the standard deviation of both routes with exact fractions. Then it simulates 5000 days of route B and measures the spread of that sample both ways.
Your turn
The usual mistakes
Forgetting to weight by the probabilities. Each squared distance is multiplied by its probability.
Stopping at the variance. The standard deviation is the square root, and it has the unit of X.
Writing E(X2) as μ2. They are different. Their difference is the variance.
Thinking that adding a constant changes the spread. It moves every value together, so σ stays the same.
Remember these
σ2=∑(x−μ)2P(X=x)=E(X2)−μ2.
σ is in the unit of X, and σ2 is in that unit squared.
A distribution's σ is the population kind. A long simulation's sample σ comes close to it.
Adding a constant leaves σ alone. Multiplying every value by a multiplies σ by ∣a∣.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Route A and route B have the same mean delay. Which is more reliable, and which number shows it?
X is 0 or 2, each with probability 0.5. Find the mean, the variance and the standard deviation.
X is a mass in grams. What is the unit of its variance?
Every delay on route A goes up by 4 minutes. What happens to the mean and to the standard deviation?
Can a standard deviation be negative? When is it zero?
References
OpenStax, Introductory Statistics, Chapter 4, section on the mean or expected value and the standard deviation.
Enroll free in Random Variables and Expected Value
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.