Confidence Intervals

What “95% confident” promises and what it does not. Watch a hundred intervals try to catch the truth, see why small samples need Student’s t, and pull yourself up by the bootstrap

Confidence Intervals

An estimate without an error bar is half a sentence. A confidence interval is the other half, and the word “confidence” has a precise meaning that is easier to see than to say: it is a promise about the method, kept over many repetitions, and not a statement about any one interval.

A Hundred Intervals

Press Step to watch one interval being built, then × 1,000 and read the count of hits. Change the confidence level and the sample size, press Find a miss, and then Hide the truth to see what a statistician actually has.

Population
Confidence level
Method
100
intervals so far
99
contain μ
1
miss μ
99.0%
share that contain μ
94.6–99.8%
plausible long-run rate, given this many
2.201
t*, the multiplier in x̄ ± t*·s/√n
99 of 100 intervals contain μ (99.0%). With this many, the long-run rate is plausibly anywhere from 94.6% to 99.8%, a range that includes the promised 95%. Press × 1,000 to narrow it. Of the misses, 0 fell entirely below μ and 1 entirely above.

Slate-white: the population and its true mean μ (dashed), which the method never sees. Teal: one sample. Amber: the sample mean x̄ and the margin built around it. Each bar in the stack is one sample’s interval, emerald if it contains μ and rose if it does not; click a bar to inspect it. Changing the confidence level or the method re-judges the same samples, so you can watch the same bars stretch and change colour. Changing the population or n draws 100 new samples. The amber marker at the bottom is the share of hits so far, with a 95% Wilson band for the long-run rate.

Go deeper:What the 95% Is a Probability Of

Jerzy Neyman introduced confidence intervals in 1937. In his account the parameter μ is a fixed number, unknown but not random. What is random is the sample, and therefore the interval computed from it. A 95% confidence procedure is a recipe which, applied to sample after sample, produces intervals of which 95% contain μ. The 95% describes the recipe’s hit rate over repeated samples.

Once a particular sample is in hand and the endpoints are numbers, nothing random is left. That interval either contains μ or it does not, and “there is a 95% probability that μ lies between 9.1 and 11.4” is not what the method claims. The honest reading is: this interval came from a procedure that succeeds 95% of the time, and there is no way to tell from the interval alone whether this is one of the successes.

For a mean the interval is x̄ ± (multiplier) × (standard error), and with σ known its half-width is z*σ/√n. That formula holds the trade-off. More confidence means a larger multiplier and a wider interval: 1.28 for 80%, 1.96 for 95%, 2.58 for 99%. A larger sample narrows it, but only like 1/√n, so halving the width takes four times the data. The sample size changes the width and leaves the hit rate where it was.

A Bayesian credible interval does make a probability statement about the parameter given the data. The price is a prior distribution for the parameter, which has to be supplied in addition to the data. See also Bayesian Statistics.

Why Student Needed t

Slide the sample size down to 5, then 2, and watch the amber pile grow tails that the dashed normal curve does not have, while the rose coverage curve sags below 95%. Then switch the population to skewed.

Population
—
of simulated statistics lie beyond ±1.96
12.2%
t theory, 4 d.f., for normal data
5.0%
what the normal curve says
—
coverage of x̄ ± 1.96 s/√n at this n
—
coverage of x̄ ± t* s/√n at this n
2.776
t*, the multiplier that replaces 1.96
Simulating: 0 of 20,000 samples of 5.
The multiplier t* for a 95% interval, by sample size
n23456810152030∞
t*12.714.303.182.782.572.362.262.142.092.051.96

Top: each amber block is one sample reduced to the statistic (x̄ − μ)/(s/√n); values beyond ±6 are counted but fall off the edge of the chart. Rose shading is the area of the t curve beyond ±1.96. Bottom: for every n from 2 to 30, the share of 4,000 simulated intervals that contained μ, using 1.96 (rose) and using t* (emerald); the dotted line is the exact value for normal data, and the highlighted column is the n on the slider.

1.58
mean difference x̄, hours
1.23
standard deviation s
0.389
s/√n with n = 10
4.06
t = x̄ ÷ (s/√n), 9 d.f.
2.262
t* for 9 d.f.
0.70 to 2.46
95% interval, hours

Real data: the example in Student’s 1908 paper, from measurements by Cushny and Peebles (1905). Teal: the ten differences. Amber: their mean and the 95% t interval, x̄ ± 2.26 × 0.389. Rose: the shorter interval that 1.96 would give, which claims more precision than ten patients can supply. Here the truth is not known, so the bar cannot be coloured as a hit or a miss.

Go deeper:Gosset, Guinness and Small Samples

