Foundations to Frontier
Tests
A. Mathematical Foundations › A5 Statistics › Descriptive and inferential statistics

Confidence Intervals

A confidence interval turns an estimate and its standard error into a range with a guaranteed long-run hit rate. You will build z, t, variance and proportion intervals, see what '95%' does and does not mean, learn why the textbook Wald interval for proportions fails near 0 and 1 (and why Wilson and Clopper–Pearson don't), derive intervals by inverting tests and pivots, plan sample sizes for a target width, and apply the rule of three to certify reliability after zero failures.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A net, not a point

Your best guess for a robot’s average battery life is 37.2 hours. But your guess came from a limited test, so the truth is probably near 37.2, not exactly there. A confidence interval gives a range instead: “between 36.2 and 38.2 hours”. The method is designed so that if you repeated the whole test many times, 95% of the ranges you built would catch the true value.

Think of throwing a net. The fish (the truth) doesn’t move. Your net lands in a slightly different place each time, and a good net catches the fish 95% of the time.

Fifty experiments, fifty intervals: how many catch the truth?
1 of these 50 miss · coverage over 2000 experiments: 94.8% (nominal 95%) · t critical value ≈ 2.776 vs z = 1.96
Each horizontal bar is one experiment's interval; green vertical: the truth. Orange bars missed. The confidence level is the long-run hit rate of the procedure: any single interval either contains the truth or doesn't. With small n, using 1.96 with an estimated σ (try z vs t at n = 3) or Wald for a rare event (p = 0.03, n = 30) gives far less than the promised coverage. The t interval and Wilson fix them.
Why engineers care

“The new controller reduced tracking error by 12%” means little without an interval: is it 12% ± 2% or 12% ± 30%? Intervals also answer certification questions: after 1000 failure-free test flights, how sure are you that the failure rate is below 1 in 300?

📝 Quick check (Level 0)
0/3 answered
  1. 1. A 95% confidence interval method…
  2. 2. More data usually makes the interval…
  3. 3. In the net analogy, what moves from experiment to experiment?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The basic recipe: estimate ± critical value × SE

  • Mean, σ known: xˉ±z1−α/2 σ/n\bar x\pm z_{1-\alpha/2}\,\sigma/\sqrt n, with z=1.645,1.96,2.576z = 1.645, 1.96, 2.576 for 90/95/99%.
  • Mean, σ unknown (normal data): xˉ±t1−α/2,n−1 s/n\bar x\pm t_{1-\alpha/2, n-1}\,s/\sqrt n. For n=5n = 5, t=2.776t = 2.776, not 1.96 (A5.1-2).
  • Proportion (large n, p not near 0 or 1): p^±1.96p^(1−p^)/n\hat p\pm1.96\sqrt{\hat p(1 - \hat p)/n}.
  • Difference of means: (xˉ1−xˉ2)±ts12/n1+s22/n2(\bar x_1 - \bar x_2)\pm t\sqrt{s_1^2/n_1 + s_2^2/n_2} (Welch).

What “95%” means

It’s a property of the procedure, not of one computed interval. After you compute [36.2, 38.2], the truth is either in it or not. There’s no 95% probability attached to this particular interval (that’s the Bayesian credible interval’s job, A5.2-1). Over many repetitions, 95% of such intervals cover.

Sample size for a target width

The half-width is h=zσ/nh = z\sigma/\sqrt n, so n=(zσ/h)2n = (z\sigma/h)^2. Halving the width needs 4× the data.

📝 Quick check (Level 1)
0/3 answered
  1. 1. x̄ = 37.2, σ = 4, n = 64: the 95% z-interval half-width is…
  2. 2. With n = 5 and estimated σ, the multiplier should be…
  3. 3. To halve an interval's width you need…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Proportions done right

The Wald interval p^±zp^(1−p^)/n\hat p\pm z\sqrt{\hat p(1 - \hat p)/n} under-covers badly for small nn or pp near 0 or 1. With 0 successes it collapses to the single point [0, 0]. With p=0.05p = 0.05 and n=40n = 40, its actual coverage is about 87% (Brown, Cai and DasGupta, 2001).

  • Wilson: invert the score test, i.e. solve ∣p^−p∣≤zp(1−p)/n\lvert\hat p - p\rvert\le z\sqrt{p(1 - p)/n} for pp. Centre p^+z2/2n1+z2/n\frac{\hat p + z^2/2n}{1 + z^2/n}. Coverage is close to nominal, even at small nn.
  • Clopper–Pearson (“exact”): invert the binomial test. Its bounds are beta quantiles. It’s guaranteed to cover ≥95%\ge95\%, but it’s conservative.

Pivots and test inversion

A pivot is a function of the data and the parameter whose distribution doesn’t depend on the parameter. Examples: Xˉ−μs/n∼tn−1\frac{\bar X - \mu}{s/\sqrt n}\sim t_{n-1} and (n−1)s2σ2∼χn−12\frac{(n-1)s^2}{\sigma^2}\sim\chi^2_{n-1}. Solving P(a≤pivot≤b)=0.95P(a\le\text{pivot}\le b) = 0.95 for the parameter gives an interval. For the variance it’s [(n−1)s2χ0.9752,(n−1)s2χ0.0252]\big[\frac{(n-1)s^2}{\chi^2_{0.975}}, \frac{(n-1)s^2}{\chi^2_{0.025}}\big]: asymmetric, and wide for small nn.

More generally, a 95% interval is the set of parameter values that a 5%-level test would not reject. Every test gives an interval, and vice versa (A5.1-7).

🐍 Exercise 1: t intervals and three proportion intervals
Implement the regularized incomplete beta function, t quantiles, the t interval, and the Wald, Wilson and Clopper–Pearson proportion intervals (no SciPy). Check that the t interval covers 95% at n = 6, and compare proportion coverage at p = 0.05, n = 40.
📝 Quick check (Level 2)
0/3 answered
  1. 1. With 0 successes in 20 trials, the Wald 95% interval is…
  2. 2. The Wilson interval comes from inverting…
  3. 3. A 95% interval contains exactly the values that a 5% test…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Proof that the t interval has exact coverage

For normal data, T=Xˉ−μs/n∼tn−1T = \frac{\bar X - \mu}{s/\sqrt n}\sim t_{n-1} whatever μ\mu and σ\sigma are (A5.1-2). So

P(−t0.975≤Xˉ−μs/n≤t0.975)=0.95P\Big(-t_{0.975}\le\frac{\bar X - \mu}{s/\sqrt n}\le t_{0.975}\Big) = 0.95

Rearranging the inequalities for μ\mu gives P(Xˉ−t s/n≤μ≤Xˉ+t s/n)=0.95P(\bar X - t\,s/\sqrt n\le\mu\le\bar X + t\,s/\sqrt n) = 0.95. ∎ The randomness is in Xˉ\bar X and ss, not in μ\mu.

Clopper–Pearson and the beta–binomial identity

P(Bin(n,p)≥k)=Ip(k,n−k+1)P(\text{Bin}(n, p)\ge k) = I_p(k, n - k + 1), the regularized incomplete beta function. The lower bound is the pp at which observing ≥k\ge k successes has probability α/2\alpha/2: the α/2\alpha/2 quantile of Beta(k,n−k+1)\text{Beta}(k, n - k + 1). The upper bound is symmetric. Because the binomial is discrete, the coverage is ≥1−α\ge1 - \alpha, never exactly equal.

Zero failures: the rule of three

With 0 failures in nn trials, the one-sided 95% upper bound solves (1−p)n=0.05(1 - p)^n = 0.05. So pU=1−0.051/n≈−ln⁡0.05n=2.996n≈3np_U = 1 - 0.05^{1/n}\approx\frac{-\ln0.05}n = \frac{2.996}n\approx\frac3n. To demonstrate p<0.001p<0.001 at 95% takes 2995 failure-free trials. This is why proving high reliability purely by testing is so expensive, and why autonomous-vehicle safety can’t be shown by miles driven alone (Kalra and Paddock, 2016).

Exercise 3.1: Derive the Wilson interval

Square (p^−p)2≤z2p(1−p)/n(\hat p - p)^2\le z^2p(1 - p)/n to get a quadratic in pp: (1+z2/n)p2−(2p^+z2/n)p+p^2≤0(1 + z^2/n)p^2 - (2\hat p + z^2/n)p + \hat p^2\le0. Its roots are p^+z2/2n±zp^(1−p^)/n+z2/4n21+z2/n\frac{\hat p + z^2/2n\pm z\sqrt{\hat p(1-\hat p)/n + z^2/4n^2}}{1 + z^2/n}.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A pivot's distribution depends on…
  2. 2. Clopper–Pearson coverage is…
  3. 3. 0 failures in 600 trials: approximate 95% upper bound on p?

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Certifying reliability from failure-free tests

A deployment requirement says “failure probability below 0.1% per mission, demonstrated at 95% confidence.” If testing is the only evidence, you need 2995 consecutive clean missions, or 4742 if one failure is allowed. The bound is tight: a system whose true rate equals the bound shows zero failures exactly 5% of the time. In practice, engineers combine testing with other evidence: physics-based analysis, simulation with importance sampling (A4.3-1), Bayesian priors from similar systems (A5.2), and accelerated life testing.

🐍 Exercise 2 (research): zero-failure bounds and test planning
Compute the exact zero-failure upper bound and compare it with the rule of three. Find the number of trials needed to demonstrate p < 0.001 at 95% with 0 or 1 failures allowed, and verify that the bound is tight by simulation.

Confidence intervals in AI, robotics and aerospace

  • Reporting ML results. Intervals over seeds, or bootstrap intervals over test examples (A5.1-11), should accompany every benchmark number. Agarwal et al. (2021) show how often RL conclusions flip once intervals are drawn.
  • Safety validation of autonomous vehicles. Kalra and Paddock (2016) compute that hundreds of millions of miles would be needed to demonstrate fatality rates statistically. That’s why scenario-based and simulation-based validation exist.
  • Navigation accuracy. Covariance-based confidence ellipses (for example 2σ, 95%) are reported for GNSS and INS solutions. Their validity depends on the filter being consistent (NEES tests, A5.1-7).
  • Uncertainty for predictions. Prediction intervals (for a new observation) are wider than confidence intervals (for a mean). Conformal prediction gives distribution-free prediction intervals (A4.3-6).
  • Sequential monitoring. Confidence sequences stay valid when you look at the data repeatedly (A4.4-7).

References

  1. J. Neyman (1937). “Outline of a theory of statistical estimation based on the classical theory of probability.” Phil. Trans. R. Soc. A, 236.
  2. E. B. Wilson (1927). “Probable inference, the law of succession, and statistical inference.” JASA, 22(158).
  3. C. Clopper, E. Pearson (1934). “The use of confidence or fiducial limits illustrated in the case of the binomial.” Biometrika, 26(4).
  4. L. Brown, T. Cai, A. DasGupta (2001). “Interval estimation for a binomial proportion.” Statistical Science, 16(2).
  5. J. Hanley, A. Lippman-Hand (1983). “If nothing goes wrong, is everything all right? Interpreting zero numerators.” JAMA, 249(13).
  6. N. Kalra, S. Paddock (2016). Driving to Safety: How Many Miles of Driving Would It Take to Demonstrate Autonomous Vehicle Reliability? RAND RR-1478.
  7. B. L. Welch (1947). “The generalization of ‘Student’s’ problem when several different population variances are involved.” Biometrika, 34.
  8. G. Casella, R. Berger (2002). Statistical Inference, 2nd ed., Ch. 9. Duxbury.
  9. R. Agarwal et al. (2021). “Deep reinforcement learning at the edge of the statistical precipice.” NeurIPS.
  10. Y. Bar-Shalom, X. R. Li, T. Kirubarajan (2001). Estimation with Applications to Tracking and Navigation, Ch. 5. Wiley.