Lightweight toolkit for binary A/B experiment analysis using aggregate counts.
Project description
abtestwise
A lightweight Python toolkit for binary A/B experiment analysis using aggregate count data. Version 0.1 combines frequentist and Bayesian summaries for binary proportions.
Install
Install from PyPI:
pip install abtestwise
Development install
To work on the package locally (with the test dependencies):
pip install -e ".[dev]"
Quickstart
from abtestwise import BinaryABTest
test = BinaryABTest.from_counts(
control_successes=120,
control_total=1000,
treatment_successes=145,
treatment_total=1000,
prior_alpha=1,
prior_beta=1,
n_simulations=100_000,
credible_interval=0.95,
seed=42,
)
result = test.run()
print(result.summary())
print(result.prob_lift_above(0.01))
prob_lift_above(0.01) gives the posterior probability that Treatment B improves
the metric by more than 1 percentage point.
Do-no-harm checks
prob_no_harm(margin) gives the posterior probability that Treatment B is not
worse than Control A by more than margin (in raw decimal units, so 0.005 means
0.5 percentage points). prob_harm_above(margin) is its complement.
result.prob_no_harm(0.005) # P(lift >= -0.005): B is not worse by more than 0.5pp
result.prob_harm_above(0.005) # P(lift < -0.005): B is worse by more than 0.5pp
Raw result values are also available:
result.to_dict()
Plotting
import matplotlib.pyplot as plt
result.plot_lift_distribution()
result.plot_probability_bar()
plt.show()
The lift distribution plot shows posterior lift in percentage points.
The probability bar plot shows:
P(Treatment B > Control A)
P(Control A > Treatment B)
Groups and sign convention
In product A/B testing terms:
- Control (A) is the baseline group.
- Treatment (B) is the test group or variant B.
- Lift is always Treatment B - Control A.
- Positive lift means Treatment B is better than Control A.
- Negative lift means Control A is better than Treatment B.
Scope
Current package scope:
- Binary proportions only.
- Aggregate counts only.
- Two groups only.
- Frequentist: two-sided pooled two-proportion z-test.
- Bayesian: beta-binomial posterior simulation with default prior
Beta(1, 1). - Equal-tailed credible interval.
- Expected loss.
- Practical lift thresholds.
- Do-no-harm probabilities using a user-defined harm margin.
- Simple plots.
Development
Run tests with:
python -m pytest -q
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 abtestwise-0.1.1.tar.gz.
File metadata
- Download URL: abtestwise-0.1.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc0ed0724f0d6139c94920689353965e0df2b2cad15ce939184d497f4388381
|
|
| MD5 |
222c7836588ec2fe1f83c8dbeea0571c
|
|
| BLAKE2b-256 |
6618e93307dd2410569914687698cfaf0a62be7a0934dfb4adf02d7792e5a02a
|
File details
Details for the file abtestwise-0.1.1-py3-none-any.whl.
File metadata
- Download URL: abtestwise-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9140bf89a286db89dc1a39952f85fbe11f8ce9cbaaa64f0c6b38341cd718a9f1
|
|
| MD5 |
f3d80f309cfb67d55109f1d3ef59e9ae
|
|
| BLAKE2b-256 |
5699f3c69ef9ec4087fd52a86afd5b8c4073daf47a6c79379dd61a09369d88e1
|