Tools › Statistics › Hypothesis Tests › A/B Test


A/B Test

Analysis of an online controlled experiment with a control and up to four treatments, for conversion rates (visitors and conversions per variant) or a continuous metric (n, mean and standard deviation, or pasted raw values). Frequentist part: the rate of every variant with its Wilson interval, the pooled two-proportion z test against the control, the difference with Newcombe's hybrid-score interval, the relative uplift with a log-scale large-sample interval, Fisher's exact p-value, the χ² test across all variants, Welch's t test with Cohen's d for continuous metrics, and Bonferroni or Holm adjustment of the p-values. Bayesian part: Be⁠ta posteriors, the probability that each treatment beats the control by Cook's closed-form sum and by 200,000 seeded Monte Carlo draws, the expected loss of choosing each variant and the 95 % highest-density interval of the uplift, with the posteriors drawn. Planning: the sample size per variant for a minimum detectable effect at the chosen power and significance (R's power.prop.test formula and Kohavi's 16 σ²/δ² rule), the duration from the daily traffic, the effect detectable with the current sample and the observed power. A closing note states the peeking problem and lists the Pocock and O'Brien–Fleming boundaries for the entered number of looks. The default case is an illustrative 10,000-visitor-per-variant test with 500 against 560 conversions (5.0 % against 5.6 %).

  • Conversion rates with Wilson intervals; pooled z test, Newcombe interval for the difference, relative uplift with its interval, Fisher's exact p, χ² across all variants; Welch's t and Cohen's d for continuous metrics; Bonferroni or Holm adjustment

  • Bayesian: posterior probability that each treatment beats the control (closed form and 200,000 seeded Monte Carlo draws), expected loss of each choice, 95 % highest-density interval of the uplift, posterior chart

  • Planning: sample size per variant for the minimum detectable effect (R power.prop.test formula and Kohavi's 16 σ²/δ² rule), test duration from the daily traffic, detectable effect with the current sample, observed power

  • Sequential caution: the inflated error rate of repeated looks and the Pocock and O'Brien–Fleming boundaries of Jennison and Turnbull for the entered number of looks

A/B Test


Unit System: /

Variants (control first, one per line)



Test Settings




Planning (minimum detectable effect, power, traffic)






Bayesian Prior and Simulation (conversion metrics)




Sequential Monitoring


×

A/B Test

A/B testing: frequentist, Bayesian, planning and peeking

What an A/B test is

An online controlled experiment assigns each visitor at random to a control (A, the current page) or to one or more treatments (B, C, …, the candidate changes) and compares a metric between the arms: a conversion rate (the share of visitors who click, sign up or buy) or a continuous quantity (revenue per visitor, time on page). Randomization makes the arms exchangeable, so a difference in the metric is attributed to the change and not to the kind of visitor who happened to see it. The analysis has to answer three questions: is the difference more than chance would produce, how large is it likely to be, and was the test big enough to see the effect that matters. This page gives the methods behind each section of the tool. Kohavi, Tang and Xu (2020) is the reference text for the practice; the formulas below are standard and the sources of each are named.

Rates and their intervals

A conversion rate is a binomial proportion p̂ = x/n. Its confidence interval is the Wilson (1927) score interval, ((p̂ + z²/2n) ± z √(p̂(1 − p̂)/n + z²/4n²)) / (1 + z²/n) with z the (1 − α/2) normal quantile. Unlike the textbook Wald interval p̂ ± z √(p̂(1 − p̂)/n) it never leaves [0, 1], has a sensible width when x is 0 or n, and keeps its coverage near the nominal level for the small rates of online conversion (Newcombe 1998, single-proportion paper). For a continuous metric the tool reports the mean, the sample standard deviation s and the t interval m ± t1 − α/2, n − 1 s/√n.

Frequentist comparison

Two-proportion z test. Under the null hypothesis pB = pA both arms estimate the same rate, so the standard error uses the pooled proportion p̄ = (xA + xB)/(nA + nB): z = (p̂B − p̂A) / √(p̄(1 − p̄)(1/nA + 1/nB)). Its square is Pearson's χ² on the 2 × 2 table, and the two-sided p-value is P(|Z| ≥ |z|). R's prop.test applies Yates' continuity correction by default (subtracting ½ from each |O − E|), which this tool does not; with online sample sizes the two agree to the third decimal, and for small counts Fisher's exact test is the one to quote. The one-sided alternative (treatment better) halves the p-value when the treatment is ahead; the two-sided test is the usual choice because a treatment that is worse must be found too.

Difference of rates. The interval for D = p̂B − p̂A is Newcombe's (1998) method 10, the hybrid score interval built from the two Wilson intervals (lA, uA) and (lB, uB): lower bound D − √((p̂B − lB)² + (uA − p̂A)²), upper bound D + √((uB − p̂B)² + (p̂A − lA)²). In Newcombe's comparison of eleven methods it was among the best for coverage and width at every sample size, and it is defined when a count is 0 or equals n, where the Wald interval collapses to a point.

Relative uplift. Product teams read the result as a relative change, p̂B/p̂A − 1. Its interval comes from the large-sample variance of the log ratio, Var[ln(p̂B/p̂A)] = (1 − p̂A)/(nA p̂A) + (1 − p̂B)/(nB p̂B) (the delta method applied to the ratio of two independent binomial proportions); the bounds are exp(ln(p̂B/p̂A) ± z SE) − 1. The interval is asymmetric about the point estimate, as a ratio should be, and requires both rates to be positive.

Fisher's exact test conditions on the margins of the 2 × 2 table; the two-sided p-value sums the hypergeometric probabilities of every table no more probable than the observed one (R's fisher.test convention). It is exact for any counts and the one to report when a cell is below about 5.

