Confidence intervals in this visualization
A confidence interval estimates an unknown number, here the population mean , by a range computed from one sample. The rule that turns a sample into an interval is fixed in advance, and its confidence level, such as 95%, is the share of samples whose interval covers the true value. On this page every sample consists of independent draws from a normal population with and ; each row of the stack is one sample’s interval, and the blue line is .
Why can’t one interval claim a 95% chance of containing ? Here is a fixed number and the interval is what changes from sample to sample. Before the sample is drawn, the chance that its interval will cover is 95%; once it is drawn, that interval either contains 50 or it does not. The band shows why the rule works when is known. The interval covers exactly when , that is, when falls in the band of the same width. Since is normal with standard deviation , it lands in that band 95% of the time when . A probability for itself needs a prior distribution for ; that is a Bayesian credible interval, a different construction.
What sets the width? With known, the half-width is the margin of error , where leaves half of the remaining probability in each tail of the standard normal. Each step towards 100% costs more width than the last: is about 1.645 at 90%, 2.576 at 99% and 3.29 at 99.9%, and no finite interval is 100% sure. The standard error of the mean is (the sampling distribution), so at a fixed level the width shrinks in proportion to . The coverage does not change with : the margin is always measured in units of the spread of .
Why does an unknown need ? Putting the sample’s in place of makes both the centre and the width random. A sample whose comes out small gets a short interval, so misses gather among the short intervals, and with the coverage is , below the level, where is the distribution function of Student’s with degrees of freedom. That is the distribution of for normal data. Its tails are heavier than the normal’s, so its point is larger than , and covers exactly at the level. Correcting the average of alone is not enough: estimates without bias, yet used with at a nominal 95% it still covers only about 89.5% at . As grows, settles near and approaches .
Things to notice
- The interval is for the mean, not for the data. With known, and 95%, on average only about 31% of a sample’s values lie inside its own interval.
- When the method’s true coverage is 95%, the share covered among the last 100 intervals wanders with a standard error of about 2.2 percentage points; over 10 000 samples it is about 0.22 points.
Controls
- The level knob is spaced by the distance to 100%: 90%, 99% and 99.9% are equally far apart, where the width changes fastest.
- Click a row of the stack, or use ↑ ↓ on the focused graph, to show that interval’s sample above; a click during a run pauses it. The level and the formula recompute the same samples’ intervals; a new needs new samples.