Sub topic 10
Significance, Power, and Sample Size
This chapter assumes that you can serve two model versions, split users into groups, and calculate a metric such as conversion rate. It also assumes basic probability, proportions, and averages.
A production experiment asks whether a candidate model changes an outcome. For example, the stable model may produce 480 conversions from 10,000 users, while the candidate produces 540 from 10,000 users. The candidate rate is higher, but random variation can produce differences even when the models are equally effective.
Statistical significance
Statistical significance measures how surprising the observed difference would be if there were no real difference. The usual null hypothesis says that the control and treatment have the same conversion rate.
A two-sided two-proportion z-test compares two conversion rates:
p_a = x_a / n_ais the control rate.p_b = x_b / n_bis the candidate rate.- The pooled rate combines both groups under the null hypothesis.
- The p-value is the probability of seeing a difference at least this large by chance.
A small p-value provides evidence against the null hypothesis. A common threshold is 0.05, but that threshold is a decision rule, not a guarantee that the candidate is useful.
from math import sqrt
from statistics import NormalDist
def two_proportion_z_test(x_a: int, n_a: int, x_b: int, n_b: int):
p_a, p_b = x_a / n_a, x_b / n_b
pooled = (x_a + x_b) / (n_a + n_b)
standard_error = sqrt(
pooled * (1 - pooled) * (1 / n_a + 1 / n_b)
)
z = (p_b - p_a) / standard_error
p_value = 2 * (1 - NormalDist().cdf(abs(z)))
return z, p_value
z, p_value = two_proportion_z_test(480, 10_000, 540, 10_000)
print("z =", round(z, 2))
print("p-value =", round(p_value, 4))Statistical significance does not measure the size or business value of an improvement. A tiny improvement can become significant with millions of observations. Always report the absolute difference, relative difference, and a confidence interval alongside the p-value.
Power and minimum sample size
Power is the probability that an experiment detects a real effect of a chosen size. An experiment with low power can miss a valuable candidate. This is called a false negative, or a Type II error.
Before starting, choose:
- The baseline conversion rate.
- The minimum detectable effect (MDE), which is the smallest improvement worth acting on.
- The significance level, often 0.05.
- The desired power, often 0.80 or 0.90.
- The traffic split and expected experiment duration.
Sample size depends strongly on the baseline rate and MDE. Detecting a change from 10.0% to 10.1% requires much more data than detecting a change from 10.0% to 12.0%.
| Decision | Meaning |
|---|---|
| Significance level | Tolerated probability of a false positive |
| Power | Probability of detecting the chosen real effect |
| MDE | Smallest effect that justifies action |
| Sample size | Observations needed for the planned decision |
Planning and interpreting results
Estimate sample size before routing traffic. If the experiment collects too few observations, extend it or record that it was inconclusive. Do not quietly change the MDE after seeing the results.
Repeatedly checking results and stopping when a p-value crosses 0.05 increases false positives. Set a stopping rule in advance, or use a sequential testing method designed for repeated looks.
Exercise
An experiment reports a p-value of 0.03, but the candidate's latency is 25% higher than the stable model's. Should the candidate be promoted?
Show answer
No. The result is statistically significant, but the latency guardrail fails. Investigate the trade-off or keep the stable model.