A/B Test Sample Size, Statistical Power and Duration Calculator

Last updated

Computes the visitors each variant of an A/B test needs with the normal-approximation formula for two conversion rates used by R's power.prop.test: the pooled rate sets the variance under the null hypothesis and each arm's own rate under the alternative. Takes the baseline rate, a relative or absolute minimum detectable effect, power, significance level, one or two tails, the variant count with optional Bonferroni correction, and daily traffic, then returns the total, days and full weeks.

Minimum detectable effect as
Test type
Correction for 3+ variants
Sample size per variant –
Total sample size –
Days to run –
In full weeks –
Rate to detect –
Effect to detect –
Alpha per comparison –
z for α and for power –
Detectable lift by test length

Enter the current conversion rate, the smallest change worth detecting and the traffic the test will get, and the calculator returns the visitors each variant needs, the total sample, and the days and full weeks to run. A conversion rate is conversions as a percentage of visitors, so a 5% baseline means 5 sign-ups or purchases per 100 visitors. The defaults test that 5% rate for a 10% relative lift, with 80% power, 5% two-tailed significance and 5,000 visitors a day: 31,234 visitors per variant, 62,468 in total and 13 days, rounded up to two full weeks.

How the sample size formula works

A relative lift is an ordinary percentage change of the conversion rate, so 10% on a 5% baseline means 5.5%. An absolute effect counts percentage points, so 0.5 points also means 5.5%, and both give the same answer.

Each visitor either converts or does not, and a yes-or-no outcome with rate p has a variance of p(1 − p), the square of its standard deviation. In the normal-approximation formula for two proportions, under the null hypothesis that both variants convert alike, the variance comes from the pooled rate p̄, the average of the two rates. Under the alternative, each arm keeps its own rate:

n = (zα √(2p̄(1 − p̄)) + zβ √(p1(1 − p1) + p2(1 − p2)))² ÷ (p2 − p1)²

Here p1 is the baseline rate, p2 the rate to detect, zα the normal quantile for the significance level (1 − α/2 for a two-tailed test, 1 − α for a one-tailed one) and zβ the quantile for the power. This is the formula behind R's power.prop.test, whose documentation defines n as the number of observations per group. Frank Harrell's Hmisc package for R uses the same formula, the method of Fleiss, Tytun and Ury without the continuity correction, and its documentation notes that simulations show the uncorrected formulas are quite accurate, so none is applied here. The z values come from M. J. Wichura's Algorithm AS 241 (Applied Statistics, 1988), which its source code calls accurate to about 1 part in 1016.

A two-tailed test can flag a drop as well as a rise, so the calculator also sizes the test for a drop of the same size and keeps the larger of the two numbers. Below a 50% baseline the rise always needs more. Above 50% the drop takes over: at an 80% baseline and a 5-point effect, a rise alone needs 906 visitors per variant, but the two-tailed test needs 1,094. A one-tailed test plans for a rise only.

The total multiplies the per-variant figure by the number of variants k, with traffic split equally, and the days divide that by the daily visitors v:

days = ⌈n × k ÷ v⌉

The defaults, worked by hand

The baseline is p1 = 0.05, and a 10% lift puts the treatment at p2 = 0.055, a gap of 0.005. For a two-tailed test at 5%, zα = 1.959964, and for 80% power zβ = 0.841621. The pooled rate is 0.0525, so the null term is √(2 × 0.0525 × 0.9475) = √0.0994875 = 0.315416, and the alternative term is √(0.05 × 0.95 + 0.055 × 0.945) = √0.099475 = 0.315397. Times the z values these give 0.618205 and 0.265444, which sum to 0.883649. Dividing by the gap of 0.005 gives 176.7298, and squaring that gives 31,233.44, which rounds up to 31,234 visitors per variant.

Two variants make 62,468 visitors. At 5,000 a day that is 12.49 days, so 13 days, or two full weeks. A drop to 4.5% would need only 28,408 visitors per variant, so the rise sets the size. The table agrees: two weeks of traffic gives each variant 35,000 visitors, enough to detect a change of ±9.43%, a little under the planned 10%.

From Fisher's 1 in 20 to Neyman and Pearson's power

