Skip to main content

Confidence Intervals for Difference of Binomial Proportions

pytest random-test codecov PyPI RTD Status gh-page status downloads license GitHub Release Date - Published_At GitHub commits since latest release (by SemVer including pre-releases) Streamlit App

Computation of confidence intervals for binomial proportions and for difference of binomial proportions.

[GitHub Pages] [Read the Docs]

🚀 NEW 🚀 Streamlit support! See here for an app deployed on Streamlit Community Cloud.

Installation

Run

python -m pip install diff-binom-confint

or install the latest version in GitHub using

python -m pip install git+https://github.com/DeepPSP/DBCI.git

or git clone this repository and install locally via

cd DBCI
python -m pip install .

Numba accelerated version

Install using

python -m pip install diff-binom-confint[acc]

Usage examples

from diff_binom_confint import compute_difference_confidence_interval

n_positive, n_total = 84, 101
ref_positive, ref_total = 89, 105

confint = compute_difference_confidence_interval(
    n_positive,
    n_total,
    ref_positive,
    ref_total,
    conf_level=0.95,
    method="wilson",
)

Implemented methods

Confidence intervals for binomial proportions

Click to view!
Method (type) Implemented
wilson ✔️
wilson-cc ✔️
wald ✔️
wald-cc ✔️
agresti-coull ✔️
jeffreys ✔️
clopper-pearson ✔️
arcsine ✔️
logit ✔️
pratt ✔️
witting ✔️
mid-p ✔️
lik ✔️
blaker ✔️
modified-wilson ✔️
modified-jeffreys ✔️

Confidence intervals for difference of binomial proportions

Click to view!
Method (type) Implemented
wilson ✔️
wilson-cc ✔️
wald ✔️
wald-cc ✔️
haldane ✔️
jeffreys-perks ✔️
mee ✔️
miettinen-nurminen ✔️
true-profile ✔️
hauck-anderson ✔️
agresti-caffo ✔️
carlin-louis ✔️
brown-li ✔️
brown-li-jeffrey ✔️
miettinen-nurminen-brown-li ✔️
exact ❌
mid-p ❌
santner-snell ❌
chan-zhang ❌
agresti-min ❌
wang ✔️
pradhan-banerjee ❌

Creating report

One can use the make_risk_report function to create a report of the confidence intervals for difference of binomial proportions.

from diff_binom_confint import make_risk_report

# df_train and df_test are pandas.DataFrame providing the data
table = make_risk_report((df_train, df_test), target = "binary_target")
# or if df_data is a pandas.DataFrame containing both training and testing data
table = make_risk_report(df_data, target = "binary_target")

For more details, see corresponding documenation. The produced table is similar to the following:

Click to view!

risk report

References

  1. SAS
  2. PASS
  3. statsmodels.stats.proportion
  4. scipy.stats._binomtest
  5. corplingstats
  6. DescTools.StatsAndCIs
  7. Newcombee

NOTE

Reference 1 has errors in the description of the methods Wilson CC, Mee, Miettinen-Nurminen. The correct computation of Wilson CC is given in Reference 5. The correct computation of Mee, Miettinen-Nurminen are given in the code blocks in Reference 1

Test data

Test data are

  1. taken (with slight modification, e.g. the upper_bound of miettinen-nurminen-brown-li method in the edge case file) from Reference 1 for automatic test of the correctness of the implementation of the algorithms.

  2. generated using DescTools.StatsAndCIs via

    library("DescTools")
    library("data.table")
    
    results = data.table()
    for (m in c("wilson", "wald", "waldcc", "agresti-coull", "jeffreys",
                    "modified wilson", "wilsoncc", "modified jeffreys",
                    "clopper-pearson", "arcsine", "logit", "witting", "pratt",
                    "midp", "lik", "blaker")){
        ci = BinomCI(84,101,method = m)
        new_row = data.table("method" = m, "ratio"=ci[1], "lower_bound" = ci[2], "upper_bound" = ci[3])
        results = rbindlist(list(results, new_row))
    }
    fwrite(results, "./test/test-data/example-84-101.csv")  # with manual slight adjustment of method names
    
  3. taken from Reference 7 (Table II).

The filenames has the following pattern:

# for computing confidence interval for difference of binomial proportions
"example-(?P<n_positive>[\\d]+)-(?P<n_total>[\\d]+)-vs-(?P<ref_positive>[\\d]+)-(?P<ref_total>[\\d]+)\\.csv"

# for computing confidence interval for binomial proportions
"example-(?P<n_positive>[\\d]+)-(?P<n_total>[\\d]+)\\.csv"

Note that the out-of-range values (e.g. > 1) are left as empty values in the .csv files.

Known Issues

  1. Edge cases incorrect for the method true-profile.

Metadata

Release files for diff-binom-confint 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for diff-binom-confint 0.1.0
File Size Uploaded
diff_binom_confint-0.1.0.tar.gz 22.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for diff-binom-confint 0.1.0
File Interpreter ABI Platform
diff_binom_confint-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.1 kB

Release files / diff_binom_confint-0.1.0.tar.gz

Download URL diff_binom_confint-0.1.0.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ce47737a492bed878ed3e733451942564408ccacb141a37c29ab88e95c2c663d
BLAKE2b-256 checksum
How to use checksums
8b5d56cfa19c074a3b9bc2aa48bffa14a71143b41f271f8011a395fc6f9a2a17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / diff_binom_confint-0.1.0-py3-none-any.whl

Download URL diff_binom_confint-0.1.0-py3-none-any.whl
Size 27.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb34ceef83af7f32fff306c34f30af49eacfe31b4ce378f14cb0331462f356c9
BLAKE2b-256 checksum
How to use checksums
0c1742226a566d0428e856fe180daa5d2d97ccd2e5cc2cac63942b2e91de082d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page