Skip to main content

Confidence intervals for binomial distributions.

Project description

binomial_cis

This package computes confidence intervals for the probability of success parameter, $p$, of a binomial distribution. The confidence intervals computed by this package cover $p$ with exactly the user-specified probability and have minimal excess length.

Documentation

The documentation for the package can be found at: https://tri-ml.github.io/binomial_cis.

Installation

Install the package with pip:

pip install binomial_cis

What does this package do?

This package constructs optimal confidence intervals for the probability of success parameter, $p$, of a binomial distribution.

Lower Bounds

Given user specified miscoverage rate ($\alpha$) and maximum expected shortage ($\text{MES}$), return a lower bound on $p$ that satisfies the following requirements:

  1. achieves exact desired coverage: $\mathbb{P}[\underline{p} \le p] = 1-\alpha$,
  2. $[\underline{p}, 1]$ is uniformly most accurate,
  3. achieves exact desired maximum expected shortage: $\max_p \ \mathbb{E}_p[\max (p - \underline{p}, 0)] = \text{MES}$,
  4. uses the minimum number of samples $n$ to achieve requirements 1,2,3.

Upper Bounds

Given user specified miscoverage rate ($\alpha$) and maximum expected excess ($\text{MEE}$), return an upper bound on $p$ that satisfies the following requirements:

  1. achieves exact desired coverage: $\mathbb{P}[p \le \overline{p}] = 1-\alpha$,
  2. $[0, \overline{p}]$ is uniformly most accurate,
  3. achieves exact desired maximum expected excess: $\max_p \ \mathbb{E}_p[\max (\overline{p} - p, 0)] = \text{MEE}$,
  4. uses the minimum number of samples $n$ to achieve requirements 1,2,3.

2-Sided Bounds

Given the user specified miscoverage rate ($\alpha$) and maximum expected width ($\text{MEW}$), return simultaneous lower and upper bounds on $p$ that satisfy the following requirements:

  1. achieves exact desired coverage: $\mathbb{P}[\underline{p} \le p \le \overline{p}] = 1-\alpha$,
  2. $[\underline{p}, \overline{p}]$ is uniformly most accurate unbiased,
  3. achieves exact desired maximum expected width: $\max_p \ \mathbb{E}_p[\overline{p} - \underline{p}] = \text{MEW}$,
  4. uses the minimum number of samples $n$ to achieve requirements 1,2,3.

How do I use this package?

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binomial_cis-0.0.11.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

binomial_cis-0.0.11-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file binomial_cis-0.0.11.tar.gz.

File metadata

  • Download URL: binomial_cis-0.0.11.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for binomial_cis-0.0.11.tar.gz
Algorithm Hash digest
SHA256 a4c8be9c5fb9dee2efde0debc6e56e9feb4ac4e4722b5f074fb052e72026c336
MD5 52b7376a406a1f8c19d342e60bc526fd
BLAKE2b-256 e5805bbb595dc349f81100e5b78baa14b4d20f212650989a60449f6ed132800d

See more details on using hashes here.

File details

Details for the file binomial_cis-0.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for binomial_cis-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 7c9ab135400bfb55f460945a9bb1fae26b63356d122950beecb9fad67111dcd3
MD5 fac97cf53ceded89d0e7f17affd1400f
BLAKE2b-256 f4049a45e32d72d2747266159d8747f1f64051b57a799248b00682fc85d6d465

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page