CLT simulator
Choose a population, the size n of each sample and how many samples to draw. Each sample's values drop out of the population, their mean falls into the histogram below, and the histogram builds up against the normal curve the central limit theorem predicts, N(μ, σ/√n). The axis never changes, so a larger n visibly narrows the histogram.
Goes with chapter 10. Sampling distributions and the CLT
Population
Every value from 0 to 10 equally likely: no peak at all.
Number of samples
- Population
- One sample's values
- Its mean
- Histogram of the sample means
- N(μ, σ/√n)
After 500 samples of n = 5, the means average 5.0446, and their standard deviation, the observed standard error, is 1.2637; the CLT predicts σ/√n = 1.2910.
Predicted and observed
| Quantity | Predicted by the theory | Observed in this run |
|---|---|---|
| Mean of the sample means | μ = 5.0000 | 5.0446 |
| Standard error | σ/√n = 1.2910 | 1.2637 |
| Skewness of the sample means | γ/√n = 0.0000 | 0.0702 |
| Share within 1.96 standard errors of μ | 0.9500 | 0.9620 |
rng.uniform(0, 10, size=(500, 5)).mean(axis=1)
What to look for
- Choose the exponential and move n from 1 to 50. At n = 1 the histogram is the population itself, skewed to the right; by n = 30 it is close to the bell, though its right tail is still a little longer than the curve's.
- Keep the population and watch the width: the axis is fixed, so as n grows the histogram narrows. The observed standard error follows σ/√n: quadruple n and it halves.
- Choose the normal and set n = 2: the means are already a perfect bell, because the mean of normal values is exactly normal.
- Choose the bimodal: hardly any single value lies near its mean of 5, yet by n = 10 the sample means pile up right there.
- Change the number of samples, not n: 100 samples give a ragged histogram and 2,000 a smooth one, but its width stays the same. n is the knob the theorem is about.