Skip to main content

Bayesian A/B testing for proportions

Project description

Bayesian A/B Testing for Proportions

PyPI TestPyPI Documentation Python Tests codecov

A Python package for Bayesian hypothesis testing of success-rate differences in any Bernoulli-like experiment, using analytic and approximate inference methods. Input data can be binary (0/1) or real-valued on (0, 1) — continuous scores are automatically binarized at a configurable threshold. Typical applications include comparing treatments, groups, items, model variants, or any two conditions whose outcomes can be expressed as proportions. Please check out our Getting Started guide for installation and quick examples.

Features

  • Effect-size inference for proportions — estimate and test the difference in success rates for both paired and non-paired samples
  • Savage–Dickey Bayes Factor — test a point-null hypothesis ($\delta = 0$) without fitting a separate null model
  • Posterior of the null & ROPE — quantify the posterior mass inside a Region of Practical Equivalence for nuanced decisions beyond simple reject/accept
  • Posterior predictive checks — assess model fit by comparing observed data to data simulated from the posterior
  • Bayes Factor Design Analysis (BFDA) — plan sample sizes to reach a target level of evidence before running the experiment
  • Publication-ready plots — posterior distributions, predictive checks, Savage–Dickey density-ratio plots, and BFDA power curves out of the box

Models

Model Class Method When to use
Non-paired Beta–Bernoulli NonPairedBayesPropTest Conjugate Beta posterior Independent groups, exact & fast
Paired Logistic (Laplace) PairedBayesPropTest MAP + Laplace approximation Paired scores, large n, fast iteration
Paired Logistic (Pólya–Gamma) PairedBayesPropTestPG Exact Gibbs sampling Paired scores, small n, exact posterior

Quick start

from bayesprop.resources.bayes_paired_pg import PairedBayesPropTestPG
from bayesprop.utils.utils import simulate_paired_scores

# Simulate paired binary data
sim = simulate_paired_scores(N=200, delta_A=0.5, seed=42)
y_A, y_B = sim.y_A, sim.y_B

# Fit & summarise
model = PairedBayesPropTestPG(seed=42, n_iter=2000, burn_in=500, n_chains=4).fit(y_A, y_B)
print(model.summary)           # PairedSummary with mean_delta, ci_95, P(A>B), …

# Hypothesis test
bf = model.savage_dickey_test() # SavageDickeyResult with BF_10, decision, …

# Plots
model.plot_posteriors()
model.plot_ppc(seed=42)
model.plot_savage_dickey()

Package structure

├── pyproject.toml
├── justfile                   # task runner (just <recipe>)
├── .pre-commit-config.yaml    # ruff format + lint hooks
├── data/                      # evaluation datasets
├── docs/                      # model derivations & MkDocs site
├── src
│   ├── bayesprop
│   │   ├── config/            # global_config, YAML configs
│   │   ├── resources/
│   │   │   ├── bayes_nonpaired.py      # NonPairedBayesPropTest
│   │   │   ├── bayes_paired_laplace.py # PairedBayesPropTest
│   │   │   ├── bayes_paired_pg.py      # PairedBayesPropTestPG
│   │   │   ├── bfda_utils.py           # BFDA helpers
│   │   │   └── data_schemas.py         # Pydantic models
│   │   ├── services/
│   │   │   └── file.py                 # CSV / JSON / YAML / XLSX I/O
│   │   └── utils/
│   │       └── utils.py                # simulate, BFDA power curves, plots
│   └── notebooks/
│       ├── bayesian_AB_model_comparison_nonpaired.ipynb
│       ├── bayesian_AB_model_comparison_paired_laplace.ipynb
│       └── bayesian_AB_model_comparison_paired_gibbs.ipynb
└── tests/
    ├── test_bayes_nonpaired.py
    ├── test_bayes_paired_laplace.py
    ├── test_bayes_paired_pg.py
    ├── test_bfda_utils.py
    ├── test_data_schemas.py
    └── test_file_services.py

Installation

pip install BayesProp

Or with uv:

uv pip install BayesProp

For development (from source):

git clone https://github.com/AVoss84/bayesProp.git
cd bayesprop
uv venv --python 3.13
uv sync
source .venv/bin/activate

Dependencies

  • Python ≥ 3.13
  • numpy, scipy, matplotlib, pandas
  • pydantic (v2)
  • polyagamma

References

  • Gelman, A., Carlin, J. B., Stern, H. S., Dunson, D. B., Vehtari, A. & Rubin, D. B. (2013). Bayesian Data Analysis (3rd ed.). Chapman & Hall/CRC.
  • Kruschke, J. K. (2018). Rejecting or accepting parameter values in Bayesian estimation. Advances in Methods and Practices in Psychological Science, 1(2), 270–280.
  • Polson, N. G., Scott, J. G. & Windle, J. (2013). Bayesian inference for logistic models using Pólya–Gamma latent variables. JASA, 108(504), 1339–1349.
  • Schönbrodt, F. D. & Wagenmakers, E.-J. (2018). Bayes factor design analysis: Planning for compelling evidence. Psychonomic Bulletin & Review, 25(1), 128–142.

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

bayesprop-0.1.0.3.tar.gz (52.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bayesprop-0.1.0.3-py3-none-any.whl (45.2 kB view details)

Uploaded Python 3

File details

Details for the file bayesprop-0.1.0.3.tar.gz.

File metadata

  • Download URL: bayesprop-0.1.0.3.tar.gz
  • Upload date:
  • Size: 52.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bayesprop-0.1.0.3.tar.gz
Algorithm Hash digest
SHA256 b19ef16bd085ab95f041189ba310a01d01ca2a46d67d15405b04f3d2c10b27ef
MD5 c0d4f8f5221915d9ca00e4de28d3848a
BLAKE2b-256 b6f94ec2771c67d1d7a32eb324783569383a45f295999cd35e461ff7cfb935e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for bayesprop-0.1.0.3.tar.gz:

Publisher: publish_pypi.yml on AVoss84/bayesProp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bayesprop-0.1.0.3-py3-none-any.whl.

File metadata

  • Download URL: bayesprop-0.1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 45.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bayesprop-0.1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e88e2f154e1340894d0de3e0990994510cc59480e9203d20cd2e569d4b061e02
MD5 f4c39917de3b75d0eb17f34092005ede
BLAKE2b-256 f53a28369f29f7e81bcbca707c0faae4f67c34b554c44f6951154ce92d820e06

See more details on using hashes here.

Provenance

The following attestation bundles were made for bayesprop-0.1.0.3-py3-none-any.whl:

Publisher: publish_pypi.yml on AVoss84/bayesProp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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