statsmodels.stats.proportion.proportion_confint

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

Confidence interval for a binomial proportion

Parameters:
count{int or float, array_like}

number of successes, can be pandas Series or DataFrame. Arrays must contain integer values if method is “binom_test”.

nobs{int or float, array_like}

total number of trials. Arrays must contain integer values if method is “binom_test”.

alphafloat

Significance level, default 0.05. Must be in (0, 1)

method{“normal”, “agresti_coull”, “beta”, “wilson”, “binom_test”}

default: “normal” method to use for confidence interval. Supported 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 : Numerical inversion of binom_test

alternative{“two-sided”, “larger”, “smaller”}

default: “two-sided” specifies whether to calculate a two-sided or one-sided confidence interval.

Returns:
ci_low, ci_upp{float, ndarray, Series DataFrame}

larger and smaller confidence level with coverage (approximately) 1-alpha. When a pandas object is returned, then the index is taken from count. When side is not “two-sided”, lower or upper bound is set to 0 or 1 respectively.

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


Last update: Nov 14, 2024