Several variants. Pearson's χ² test of homogeneity on the k × 2 table, with expected counts ni p̄ and ni(1 − p̄) and k − 1 degrees of freedom, asks whether the rates differ at all. Each treatment is also compared with the control, and because several comparisons share one control the family-wise false-positive rate grows with their number. Bonferroni multiplies every p-value by the number of comparisons m; Holm's (1979) step-down procedure orders the p-values, multiplies the smallest by m, the next by m − 1 and so on, enforces monotonicity, and controls the same family-wise error with more power. Treatments compared with one another, rather than with the control, are not tested.

Continuous metrics. Welch's (1947) t test compares two means without assuming equal variances: t = (mB − mA) / √(sA²/nA + sB²/nB) on the Welch–Satterthwaite degrees of freedom. Cohen's d = (mB − mA)/sp with the pooled standard deviation puts the difference in standardized units (0.2 small, 0.5 medium, 0.8 large; Cohen 1988). Revenue-type metrics are heavily skewed; Kohavi, Deng, Longbotham and Xu (2014) recommend at least 355 s² observations per arm, s being the skewness, before the mean is treated as normal, and capping the metric to reduce the skewness.

Bayesian analysis

With a Be⁠ta(a, b) prior on a conversion rate, the posterior after x conversions in n visitors is Be⁠ta(a + x, b + n − x): the prior counts as a conversions in a + b visitors, and Be⁠ta(1, 1) is the flat prior. The quantity a product team wants is the probability that the treatment's true rate exceeds the control's, P(pB > pA) = ∫01 fA(x) [1 − FB(x)] dx with fA the posterior density of A and FB the posterior distribution function of B. Cook (2005) showed that this Be⁠ta inequality has a closed form whenever one of the four parameters is a positive integer, which is always the case with an integer prior: in the form Evan Miller (2015) gives it, P(pB > pA) = Σi=0aB − 1 B(aA + i, bA + bB) / [(bB + i) B(1 + i, bB) B(aA, bA)], evaluated in logarithms of the Be⁠ta function. The tool computes it exactly this way (choosing the smallest integer parameter among the four equivalent sums), by Gauss–Legendre quadrature when no parameter is an integer, and again by 200,000 Monte Carlo draws from the posteriors with a fixed seed, so the two agree to about three decimals and the simulation also gives P(best) when there are several treatments.

The expected loss of choosing a variant is E[max(pother − pchosen, 0)], the average conversion rate given up if the other variant is in fact better; it is small when the chosen variant is very likely better or when the two are nearly equal, which makes it a decision quantity rather than a significance one. Stucchio (2015) proposed stopping when the expected loss of the leading variant falls below a threshold of caring, such as 0.1 % of conversion rate. The tool evaluates it exactly for each treatment against the control by quadrature and for every variant against the best by Monte Carlo. The highest-density interval of the uplift is the shortest interval holding the chosen share of the posterior draws of pB/pA − 1 (and of the difference); unlike the equal-tailed interval it is centred on the most probable values.

The Bayesian numbers do not suffer the peeking problem in the sense that P(pB > pA) is a valid posterior statement at any time, but a rule such as "ship when P > 0.95" examined repeatedly still ships flat changes more often than 5 % of the time; the expected-loss rule degrades more gracefully. The Bayesian section applies to conversion metrics; a continuous metric's frequentist interval is its report (a normal posterior with a flat prior would reproduce it).

Planning: sample size, duration, detectable effect

