You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DOC: "samplesize_confint_proportion" docstring over-promises: no guarantee on realized CI width or coverage #11065
The docstring says "Find sample size to get desired confidence interval length" but the formula inverts a different quantity! The returned n makes half_length the normal-approximation 100(1−α)% margin of error of the point estimator:
Pr(|p_hat − p| ≤ half_length) ≈ 1 − α.
This describes the sampling error of p_hat at the planning value. It says nothing about the confidence interval the study will actually produce.
What the formula guarantees
With p0 = proportion, d = half_length and z the 1 − alpha/2 normal quantile, the function returns
n = p0 * (1 - p0) / (d / z) ** 2
This solves the margin-of-error equation at the planning value. If the true proportion equals p0, the point estimate satisfies
Pr(|p_hat - p0| <= d) ≈ 1 - alpha
This describes the sampling error of p_hat at the planned p0 (nothing about the confidence interval)
The realized width meets the target only about half the time
The realized interval is random because its half-width, z * sqrt(p_hat * (1 - p_hat) / n), depends on the observed proportion. It is no larger than half_length only when p_hat falls at least as far from 0.5 as p0, which happens about half the time when p0 != 0.5.
The same collapse was measured for means: the textbook width formula ignores that the realized interval width is random, achieving a tolerance probability of 0.42 where 0.90 was planned (Kupper & Hafner 1989, Table 1: alpha = .05, n_m = 40), who formalized the fix as a tolerance probability on the realized width.
Coverage is not guaranteed either
The Wald interval under-covers at the returned n and degrades as p approaches 0 or 1. The usual safeguards (n * min(p, 1 - p) >= 5 or 10) "cannot be trusted" (Brown, Cai & DasGupta 2001). Yet method='normal' is the only option, and nothing in the docstring warns the user.
Suggested fix
Could you make the docstring say what the function delivers. Suggested wording: The returned n controls the distance between the observed proportion and the planning value: if the true proportion is equal to the planning value then Pr(|p_hat - proportion| <= half_length) ~= 1 - alpha. No property of the realized confidence interval is guaranteed.
Activity
shishir881 commentedon Nov 23, 2026
Hi! I'm new to contributing to statsmodels and would like to work on clarifying the 'samplesize_confint_proportion' docstring for this issue.