Sub topic 6
Is the difference real? Sample size and significance
This chapter assumes you can compute CTR, conversion rate, and CPA from campaign totals, and that you have a baseline to compare against. Python is optional, but the example uses it.
Why differences appear by chance
Two identical ads shown to two groups of people will rarely produce identical conversion rates. Each visitor converts or doesn't, and the totals bounce around. This is noise. Before you act on a gap between variants, you need to decide whether noise alone could plausibly produce it.
The smaller the sample, the more the rates bounce. Ten conversions out of 200 visitors can easily become 6 or 15 on a rerun. Ten thousand visitors will move far less in relative terms.
The working model
A significance test starts from a skeptical assumption, called the null hypothesis: the two variants convert at the same true rate. It then asks how likely a gap at least this large would be if that were true. That probability is the p-value.
- A small p-value (commonly below 0.05) means the gap would be unusual under pure chance.
- A large p-value means the data is consistent with no real difference.
- A p-value does not give the probability that your variant is better, and it says nothing about whether the gap is big enough to matter commercially.
Running the test
For conversion rates, a two-proportion z-test is a standard choice. It pools both variants to estimate the shared rate under the null hypothesis, then measures the gap in units of standard error.
from math import sqrt, erf
def two_proportion_z(conv_a, n_a, conv_b, n_b):
p_a, p_b = conv_a / n_a, conv_b / n_b
pooled = (conv_a + conv_b) / (n_a + n_b)
se = sqrt(pooled * (1 - pooled) * (1 / n_a + 1 / n_b))
z = (p_b - p_a) / se
p_value = 2 * (1 - 0.5 * (1 + erf(abs(z) / sqrt(2))))
return z, p_value
z, p = two_proportion_z(conv_a=100, n_a=2500, conv_b=130, n_b=2500)
print(round(z, 2), round(p, 3))This prints 2.03 0.043. Variant A converted at 4.0% and variant B at 5.2%. A p-value of 0.043 is below 0.05, so the gap is unlikely to be chance alone. It is also close to the threshold. Treat it as encouraging, not settled.
Sample size
Decide how much data you need before the test starts. Three things drive the requirement:
- The baseline rate. Low rates need more visitors to see the same relative change.
- The smallest lift you care about. Detecting a 5% relative lift takes far more traffic than detecting a 30% lift.
- How much risk of a false alarm you accept, usually 5%.
Count conversions, not only impressions. A test with 50,000 visitors and 20 conversions per arm is still small.
Significant is not the same as important
With enough traffic, a 0.1 percentage point lift can be statistically significant. Ask whether it changes CPA or ROAS enough to justify the cost of the change. Report the size of the gap, with the p-value alongside it.
Also remember the reverse: a non-significant result with a small sample means "not enough evidence," not "no effect." The correct response is usually more data or a bolder variant.
Exercise
Variant A converts 50 of 1,000 visitors. Variant B converts 60 of 1,000. Without running code, would you call B a clear winner, and why?
Show answer
No. The rates are 5% and 6%, and the pooled rate is 5.5%. The standard error is about 0.0102, so z is about 0.98 and the p-value is about 0.33. A gap this size would appear by chance roughly one time in three, so the data gives no evidence that B is better. Collect more data before deciding.