Confidence intervals explained, with a worked example

Updated

A confidence interval is a range, computed from a sample, that is likely to contain the true value of a process parameter such as its mean, standard deviation or defect rate. A 95% confidence interval comes from a method that captures the true value in 95% of samples. Its width tells you how precisely the data pin the value down: a narrow interval means you know it well, a wide one means you need more data. For engineering decisions it is often more useful than a p-value, because it shows the size of an effect, not just whether one exists.

The idea in one picture

Take a sample of ten parts and compute the mean. Take another ten and the mean will be a little different. The standard error, s/√n, measures how much sample means wobble. A confidence interval reaches out from the sample mean by a few standard errors on each side, enough to catch the true mean most of the time:

x̄ ± t(1 − α/2, n − 1) · s / √n

The t value comes from the t distribution with n − 1 degrees of freedom. It is larger than the normal z value of 1.96 for small samples, to allow for the extra uncertainty of estimating σ from the same data.

Worked example: pull-off strength of bonded brackets

A plant bonds steel brackets to panels with a structural adhesive. The design requires an average pull-off strength of at least 400 N. The lab pulls ten brackets from a trial run:

Bracket12345678910
Strength (N)412398425407391418403429396411

The mean is x̄ = 409.0 N and the sample standard deviation is s = 12.490 N.

SE = s / √n = 12.490 / √10 = 3.9497 N t(0.975, 9) = 2.2622 95% CI = 409.0 ± 2.2622 × 3.9497 = 409.0 ± 8.93 N, from 400.07 to 417.93 N

The true mean strength of this process is most likely between 400.1 and 417.9 N. You can check each step in the super calculator: TINV(0.975, 9) gives 2.26215716280.

Does it meet the 400 N requirement? The question is one-sided: only a low mean is a problem. The one-sided 95% lower confidence bound uses t(0.95, 9) = 1.8331:

lower bound = 409.0 − 1.8331 × 3.9497 = 401.76 N

With 95% confidence, the mean is at least 401.8 N, so the requirement on the mean is met, though with little margin. Notice that two of the ten brackets, at 398 and 391 N, are below 400 N. The interval is about the mean, not about individual brackets; if the requirement applies to each bracket, you need a tolerance interval or a capability analysis instead.

Choosing the confidence level

Higher confidence means a wider interval, for the same data:

Confidencet (9 degrees of freedom)Half-width (N)Interval (N)
90%1.83317.24401.76 to 416.24
95%2.26228.93400.07 to 417.93
99%3.249812.84396.16 to 421.84

The 99% interval reaches below 400 N. Nothing about the brackets changed; you simply asked for more certainty, and the price is width. 95% is the usual choice. A two-sided 90% interval has the one-sided 95% bound as its lower end, which is why both give 401.76 N.

Sample size sets the width

The half-width shrinks with the square root of the sample size, so halving it takes about four times the data. For a process with s = 12.5 N, the 95% half-width for the mean is:

Half-width of a 95% confidence interval for the mean (s = 12.5 N)102030Half-width (N)3510204080Sample size n
Half-width of a 95% confidence interval for the mean (s = 12.5 N)

Going from 3 to 10 parts cuts the half-width from 31.1 to 8.9 N, a big gain, because both the √n and the t value improve. Going from 40 to 80 parts only takes it from 4.0 to 2.8 N. Decide how precise the estimate must be, then choose n; see sample size for estimation.

What "95% confident" means

The 95% describes the method, not one particular interval. If you repeated the trial many times and computed an interval each time, about 95% of those intervals would contain the true mean. In a computer simulation of 10,000 such trials from a process with a true mean of 410 N and σ = 12.5 N, 94.7% of the 95% intervals contained 410 N, as expected within simulation noise.

For any single interval, the true mean is either inside or not; you do not know which. Saying "there is a 95% probability the true mean is between 400.1 and 417.9 N" is a common shorthand, but strictly the confidence is in the procedure.

Intervals for other parameters

Standard deviation. Variation is often more important than the mean. For normal data, the interval for σ uses the chi-square distribution:

s · √((n − 1) / χ²(0.975, n − 1)) to s · √((n − 1) / χ²(0.025, n − 1))

With χ²(0.975, 9) = 19.023 and χ²(0.025, 9) = 2.700, the brackets give 8.59 to 22.80 N. The interval is wide and lopsided: ten parts estimate a standard deviation only roughly, which is why capability indices from small samples are so uncertain. CHISQINV(0.975, 9) gives the 19.023.

Proportion. A crack test finds 2 cracked welds in 250, so p̂ = 0.8%. The simple textbook (Wald) interval, p̂ ± 1.96√(p̂(1 − p̂)/n), gives 0.8% ± 1.10%, from −0.30% to 1.90%. A negative defect rate is impossible, a sign that the method fails for small counts. The Wilson score interval stays within 0 and 1 and behaves well with few defects:

(p̂ + z²/2n ± z·√(p̂(1 − p̂)/n + z²/4n²)) / (1 + z²/n)

With z = 1.96 and n = 250, it gives 0.22% to 2.87%. For counts of defects this small, prefer Wilson or an exact interval; see the one-proportion test.

Confidence intervals and hypothesis tests

A two-sided 95% interval contains exactly the values a two-sided test at α = 0.05 would not reject. The bracket interval, 400.07 to 417.93 N, excludes 400 N but only just, so a two-sided one-sample t-test of μ = 400 N gives t = 9.0 / 3.9497 = 2.279 and p = 0.049, just under 0.05. The interval tells you more: it shows the plausible range of the mean, which a p-value alone cannot. See hypothesis testing explained and what a p-value means.

For a difference between two groups, the same logic applies: if the interval for the difference includes zero, the data do not show a difference; if it excludes zero, its ends show how big the difference could plausibly be.

Common mistakes

  • Treating the interval as a range for individual parts. It is about the mean. Individual values spread much wider, here from 391 to 429 N.
  • Using z = 1.96 with small samples. With n = 10, t = 2.262, and the z interval would be about 13% too narrow.
  • Ignoring how the data were collected. Ten brackets from one batch of adhesive give an interval for that batch, not for next month's production.
  • Using the Wald interval for rare defects. It can go negative and covers the true rate less often than claimed.
  • Comparing two groups by whether their separate intervals overlap. Overlapping intervals can still hide a significant difference. Compute the interval for the difference itself, for example with a two-sample t-test.

Frequently asked questions

What is the difference between a confidence interval and a tolerance interval?

A confidence interval brackets a parameter, such as the mean. A tolerance interval brackets a stated share of individual values, such as 99% of all parts, with a stated confidence. For specifications that apply part by part, the tolerance interval answers the right question.

Why is my interval so wide?

Too few data, too much variation, or both. The half-width is proportional to s/√n. Reduce noise in the measurement, or take more samples: four times the data halves the width.

Can I make a one-sided interval?

Yes, when only one direction matters, such as a minimum strength or a maximum impurity. Use t(1 − α, n − 1) instead of t(1 − α/2, n − 1) and report only the relevant bound, as with the 401.76 N lower bound above.

Does the confidence interval assume normal data?

The interval for the mean is fairly robust, especially as n grows, because sample means tend toward a normal distribution. The interval for the standard deviation is much more sensitive to non-normal data. Check the shape with a normality test or a probability plot.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab