A/B tests · ResultsBayesian A/B test

An online Bayesian A/B test: the probability that B beats A, the expected loss of choosing each variant and a credible interval for the uplift. Up to 10 variants, conversions or means, a uniform prior or one from past data, a stopping rule by loss threshold, and a comparison with the classical test on the same data. Python and R code.

Your numbers stay in the browser and are never sent anywhere

01Data02Result03Distributions04Comparison05Code06Examples07Questions08Related
01

Data

What to compare

Visitors and conversions per variant, up to 10. The first is the control, A. Two variants are calculated exactly, more by Monte Carlo with 20,000 draws.

VariantVisitorsConversions
A
B
Prior distribution

You can stop the test when the expected loss of choosing the leader is below the threshold: how much you are willing to lose if it is actually worse.

02

Result

You can choose B.
The probability that B beats A is 95.4 %. If B turns out worse, we lose 0.0013 pp on average, below the threshold of 0.010 pp.
Probability that B beats A
95.4 %
exact formula
Loss if you choose B
0.0013 pp
0.06 % of B's conversion
Loss if you choose A
0.1213 pp
6.06 % of A's conversion
Uplift interval of B over A
−0.9 % … +13.4 %
credible interval, 95%
Posterior conversion of B
2.121 %
Beta(1,697; 78,305)
Prior
Beta(1; 1)
uniform

A Bayesian result is easier to explain, but it does not cancel out peeking and SRM: if you stop at the first good number or traffic split unevenly, the conclusion is just as unreliable.

Check the traffic split

03

Distributions

Posterior distributions
Where the true conversion of each variant most likely lies
AB1.86 %1.96 %2.06 %2.17 %2.27 %
04

Comparison

Two-sided z-test: p = 0.091, so the difference is not proven. The Bayesian probability is close to 1 − p of the one-sided test (95.4%): both approaches see the same data but phrase the conclusion differently.

Bayes and the classical test on the same data
QuestionClassicalBayesian
What it answersHow unusual the data are if there is no effectHow likely it is that B is better
Decisionp < αLeader's loss < threshold
PeekingBreaks αAlso harmful, but less so
05

Check in Python / R

Check in Python / R
import numpy as np

rng = np.random.default_rng(7)
a = rng.beta(1601, 78401, 200_000)
b = rng.beta(1697, 78305, 200_000)
print((b > a).mean())               # P(B > A)
print(np.maximum(a - b, 0).mean())  # потери при выборе B
06

Examples

07

Frequently asked questions

A classical test answers how unusual the data are if there is no effect: that is the p-value. A Bayesian one answers how likely it is that B beats A and how much you could lose by choosing it. For 1,600 and 1,696 conversions of 80,000, the classical two-sided p = 0.091, “not proven”, while the Bayesian probability is 95.4%. There is no contradiction: these answer different questions about the same data.

Updated