Before the test, fix the smallest effect worth detecting (the minimum detectable effect, MDE, relative to the control or in absolute percentage points), the power 1 − β (usually 0.8) and α. The sample size per variant for two proportions is the formula of R's power.prop.test (strict = FALSE), n = (z1 − α/2 √(2 p̄ q̄) + z1 − β √(p1q1 + p2q2))² / (p2 − p1)² with p̄ = (p1 + p2)/2: the pooled variance under the null in the critical term and the two separate variances under the alternative (Fleiss, Levin and Paik 2003 give the same form, with an optional continuity correction the tool does not apply). Kohavi, Longbotham, Sommerfield and Henne (2009) reduce it to the rule of thumb n = 16 σ²/δ² per variant for 80 % power at 95 % confidence (21 σ²/δ² for 90 %), with σ² = p(1 − p) for a rate and δ the absolute change; the 16 is (z0.975 + z0.8)² × 2 ≈ 15.7 rounded up. Their example, a 5 % conversion rate and a 5 % relative change, needs 16 × 0.0475 / 0.0025² = 121,600 visitors per variant. For a continuous metric n = 2 (z1 − α/2 + z1 − β)² σ²/δ². Evan Miller's sample-size calculator uses the same two-term form but with the baseline variance 2p1(1 − p1) in the null term instead of 2 p̄ q̄, and gives 1,030 per variation for a 20 % baseline and a 5-point absolute effect at 80 % power where R's formula gives 1,094; the tool reports R's.

The duration is the total sample over all variants divided by the daily traffic entering the test; run whole weeks so weekday and weekend visitors are both represented. The tool also solves the same power equation the other way: the effect the current sample detects at the target power, and the power the test had for the effect it observed. The latter, the "observed power", is a function of the p-value and adds no information; it is shown because it is asked for.

The peeking problem and sequential boundaries

A p-value is valid for one analysis at a predetermined sample size. If the dashboard is watched and the test stopped the first time p drops below 0.05, the chance of a false positive is no longer 5 %: Armitage, McPherson and Rowe (1969) computed it as 0.083 for two looks, 0.142 for five and 0.193 for ten equally spaced looks, and it tends to 1 with unlimited looking. The remedy is either to fix the sample size in advance or to use a group-sequential design in which the critical value at each look is raised so the total α is held. Pocock (1977) uses one constant CP at every look (|Zk| ≥ CP); O'Brien and Fleming (1979) use CB √(K/k) at look k of K, very strict early and close to the fixed-sample 1.96 at the end, which is why it is the common choice. The constants for K = 1 to 10 equally spaced looks at two-sided α = 0.05 and 0.01 are tabulated by Jennison and Turnbull (2000, Tables 2.1 and 2.3): for five looks CP = 2.413 and CB = 2.040, so the first O'Brien–Fleming look needs |z| ≥ 2.040 √5 = 4.56. The tool lists the boundary of every look with its nominal p-value as a caution; a real group-sequential analysis fixes K and the schedule beforehand and derives its final interval and p-value from the stopping rule.

Reading the results

Report the rates with their intervals, the difference and the relative uplift with theirs, the p-value with the alternative stated, and the posterior probability with the expected loss: a treatment with p = 0.06, P(better) = 0.97 and an expected loss of 0.004 % of conversion rate is not "a failure to reach significance" but a change that is very probably positive and very cheap to ship, whereas the same probability with a wide uplift interval says the size of the gain is still unknown. Check the planning section against the sample actually collected: a test that could only detect an 18 % relative lift was never going to establish a 5 % one, and a non-significant result from it is uninformative rather than negative. Finally, the analysis assumes the randomization worked (sample-ratio mismatch between the arms is the first thing to check), that visitors are independent (one user counted once), and that the metric was fixed before the data were seen.

Worked example: 500 against 560 conversions in 10,000 visitors each