The 5% default goes back to R. A. Fisher's Statistical Methods for Research Workers (1925), which observed that "the value for which P = .05, or 1 in 20, is 1.96 or nearly 2" and that "it is convenient to take this point as a limit in judging whether a deviation is to be considered significant or not". That 1.96 is the same z this page uses for a two-tailed test at 5%. Jeff Miller's Earliest Known Uses of Some of the Words of Mathematics credits the book with doing much to popularise the 5% level. The term "null hypothesis" appears in Fisher's The Design of Experiments in 1935.

Power came from Jerzy Neyman and Egon Pearson. Their first joint paper, in Biometrika in 1928, spoke of a "first source of error" and a "second source of error". Their 1933 paper "On the Problem of the Most Efficient Tests of Statistical Hypotheses", in the Philosophical Transactions of the Royal Society, used "errors of first and second kind" and made the alternative hypothesis standard. The same year, "The Testing of Statistical Hypotheses in Relation to Probabilities A Priori", in the Proceedings of the Cambridge Philosophical Society, used the names Type I and Type II error and defined the power of a test as the probability of rejecting the hypothesis tested when an alternative is true. Here α is the Type I error rate and power is 1 − β, where β is the Type II error rate. The 80% default is a convention too: J. Cohen's 1992 "A Power Primer" tabled the sample sizes needed for .80 power across eight standard tests, among them the difference between independent proportions.

From a shopping cart test to whole weeks

A 2009 survey in Data Mining and Knowledge Discovery by Ron Kohavi, Roger Longbotham, Dan Sommerfield and Randal Henne, which lists A/B tests, split tests and Control/Treatment tests among the names for online experiments, tells how Greg Linden at Amazon prototyped recommendations based on the items in a shopping cart. A marketing senior vice-president opposed it, Linden ran a controlled experiment anyway, and the feature won by such a wide margin that not having it live was costing Amazon "a noticeable chunk of change".

The survey's rule of thumb for 95% confidence and 80% power, taken from van Belle, is n = 16σ²/Δ² per variant, with 21 in place of 16 for 90% power. For a conversion rate σ² = p(1 − p), so the defaults give 16 × 0.05 × 0.95 ÷ 0.005² = 30,400, against 31,234 here. The rule takes the variance from the baseline alone, and its 16 rounds 2 × (1.959964 + 0.841621)² = 15.70. The survey's own example, a 5% change in a 5% conversion rate, needs "less than 122,000 users" (this page gives 122,124), and a 20% change cuts that by a factor of 16 to 7,600 (8,158 here). The authors "strongly recommend running experiments for at least a week or two, then continuing by multiples of a week so that day-of-week effects can be analyzed", hence the full weeks figure. They also recommend a 50/50 split, since a 99%/1% split has to run about 25 times longer.

More than one variant

Testing several variants against one control raises the chance that at least one comparison looks significant by luck. Bonferroni's method, as the NIST/SEMATECH e-Handbook of Statistical Methods describes it, runs each of g comparisons chosen in advance at α/g, which keeps the overall confidence at no less than 1 − α. Here g is the number of variants minus one, because each treatment is compared with the control. An A/B/C test therefore runs each comparison at 2.5%, which needs 37,824 visitors per variant, 113,472 in total and 23 days, or four full weeks. Without the correction it needs 31,234 per variant, 93,702 in total and 19 days. Kohavi and his co-authors note that such adjustments amount to raising the confidence level, which costs power; the extra visitors buy it back. They also note that a larger control group adds power when treatments are compared only with the control; this page splits traffic equally.

Reading the results and the table

The detectable lift table asks the reverse question: with one to eight weeks of traffic, what is the smallest effect the test could detect? A row reads "Not detectable" when even the largest effect that keeps the treatment rate below 100% would need more visitors than that length provides. Rates and point effects show three decimals and relative lifts two, or more for small effects, to keep two significant digits; a rate that would display as 100% counts as 100%, and an effect needing over a trillion visitors per variant is reported as too small to test.

The plan fixes the sample size in advance. Ramesh Johari, Leo Pekelis and David Walsh pointed out in 2015 that ordinary p-values and confidence intervals become unreliable when people keep checking a running test and stop once it looks significant, so run to the planned size. Daily visitors means distinct users entering the test; repeat visits make that count grow more slowly than time, though Kohavi's survey finds a linear approximation reasonable for most sites. The formula is a normal approximation, weakest for small samples; for those, the NIST handbook calls the Fisher exact test an excellent choice.

Frequently asked questions

How many visitors does an A/B test need?

