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:
- achieves exact desired coverage: $\mathbb{P}[\underline{p} \le p] = 1-\alpha$,
- $[\underline{p}, 1]$ is uniformly most accurate,
- achieves exact desired maximum expected shortage: $\max_p \ \mathbb{E}_p[\max (p - \underline{p}, 0)] = \text{MES}$,
- 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:
- achieves exact desired coverage: $\mathbb{P}[p \le \overline{p}] = 1-\alpha$,
- $[0, \overline{p}]$ is uniformly most accurate,
- achieves exact desired maximum expected excess: $\max_p \ \mathbb{E}_p[\max (\overline{p} - p, 0)] = \text{MEE}$,
- 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:
- achieves exact desired coverage: $\mathbb{P}[\underline{p} \le p \le \overline{p}] = 1-\alpha$,
- $[\underline{p}, \overline{p}]$ is uniformly most accurate unbiased,
- achieves exact desired maximum expected width: $\max_p \ \mathbb{E}_p[\overline{p} - \underline{p}] = \text{MEW}$,
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file binomial_cis-0.0.12.tar.gz.
File metadata
- Download URL: binomial_cis-0.0.12.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55fc4967b2a30fafae761f7b3163ee42a748c41c9f710209d8cf8bc2953a51bc
|
|
| MD5 |
ac4deee58d211a3466ad53f62974dc17
|
|
| BLAKE2b-256 |
14b4de24057c0c8fd909bf6fe1d4b4dfba0ee05f3186326e6cf9fb55a2e35e0a
|
Provenance
The following attestation bundles were made for binomial_cis-0.0.12.tar.gz:
Publisher:
pypi-release.yml on TRI-ML/binomial_cis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
binomial_cis-0.0.12.tar.gz -
Subject digest:
55fc4967b2a30fafae761f7b3163ee42a748c41c9f710209d8cf8bc2953a51bc - Sigstore transparency entry: 201522574
- Sigstore integration time:
-
Permalink:
TRI-ML/binomial_cis@8a2d6ebb5a5ed06feefe46db19314ecf13be8b3a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TRI-ML
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@8a2d6ebb5a5ed06feefe46db19314ecf13be8b3a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file binomial_cis-0.0.12-py3-none-any.whl.
File metadata
- Download URL: binomial_cis-0.0.12-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38928ecd33e8d4d0ceea292bdcb620c4921d5dd65f3fefe53b51a71cad2c5bcf
|
|
| MD5 |
7dc737a0fd498a821ec60ac6f65a18fe
|
|
| BLAKE2b-256 |
6b74f59780bd9ecc5cbbdeb1c3d3aa07bd211708ad9d731064483142b1f62469
|
Provenance
The following attestation bundles were made for binomial_cis-0.0.12-py3-none-any.whl:
Publisher:
pypi-release.yml on TRI-ML/binomial_cis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
binomial_cis-0.0.12-py3-none-any.whl -
Subject digest:
38928ecd33e8d4d0ceea292bdcb620c4921d5dd65f3fefe53b51a71cad2c5bcf - Sigstore transparency entry: 201522579
- Sigstore integration time:
-
Permalink:
TRI-ML/binomial_cis@8a2d6ebb5a5ed06feefe46db19314ecf13be8b3a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TRI-ML
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-release.yml@8a2d6ebb5a5ed06feefe46db19314ecf13be8b3a -
Trigger Event:
workflow_dispatch
-
Statement type: