statsmodels.stats.proportion.proportion_confint

statsmodels.stats.proportion.proportion_confint(count, nobs, alpha=0.05, method='normal')[source]

confidence interval for a binomial proportion

Parameters:
countint or array_array_like

number of successes, can be pandas Series or DataFrame

nobsint

total number of trials

alphafloat in (0, 1)

significance level, default 0.05

method{‘normal’, ‘agresti_coull’, ‘beta’, ‘wilson’, ‘binom_test’}

default: ‘normal’ method to use for confidence interval, currently available methods :

  • normal : asymptotic normal approximation

  • agresti_coull : Agresti-Coull interval

  • beta : Clopper-Pearson interval based on Beta distribution

  • wilson : Wilson Score interval

  • jeffreys : Jeffreys Bayesian Interval

  • binom_test : experimental, inversion of binom_test

Returns:
ci_low, ci_uppfloat, ndarray, or pandas Series or DataFrame

lower and upper confidence level with coverage (approximately) 1-alpha. When a pandas object is returned, then the index is taken from the count.

Notes

Beta, the Clopper-Pearson exact interval has coverage at least 1-alpha, but is in general conservative. Most of the other methods have average coverage equal to 1-alpha, but will have smaller coverage in some cases.

The ‘beta’ and ‘jeffreys’ interval are central, they use alpha/2 in each tail, and alpha is not adjusted at the boundaries. In the extreme case when count is zero or equal to nobs, then the coverage will be only 1 - alpha/2 in the case of ‘beta’.

The confidence intervals are clipped to be in the [0, 1] interval in the case of ‘normal’ and ‘agresti_coull’.

Method “binom_test” directly inverts the binomial test in scipy.stats. which has discrete steps.

TODO: binom_test intervals raise an exception in small samples if one

interval bound is close to zero or one.

References

https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval

Brown, Lawrence D.; Cai, T. Tony; DasGupta, Anirban (2001). “Interval

Estimation for a Binomial Proportion”, Statistical Science 16 (2): 101–133. doi:10.1214/ss/1009213286.