A true value sits still. A hundred samples each throw an interval around their own estimate. Watch how many catch it.
Most intervals catch the truth
100 samples of 25 from a bell with mean 10 and spread 2, each with its interval (seed 6400).
The true mean is 10, the line that never moves. Each run draws 25 values and builds a 95 % interval from them.
Predict first. Of 100 intervals at 95 %, how many will contain the true mean?
Describe this picture
A vertical line, labelled “true mean 10”, marks the true mean of a bell-shaped population with standard deviation 2; it never moves. Each run draws a sample of 25 values (seed 6400) and draws its 95 % interval, the interval with the sample’s own , as a thin horizontal bar, one run per row, with a dot at the sample mean, on an axis from 7.5 to 12.5. Before the clip a question asks how many of 100 intervals will contain the true mean: all 100, about 95, or about 50, drawn as small bars. A tap picks one and starts the clip. In the clip the 100 rows appear one after another; the bars that miss the line are drawn thicker in a second colour, and a bar at the top counts the hits: 98 of 100 for this seed, with rows 3 and 53 missing. At the end your guess is a dotted mark on that count bar. Readouts give the level and the hits. After the clip a slider, “Confidence level, %”, sets the level from 50 % to 99 % in steps of 1, and every bar widens or narrows: 48 hits at 50 %, 91 at 90 %, 99 at 99 %.
Intervals around a fixed true mean
Before the clip you guessed. About 95 of the 100 intervals contain the true mean; a few miss. The clip’s 100 runs gave 98 hits, two misses: ordinary, because the count of hits wobbles around 95 by about 2.
Look at what moves. The line never moves: the true mean is a fixed number, 10. The intervals move, because each one is built from a different random sample. Some are wider than others, because each sample’s spread is different too.
An interval like this is a confidence interval. Its confidence level, here 95 %, is a property of the recipe: if you used the recipe on sample after sample, it would catch the true value in 95 % of them.
Building the interval
The recipe starts from the sample mean . Over repeated samples of size , the sample mean has mean and standard deviation , and by The central limit theorem its distribution is close to a bell. Its standard deviation is the standard error of the mean.
For a bell, 95 % of the area lies within 1.96 standard deviations of the centre. I write that edge : the point of the standard bell with 0.975 of the area below it, leaving 0.025 in each tail. So, before the sample is drawn,
Turn the inequality around: is within of exactly when is within that distance of . That gives the interval
The probability statement is about , a random variable, before the data arrive. Once a sample gives a number , the interval is two fixed numbers, and the true mean is either inside it or not.
For other levels, swap the 1.96 for another edge: for 50 %, for 80 %, for 90 %, for 99 %. After the clip, drag the level: higher confidence needs wider intervals.
When the spread is unknown: the t interval
In practice is unknown too, so I put the sample standard deviation in its place. That adds a second source of wobble: itself varies from sample to sample, and with small samples it is sometimes much too small. To keep 95 % coverage, the edge must be wider than 1.96.
The right edge comes from the t law with degrees of freedom, a bell with heavier tails, worked out for bell-shaped data. I write its 0.975 point :
For , ; for , . As grows it approaches 1.96. The picture uses this t interval for each sample of 25.
What “95 %” does and does not say
Watch out
Three readings of a 95 % interval are common and wrong. In one study, researchers and students accepted on average more than three of six such false statements.
- “There is a 95 % chance that the true value lies in this interval.” Once computed, the interval either contains the fixed true value or it does not; the 95 % belongs to the recipe, over many samples.
- “95 % of the data lie in the interval.” The interval is about the mean, not about single values; most single values lie well outside an interval for the mean.
- “A repeat experiment will give a mean inside this interval 95 % of the time.” The next sample’s mean has its own scatter around the true value, not around this interval’s centre.
What it does say, in one sentence: the recipe that made this interval catches the true value in 95 % of the samples it is used on. The hundred bars in the picture are that sentence, drawn.
A proportion
For a share, such as the fraction of voters for a party, the estimate is , the share in the sample. By Discrete random variables the count of yes answers is binomial, so has standard error , which is estimated by putting for :
This plain interval works when the counts of yes and no are both reasonably large. With small counts it can run below 0 or above 1. A better recipe, the Wilson interval, solves for the values of that sit within 1.96 standard errors of , and always stays between 0 and 1. Software computes it; the worked example quotes it.
How much data
With a known spread, an interval for a mean has half-width , so the width falls like .
Four times the data, half the margin
The half-width of a 95 % interval for a mean, with known spread 2, against the number of draws.
The half-width of a 95 % interval for a mean, 1.96 × 2/√n, against the sample size n.
Describe this picture
One panel: the half-width of a 95 % interval for the mean of a bell-shaped population with known standard deviation 2, , plotted against the sample size from 1 to 200. The clip traces the curve and marks two points, with dashed guides to both axes: 0.784 at 25 draws and 0.392 at 100 draws. Four times the data gives half the margin. Readouts give and the margin. The panel has a play button and no other control.
To make the half-width at most a chosen margin, solve for :
For a proportion, is never more than , its value at . So the worst case needs
Worked example
1. An opinion poll. Of 1000 people asked, 540 support a plan, so . The standard error is , the margin , and the 95 % interval runs from to .
At the worst case the margin is : the familiar “plus or minus 3 points” of a poll of 1000. For plus or minus 2 points you need people, and for 1 point, . Halving the margin costs four times the people.
2. Eight response times. The eight times of Describing data have ms and ms. The standard error is . With the margin is , and the interval runs from to ms.
Using 1.96 instead would give a margin of , too narrow: with only eight values, is too uncertain to treat as the true spread.
3. A small count. Three of 20 parts fail a test, so . The plain interval is , which runs below 0, an impossible failure rate. The Wilson interval is to .
4. Known spread. With and , the 95 % half-width is . With it halves, to .
Try it yourself. A large sample with , and gives the interval . The same sample gives a wider interval at 99 %: catching the truth more often needs more room.
Where you’ll meet this
Polls and elections. Every published poll carries a margin of error, the half-width of a 95 % interval for a share, usually quoted for the worst case .
Experiments. An A/B test on a website reports the difference in sign-up rates between two versions with an interval. An interval for the difference that excludes 0 is evidence of a real difference, the question of Significance tests.
Measurements. A lab result such as "" is an estimate with an uncertainty. Whether the is one standard error or a 95 % half-width must be stated; it differs by a factor of about 2.
Planning. The sample-size formula decides how many users to survey, patients to enrol or parts to test before the work starts.
In signal processing · error bars on a spectrum
A spectrum estimated by averaging periodograms has a spread, relative to its value, of about , the variance of a mean again. Averaged periodograms: Bartlett and Welch in the signal processing course uses it to put error bars on a spectrum.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Standard error of the mean | , estimated by | spread of over samples |
| Known spread | ||
| Unknown spread | ; | |
| Proportion | small counts: Wilson | |
| Other levels | 50, 80, 90, 99 %: 0.6745, 1.2816, 1.6449, 2.5758 | edges of the standard bell |
| Sample size for a mean | ||
| Sample size for a share | 2401 for 2 points | |
| Meaning of 95 % | the recipe catches the truth in 95 % of samples | not a chance for this one interval |