Sub topic 13
Reading small-sample results and confidence intervals
This chapter assumes you know what a smoke test is, can work with percentages, and can read short Python snippets. By the end you will be able to turn a count such as "18 of 400 visitors clicked" into a range of plausible conversion rates and compare that range with the thresholds you set before the test.
Why a single percentage misleads
A smoke test gives you a count of conversions out of a count of visitors. The share is easy to compute, but it is only a sample from the larger population of people who might see your offer. If you ran the same test again with different visitors, you would get a different number.
The question is how far the observed rate could sit from the true rate. A confidence interval answers it with a range. A 95% interval comes from a procedure that, over many repeated tests, captures the true rate about 95% of the time. For decisions, read it as "the rates that are consistent with what I saw."
Two things control the width of the interval:
- The number of visitors. More visitors give a narrower range.
- How close the rate is to 0% or 100%. Ranges are asymmetric near the edges, because a rate cannot go below zero.
The Wilson interval
Many people use the "normal approximation" interval, which is the rate plus or minus a margin. It fails exactly where demand tests live: small samples and low conversion rates. It can produce negative lower bounds, and with zero conversions it gives a range of width zero. The Wilson score interval stays sensible in those cases, so use it by default.
import math
def wilson_interval(successes, trials, z=1.96):
"""95% Wilson score interval for a conversion rate."""
if trials <= 0:
raise ValueError("trials must be positive")
if not 0 <= successes <= trials:
raise ValueError("successes must be between 0 and trials")
p = successes / trials
denom = 1 + z**2 / trials
centre = (p + z**2 / (2 * trials)) / denom
margin = z * math.sqrt(p * (1 - p) / trials + z**2 / (4 * trials**2)) / denom
return centre - margin, centre + margin
low, high = wilson_interval(successes=18, trials=400)
print(f"Observed rate: {18 / 400:.1%}")
print(f"95% interval: {low:.1%} to {high:.1%}")This prints an observed rate of 4.5% and an interval of 2.9% to 7.0%. The best single guess is 4.5%, but the data are also consistent with a true rate as low as 2.9% or as high as 7.0%.
Comparing the interval with your thresholds
The pre-registered test plan from the earlier chapter on success criteria said: build if the lower bound is at least 2%, stop if the upper bound is below 1%. The rule uses the bounds, not the observed rate, because the bounds carry the uncertainty.
With 18 of 400, the lower bound is 2.9%, which is above 2%. The plan says build.
The decision has three outcomes, not two:
The inconclusive branch is the common one with small samples. Here is the rule as code:
import math
def wilson_interval(successes, trials, z=1.96):
"""95% Wilson score interval for a conversion rate."""
if trials <= 0:
raise ValueError("trials must be positive")
if not 0 <= successes <= trials:
raise ValueError("successes must be between 0 and trials")
p = successes / trials
denom = 1 + z**2 / trials
centre = (p + z**2 / (2 * trials)) / denom
margin = z * math.sqrt(p * (1 - p) / trials + z**2 / (4 * trials**2)) / denom
return centre - margin, centre + margin
def decide(successes, trials, build_if=0.02, stop_if=0.01):
low, high = wilson_interval(successes, trials)
if low >= build_if:
verdict = "build"
elif high < stop_if:
verdict = "stop"
else:
verdict = "inconclusive"
return f"{successes}/{trials}: {low:.1%} to {high:.1%} -> {verdict}"
print(decide(18, 400))
print(decide(4, 50))
print(decide(0, 300))
print(decide(0, 400))The output:
18/400: 2.9% to 7.0% -> build
4/50: 3.2% to 18.8% -> inconclusive
0/300: 0.0% to 1.3% -> inconclusive
0/400: 0.0% to 1.0% -> stopLook at the second line. A rate of 8% sounds better than 4.5%, but with only 50 visitors the interval is so wide that it also includes rates below your build threshold. A high rate on a tiny sample is weaker evidence than a modest rate on a large one.
The third line shows a trap. Zero conversions out of 300 feels like a clear failure, but the true rate could still be 1.3%, above your stop threshold of 1%. With zero conversions, the upper bound is roughly 3.84 divided by the number of visitors plus 3.84. You need about 381 visitors with no conversions before the upper bound drops below 1%.
How sample size changes the range
The table shows a 5% observed rate at three sample sizes.
| Visitors | Conversions | 95% interval | Width |
|---|---|---|---|
| 100 | 5 | 2.2% to 11.2% | 9.0 points |
| 400 | 20 | 3.3% to 7.6% | 4.3 points |
| 1,600 | 80 | 4.0% to 6.2% | 2.2 points |
Quadrupling the traffic roughly halves the width. This is why precision gets expensive: going from "roughly right" to "precisely right" costs much more traffic than most early-stage budgets allow. Decide how precise you need to be, and no more. If your build and stop thresholds are 2% and 1%, you need to tell those two rates apart, not to pin the rate down to a tenth of a point.
Planning traffic before you launch
Work backwards from the number of buyers you need to see. This calculation gives the expected visitors, not a guarantee.
import math
def visitors_needed(target_buyers, conversion_rate):
"""Visitors required to expect a given number of buyers at a conversion rate."""
if target_buyers <= 0:
raise ValueError("target_buyers must be positive")
if not 0 < conversion_rate <= 1:
raise ValueError("conversion_rate must be in (0, 1]")
return math.ceil(target_buyers / conversion_rate)
# To expect 20 paying preorders at a 2% visit-to-preorder rate:
print(visitors_needed(20, 0.02))This prints 1000. If clicks on your ads cost $1.50 each, that is about $1,500 of traffic. If that is more than you can spend, either lower the precision you need or test a higher rung of the commitment ladder with a narrower, better-qualified audience.
Common errors
- Peeking and stopping early. Checking the interval daily and stopping when it first crosses a threshold inflates false positives. Set the minimum sample in the plan, as the YAML example does with 300 qualified visitors, and read the result when you reach it.
- Counting the wrong visitors. The denominator must be qualified visitors from your target segment, not bots, friends, or people who bounced in under a second. Defining "qualified" after seeing the data is a form of reinterpretation.
- Mixing sources. If one ad campaign converts at 6% and another at 1%, pooling them hides which audience works. Report the intervals separately, accepting that each will be wider.
- Treating the interval as a probability. A 95% interval does not mean there is a 95% chance the true rate is inside this particular range. It describes the long-run behavior of the method. In practice, the plain-language reading above is good enough for a build decision.
- Ignoring non-sampling error. The interval covers only random variation. It does not cover bias from unrepresentative traffic, a misleading button label, or stated-price answers that overstate real buying. A narrow interval on biased data is precisely wrong.
- Extrapolating to later funnel steps. A 4.5% rate of clicks on a fake door is not a 4.5% rate of paying customers. Apply a separate, honest estimate for the drop between the test action and real purchase.
Stated-price data are noisy too
The Gabor-Granger approach from the willingness-to-pay chapter has the same sampling problem. Each acceptance share is a proportion from a sample, so each deserves an interval.
def gabor_granger_revenue(prices, share_willing):
"""Return the price that maximizes price * share of respondents willing to buy."""
if len(prices) != len(share_willing):
raise ValueError("prices and share_willing must have the same length")
best_price, best_revenue = None, -1.0
for price, share in zip(prices, share_willing):
revenue = price * share
if revenue > best_revenue:
best_price, best_revenue = price, revenue
return best_price, best_revenue
prices = [9, 15, 19, 25, 35]
share_willing = [0.62, 0.48, 0.40, 0.25, 0.12]
print(gabor_granger_revenue(prices, share_willing))The output is (15, 7.199999999999999), so $15 maximizes price times share. But $15 gives 7.20 and $19 gives 7.60 only if you read the shares as exact. Compute 0.48 × 15 = 7.2, 0.40 × 19 = 7.6. The code actually returns 19, since 7.6 is larger.
Correcting the claim above: the function returns (19, 7.6). With 40 respondents per price, the interval for the $19 acceptance share would run from about 26% to 56%, which easily overlaps the shares at neighboring prices. Treat the result as "the best price is somewhere around $15 to $25," then confirm it with a live price test.
Exercise
You ran a fake-door test with a build threshold of 2% (lower bound) and a stop threshold of 1% (upper bound). You got 9 conversions from 250 qualified visitors, an observed rate of 3.6%. The Wilson interval is about 1.9% to 6.7%. What do you decide, and what is one way to reach a clearer answer?
Show answer
The result is inconclusive. The lower bound (1.9%) is just below the 2% build threshold, and the upper bound (6.7%) is far above the 1% stop threshold, so neither rule fires. You can add qualified traffic to narrow the interval, for example by running the test to the 400 visitors a plan like this would normally specify. If the rate holds near 3.6%, the lower bound would rise above 2%. Or you can change the offer or audience and rerun. Do not build on the 3.6% observed rate alone.