Skip to content

DOC: "samplesize_confint_proportion" docstring over-promises: no guarantee on realized CI width or coverage #11065

Open

Description

@mau-reen

Location of the documentation

https://www.statsmodels.org/v0.14.1/_modules/statsmodels/stats/proportion.html

Describe the issue

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.

  1. 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)

  1. 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.

  1. 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

  1. shishir881 commented on Nov 23, 2026

    @shishir881

    Hi! I'm new to contributing to statsmodels and would like to work on clarifying the 'samplesize_confint_proportion' docstring for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions