Week 07 · Confidence intervals and coverage
Compare two interval methods near a probability boundary.
← Week 6 · Subject contents · Week 8 →
Compare two interval methods near a probability boundary.
Work through the problem
A 95% confidence procedure aims to capture the fixed parameter in roughly 95% of repeated samples under its assumptions. The Wald interval uses p̂ ± z√[p̂(1−p̂)/n]. If k = 0, both endpoints equal zero. That outcome alone has probability 0.95²⁰ ≈ 0.358 when the true p is 0.05.
The Wilson score interval solves (p̂−p)² ≤ z² p(1−p)/n for p. Its centre is (p̂ + z²/2n)/(1 + z²/n). Inverting the score test leaves a positive upper endpoint at k = 0. Actual coverage can still vary with p and n because the counts are discrete.
Run the Python lab
import numpy as np
n, p, z = 20, .05, 1.96
q = np.random.default_rng(16).binomial(n, p, 50000) / n
wald = z * np.sqrt(q*(1-q)/n)
den = 1 + z*z/n
center = (q + z*z/(2*n)) / den
half = z * np.sqrt(q*(1-q)/n + z*z/(4*n*n)) / den
coverage = [np.mean(abs(q-p) <= wald), np.mean(abs(center-p) <= half)]
print("Wald, Wilson:", np.round(coverage, 3))
assert coverage[1] > coverage[0] + .2
Output from the lab
Wald, Wilson: [0.639 0.924]
Practice
- What is the Wilson upper bound at k = 0?
Check your reasoning
- Simplifying gives z²/(n+z²), about 0.161 at n = 20.