It depends most on the smallest effect you want to detect. At the defaults, a 5% baseline conversion rate, a 10% relative lift, 80% power and a 5% two-tailed significance level, each variant needs 31,234 visitors, or 62,468 for an A/B test. At 5,000 visitors a day that takes 13 days, which rounds up to two full weeks. The requirement grows with the inverse square of the effect, so halving the lift to 5% needs 122,124 visitors per variant, about 3.9 times as many.

What is the difference between a relative and an absolute minimum detectable effect?

A relative effect is a percentage change of the conversion rate, while an absolute effect is counted in percentage points. On a 5% baseline, a 10% relative lift and a 0.5-point absolute lift describe the same treatment rate of 5.5%, so both need 31,234 visitors per variant. The two diverge as the baseline moves: on a 20% baseline, a 10% relative lift is 2 points.

Should I use a one-tailed or a two-tailed test?

A two-tailed test can flag a change in either direction, and at 5% significance it uses a z of 1.96. A one-tailed test looks only for a rise and uses 1.6449, so the defaults drop from 31,234 to 24,603 visitors per variant. The price is that a one-tailed test cannot declare a drop significant, so choose before the test starts. For a two-tailed test this calculator also sizes for a drop and keeps the larger number, which matters above a 50% baseline: at an 80% baseline and a 5-point effect it needs 1,094 per variant, against 906 for a rise alone.

Why are 80% power and 5% significance the usual defaults?

Both are conventions. R. A. Fisher wrote in 1925 that the value for which P = .05, or 1 in 20, is 1.96 or nearly 2, and that it is convenient to take this point as a limit for judging significance. Jerzy Neyman and Egon Pearson defined the power of a test in 1933, and J. Cohen's 1992 A Power Primer tabled the sample sizes needed for .80 power across eight standard tests. A test with less power is more likely to miss a real effect of the size you planned for.

How does testing more than one variant change the sample size?

Each extra variant adds another comparison with the control and another chance of a false positive. With the Bonferroni correction, an A/B/C test runs each of its two comparisons at 2.5%, which needs 37,824 visitors per variant, 113,472 in total and 23 days at 5,000 a day. Without the correction it needs 31,234 per variant, 93,702 in total and 19 days, but the chance that at least one comparison is a false positive rises above 5%.

How do I check significance once the test ends?

This page plans a test before it runs; it does not compute a p-value from results. For a finished test, the NIST/SEMATECH e-Handbook gives the pooled two-proportion z statistic: the difference between the two observed rates divided by the square root of p(1 − p)(1/n1 + 1/n2), where p is the pooled rate of both groups. In a two-tailed test at 5%, a z further from zero than 1.96 is significant. Decide the sample size in advance and do not stop the first time the result looks significant.

Sources

  1. power.prop.test: Power Calculations for Two-Sample Test for Proportions, R Core Team, R stats package documentation
  2. bpower: Power and Sample Size for Two-Sample Binomial Test (Frank Harrell, Hmisc), Vanderbilt University Department of Biostatistics, via rdrr.io
  3. NIST/SEMATECH e-Handbook of Statistical Methods, 7.3.3 Comparing two proportions, National Institute of Standards and Technology
  4. NIST/SEMATECH e-Handbook of Statistical Methods, 7.4.7.3 Bonferroni's method, National Institute of Standards and Technology
  5. Controlled experiments on the web: survey and practical guide (Kohavi, Longbotham, Sommerfield, Henne), Data Mining and Knowledge Discovery, via exp-platform.com, 2009
  6. Algorithm AS 241: The Percentage Points of the Normal Distribution (M. J. Wichura), Applied Statistics, via StatLib, Carnegie Mellon University, 1988
  7. Statistical Methods for Research Workers, Chapter III (R. A. Fisher), Classics in the History of Psychology, York University, 1925
  8. Earliest Known Uses of Some of the Words of Mathematics (P): Power, P-value (Jeff Miller), MacTutor History of Mathematics, University of St Andrews
  9. Earliest Known Uses of Some of the Words of Mathematics (T): Type I and Type II Error (Jeff Miller), MacTutor History of Mathematics, University of St Andrews
  10. Earliest Known Uses of Some of the Words of Mathematics (H): Hypothesis (Jeff Miller), MacTutor History of Mathematics, University of St Andrews
  11. A power primer (J. Cohen), Psychological Bulletin, via PubMed, 1992
  12. Always Valid Inference: Bringing Sequential Analysis to A/B Testing (Johari, Pekelis, Walsh), arXiv, 2015