Probability & Statistics · Confidence interval

Confidence interval

A 95% confidence interval is computed from a sample by a method that, over repeated samples, captures the true value 95% of the time. Each interval here comes from one sample of n values; the blue line is the true mean μ, and the yellow intervals either cover it or miss it.

Confidence intervals in this visualization

A confidence interval estimates an unknown number, here the population mean μ\mu, 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 nn independent draws from a normal population with μ=50\mu = 50 and σ=10\sigma = 10; each row of the stack is one sample’s interval, and the blue line is μ\mu.

Why can’t one interval claim a 95% chance of containing μ\mu? Here μ\mu 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 μ\mu is 95%; once it is drawn, that interval either contains 50 or it does not. The band shows why the rule works when σ\sigma is known. The interval xˉ±ME\bar x \pm \mathrm{ME} covers μ\mu exactly when ∣xˉ−μ∣≤ME|\bar x - \mu| \le \mathrm{ME}, that is, when xˉ\bar x falls in the band μ±ME\mu \pm \mathrm{ME} of the same width. Since Xˉ\bar X is normal with standard deviation σ/n\sigma/\sqrt{n}, it lands in that band 95% of the time when ME=z∗σ/n\mathrm{ME} = z^*\sigma/\sqrt{n}. A probability for μ\mu itself needs a prior distribution for μ\mu; that is a Bayesian credible interval, a different construction.

What sets the width? With σ\sigma known, the half-width is the margin of error z∗σ/nz^*\sigma/\sqrt{n}, where z∗z^* leaves half of the remaining probability in each tail of the standard normal. Each step towards 100% costs more width than the last: z∗z^* 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 σ/n\sigma/\sqrt{n} (the sampling distribution), so at a fixed level the width shrinks in proportion to 1/n1/\sqrt{n}. The coverage does not change with nn: the margin is always measured in units of the spread of xˉ\bar x.

Why does an unknown σ\sigma need tt? Putting the sample’s ss in place of σ\sigma makes both the centre and the width random. A sample whose ss comes out small gets a short interval, so misses gather among the short intervals, and with z∗z^* the coverage is 2Fn−1(z∗)−12F_{n-1}(z^*) - 1, below the level, where Fn−1F_{n-1} is the distribution function of Student’s tt with n−1n - 1 degrees of freedom. That is the distribution of (Xˉ−μ)/(S/n)(\bar X - \mu)/(S/\sqrt{n}) for normal data. Its tails are heavier than the normal’s, so its point t∗t^* is larger than z∗z^*, and xˉ±t∗s/n\bar x \pm t^* s/\sqrt{n} covers exactly at the level. Correcting the average of ss alone is not enough: s/c4s/c_4 estimates σ\sigma without bias, yet used with z∗z^* at a nominal 95% it still covers only about 89.5% at n=5n = 5. As nn grows, ss settles near σ\sigma and t∗t^* approaches z∗z^*.

Things to notice

  • The interval is for the mean, not for the data. With σ\sigma known, n=25n = 25 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 nn needs new samples.

Related