Binoculars: Binomial Confidence Intervals
This is a small package that provides functions to compute the confidence interval for a binomial proportion. I made it because I spend altogether too much time staring at the Binomial proportion confidence interval wiki page.
Presently, the package implements:
- The Normal Approximation
- The Wilson Interval (no continuity correction)
- Jeffrey's interval (via scipy.stats.beta)
- Clopper-Pearson interval (also via scipy.stats.beta)
If you haven't spent a lot of time thinking about which interval you should use (and why would you want to?), I suggest using the Wilson interval or Jeffrey's interval. Jeffrey's interval is returned by default by the binomial_confidence function in this package.
You oughtn't use the normal approximation if you don't have to. It produces patently inaccurate values with low/high probabilities at low Ns. The plot at the top of this readme shows the normal approximation producing lower lower bounds of less than 0 in these cases.
Install
pip install binoculars
Usage
from binoculars import binomial_confidence
N, p = 100, 0.2
binomial_confidence(p, N) # default to jeffrey's interval
# (0.1307892803998113, 0.28628125447599173)
binomial_confidence(p, N, tail='lower') # grab one tail
# 0.1307892803998113
# set Z value
binomial_confidence(p, N, tail='lower', z=2.58)
# 0.11212431621448567
# choose your method
binomial_confidence(p, N, method='normal')
# (0.12160000000000001, 0.2784)
binomial_confidence(p, N, method='wilson')
# (0.1333659225590988, 0.28883096192650237)
Development
I honestly do not imagine touching this a lot. But maybe you want to add one of the other interval methods?
- Make a python 3.6+ venv
pip install -e .[test]black lib --checkpytest
Later (?)
- Add confidence intervals for odds ratios, differences
- Add the unimplemented intervals
- Add plots comparing the intervals to readme.
Metadata
Release files for binoculars 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| binoculars-0.1.3.tar.gz | 3.5 kB | Without provenance | Details for binoculars-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| binoculars-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for binoculars-0.1.3-py3-none-any.whl |
Total release size: 7.9 kB
Release files / binoculars-0.1.3.tar.gz
| Download URL | binoculars-0.1.3.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e8f7c6d9ec9740696e85b45bdc62f27bed6fa0a3de237ab75312265536e8d97
|
|
BLAKE2b-256 checksum How to use checksums |
ff2ac0de4e29218da41fdba4018a005cc54a708c1bac16268a434279433ca87e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6
|
Release files / binoculars-0.1.3-py3-none-any.whl
| Download URL | binoculars-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83a3eb0c1fc698ff0eee35c2935f535f776b80adbdcf758aa76eeae0419aa610
|
|
BLAKE2b-256 checksum How to use checksums |
1f4bf5a59b1ce81a404cf093d6b83703c2fc77960323f9b116f5df378429a7b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6
|
Security for binoculars 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.