binomial_cis

This is a Python package for computing confidence intervals for the probability of success parameter, \(p\), of a binomial distribution. The binomial distribution represents the likelihood of observing \(k\) successes in \(n\) trials where the probability of success for each trial is \(p\). For example, \(p\) may be the probability of a coin flip landing on heads, and \(k\) the number of heads we observe after \(n\) flips. One often does not know the value of \(p\) and wishes to estimate it. A confidence interval is a set, constructed based on \(k, n\), that covers the unknown parameter \(p\) with some user-specified probability. The binomial_cis package computes confidence intervals that lower and/or upper bound \(p\) with a user-specified probability.

Source Code

The source code for this package is available at https://github.com/TRI-ML/binomial_cis/.

Installation

Install the package with pip:

pip install binomial_cis

Example Usage

Lower Bounds

Find a lower bound on \(p\):

from binomial_cis import binom_ci

k = 5 # number of successes
n = 10 # number of trials
alpha = 0.05 # miscoverage probability

lb = binom_ci(k, n, alpha, 'lb')

Find maximum expected shortage given miscoverage rate and number of samples:

from binomial_cis import max_expected_shortage

mes_ub, mes_lb, p_lb, num_iters = max_expected_shortage(alpha, n, tol=1e-3)

Upper Bounds

Find an upper bound on \(p\):

from binomial_cis import binom_ci

k = 5 # number of successes
n = 10 # number of trials
alpha = 0.05 # miscoverage probability

ub = binom_ci(k, n, alpha, 'ub')

Find maximum expected excess given miscoverage rate and number of samples:

from binomial_cis import max_expected_excess

mee_ub, mee_lb, p_lb, num_iters = max_expected_excess(alpha, n, tol=1e-3)

2-Sided Bounds

Find simultaneous lower and upper bounds on \(p\):

from binomial_cis import binom_ci

k = 5 # number of successes
n = 10 # number of trials
alpha = 0.05 # miscoverage probability

lb, ub = binom_ci(k, n, alpha, 'lb,ub')

Find maximum expected width given miscoverage rate and number of samples:

from binomial_cis import max_expected_width

mew_ub, mew_lb, p_lb, num_iters = max_expected_width(alpha, n, tol=1e-3)

More Resources

Index