The default case is illustrative. The control converts 5.00 % (Wilson 4.59 % to 5.45 %), the treatment 5.60 % (5.17 % to 6.07 %). Pooled z = 0.006/0.003168 = 1.894, two-sided p = 0.0583 (Fisher 0.0625; R's prop.test with Yates' correction gives X² = 3.468, p = 0.0626): not significant at 0.05. The difference is 0.60 points with Newcombe interval −0.02 to 1.22 points, the relative uplift 12.0 % with interval −0.4 % to 25.9 %. With a flat prior the posteriors are Be⁠ta(501, 9501) and Be⁠ta(561, 9441); P(pB > pA) = 0.9708 by the closed sum, the expected loss of shipping B is 0.0036 % of conversion rate against 0.60 % for keeping A. To detect a 10 % relative lift (5.0 % to 5.5 %) at 80 % power the test needs 31,234 visitors per variant (Kohavi's rule: 30,400); the 10,000 collected detect only an 18 % lift, and the power at the observed 12 % lift was 0.47. Five unadjusted looks would carry a 14.3 % false-positive rate; the O'Brien–Fleming boundary at the final look is 2.040 and the observed |z| of 1.894 does not reach it.




References

Kohavi, R., Longbotham, R., Sommerfield, D., and Henne, R. M. (2009). "Controlled Experiments on the Web: Survey and Practical Guide." Data Mining and Knowledge Discovery, Vol. 18, No. 1, pp. 140–181.

Kohavi, R., Deng, A., Longbotham, R., and Xu, Y. (2014). "Seven Rules of Thumb for Web Site Experimenters." In Proceedings of the 20th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, ACM, New York, pp. 1857–1866.

Kohavi, R., Tang, D., and Xu, Y. (2020). Trustworthy Online Controlled Experiments: A Practical Guide to A/B Testing. Cambridge University Press, Cambridge.

Wilson, E. B. (1927). "Probable Inference, the Law of Succession, and Statistical Inference." Journal of the American Statistical Association, Vol. 22, No. 158, pp. 209–212.

Newcombe, R. G. (1998). "Interval Estimation for the Difference Between Independent Proportions: Comparison of Eleven Methods." Statistics in Medicine, Vol. 17, No. 8, pp. 873–890.

Newcombe, R. G. (1998). "Two-Sided Confidence Intervals for the Single Proportion: Comparison of Seven Methods." Statistics in Medicine, Vol. 17, No. 8, pp. 857–872.

Agresti, A. (2013). Categorical Data Analysis, 3rd ed. John Wiley and Sons, Hoboken, NJ.

Fisher, R. A. (1935). The Design of Experiments. Oliver and Boyd, Edinburgh.

Welch, B. L. (1947). "The Generalization of 'Student's' Problem When Several Different Population Variances Are Involved." Biometrika, Vol. 34, No. 1–2, pp. 28–35.

Cohen, J. (1988). Statistical Power Analysis for the Behavioral Sciences, 2nd ed. Lawrence Erlbaum Associates, Hillsdale, NJ.

Holm, S. (1979). "A Simple Sequentially Rejective Multiple Test Procedure." Scandinavian Journal of Statistics, Vol. 6, No. 2, pp. 65–70.

Cook, J. D. (2005). Exact Calculation of Beta Inequalities. Technical Report UTMDABTR-005-05, Department of Biostatistics, The University of Texas M. D. Anderson Cancer Center, Houston, TX.

Miller, E. (2015). Formulas for Bayesian A/B Testing. evanmiller.org, 1 October 2015.

Stucchio, C. (2015). Bayesian A/B Testing at VWO. Visual Website Optimizer (Wingify), Pune.

R Core Team (2024). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna.

Fleiss, J. L., Levin, B., and Paik, M. C. (2003). Statistical Methods for Rates and Proportions, 3rd ed. John Wiley and Sons, Hoboken, NJ.

van Belle, G. (2002). Statistical Rules of Thumb. John Wiley and Sons, New York.

Armitage, P., McPherson, C. K., and Rowe, B. C. (1969). "Repeated Significance Tests on Accumulating Data." Journal of the Royal Statistical Society, Series A (General), Vol. 132, No. 2, pp. 235–244.

Pocock, S. J. (1977). "Group Sequential Methods in the Design and Analysis of Clinical Trials." Biometrika, Vol. 64, No. 2, pp. 191–199.

O'Brien, P. C., and Fleming, T. R. (1979). "A Multiple Testing Procedure for Clinical Trials." Biometrics, Vol. 35, No. 3, pp. 549–556.

Jennison, C., and Turnbull, B. W. (2000). Group Sequential Methods with Applications to Clinical Trials. Chapman and Hall/CRC, Boca Raton, FL.

SAS Institute Inc. (2011). SAS/STAT 9.3 User's Guide: The SEQDESIGN Procedure. SAS Institute Inc., Cary, NC.

Wichura, M. J. (1988). "Algorithm AS 241: The Percentage Points of the Normal Distribution." Journal of the Royal Statistical Society, Series C (Applied Statistics), Vol. 37, No. 3, pp. 477–484.

Marsaglia, G., and Tsang, W. W. (2000). "A Simple Method for Generating Gamma Variables." ACM Transactions on Mathematical Software, Vol. 26, No. 3, pp. 363–372.

Worked Examples

Published examples this tool reproduces; each page lists the inputs to enter and the printed answers.

All worked examples


DISCLAIMER: The methods and calculation on aNOWysis.com are provided as means to educate the reader. There is no warranty, expessed or implied, as to the relevance or accuracy of the methods or calculations. All calculations should be checked by a qualified analyst for appropriateness and accuracy. We will not be held liable for any damages, injuries or deaths caused by using methods or calculations from this site.