William Sealy Gosset was a chemist and brewer at Guinness in Dublin, where experiments on barley and malt came in small samples. Guinness did not allow its employees to publish under their own names, so “The Probable Error of a Mean” appeared in Biometrika in 1908 under the pseudonym “Student”. He found the distribution partly by simulation, drawing samples by hand from cards of measurements, much as the demo does. R. A. Fisher supplied the rigorous derivation and the modern form of t in the 1920s.

The problem is that σ is almost never known. Replacing it by the sample’s s makes the statistic (x̄ − μ)/(s/√n) a ratio of two random quantities, and when s happens to come out small the ratio is large. For normal data this ratio follows the t distribution with n − 1 degrees of freedom, which has heavier tails than the normal curve. With n = 5 about 12% of its area lies beyond ±1.96, so the interval x̄ ± 1.96 s/√n covers only about 88% of the time; with n = 2 it covers about 70%. The cure is to use the wider multiplier t* in place of 1.96: 12.71 for n = 2, 2.78 for n = 5, 2.26 for n = 10, falling towards 1.96 as n grows.

The example is the one in Student’s paper: the extra sleep of ten patients on two drugs. The ten differences have mean 1.58 hours and t = 4.06 on 9 degrees of freedom, and the 95% interval runs from 0.70 to 2.46 hours.

The t interval is exact when the data are normal and holds up well under moderate departures from normality. Strong skewness at small n is its weak point: the interval then misses more often than promised, and mostly on one side.

The Bootstrap

Press Step to draw one resample, then Fill to 10,000 and read the middle 95% of the pile. Drag a dot out to make an outlier, reveal the population, and try the maximum of the uniform sample, where the method fails.

Data
Statistic
10.29
this sample’s median
500
resamples so far, of up to 10,000
8.90 to 11.32
95% percentile interval
0.482
bootstrap standard error: the spread of the pile
36.0%
of the points left out of a resample, on average; theory says 36.0%
—
coverage over repeated trials (not run yet)
This sample’s median is 10.29. The middle 95% of 500 resampled values runs from 8.90 to 11.32: the percentile interval, built with no formula for how a median varies.

Teal: the sample in hand (left) and one resample of it (right), where a dot drawn several times grows and a dot never drawn turns grey. Amber: the statistic, and the pile of its values over all the resamples; bars beyond the middle 95% are greyed. Slate-white, once revealed: the population, its true value, and the statistic’s real sampling distribution from 4,000 fresh samples. The simulated samples are drawn from a skewed population, a uniform one on 0 to 20, or pairs with correlation 0.6; Anscombe’s set I is real data. Dragging a dot restarts the resampling. The coverage check draws fresh samples from the population and ignores any dots you have moved.

Go deeper:Efron’s Idea, and Its Limits

A median, a trimmed mean or a correlation has no formula as simple as s/√n for its standard error. Bradley Efron’s answer, in “Bootstrap Methods: Another Look at the Jackknife” (Annals of Statistics, 1979), was to let the sample stand in for the population. Draw n values from the sample with replacement, compute the statistic, and repeat thousands of times; the spread of those values estimates how the statistic would vary from one real sample to the next. The name comes from the phrase about pulling oneself up by one’s own bootstraps. Because the draws are with replacement, each resample leaves out a share (1 − 1/n)n of the points on average, which is close to 1/e, about 36.8%.

The bootstrap estimates the spread of a statistic well. It cannot manufacture information the sample lacks: the pile is centred on the sample’s own value, not on the truth, and a small or unrepresentative sample gives a poor stand-in for the population. It also fails outright for some statistics. The sample maximum is the standard counterexample, because no resample can contain a value larger than the largest one observed.

The percentile interval, the middle 95% of the bootstrap values, is the simplest of several bootstrap intervals. For small samples it tends to cover somewhat less often than promised, as the coverage check shows; refinements such as the BCa and bootstrap-t intervals usually do better.

Formulas can mislead too. For a proportion, the textbook Wald interval p̂ ± 1.96 √(p̂(1 − p̂)/n) covers poorly when n is small or p is near 0 or 1. With n = 20 its true coverage falls below 90% for many values of p, and to about 64% at p = 0.05. The interval Edwin Wilson proposed in 1927 stays above 92% across p from 0.05 to 0.95 at the same n, and Brown, Cai and DasGupta (2001) recommended it over Wald.

Key Takeaways

  • “95% confidence” is the hit rate of the procedure over repeated samples; a single computed interval either contains the truth or does not.
  • More confidence widens the interval and more data narrows it, in proportion to 1/√n.
  • With s in place of σ, small samples need Student’s t* instead of 1.96, or the interval covers too rarely.
  • The bootstrap resamples the data to find a statistic’s spread without a formula, but it cannot see beyond the sample.

Spot a mistake or have an idea?

Search