Lesson 15 of 19 · Statistics for AI, GenAI & LLMs

Limit Theorems & Hypothesis Testing: When Is a Difference Real?

Lesson 9 told you a 5-point gain can be noise. This lesson gives you the machinery that puts an exact number on that doubt, and the traps that machinery sets for you.

Every eval you run produces a number from a finite sample. Lesson 5 showed that such numbers wobble, and Lesson 9 showed that a new prompt scoring higher might just be lucky. What you have not yet seen is the formal procedure that turns "might be lucky" into a calculation: the hypothesis test. This lesson covers the law that says averages settle, the test framework, two fully worked tests (one on pass rates, one on latency), and three ways testing misleads people who use it carelessly.

1. The law of large numbers: averages settle

The law of large numbers (LLN) says: if you average more and more independent draws that share the same true mean, the average converges to that mean. It is the guarantee that measuring works at all. An eval pass rate over 10,000 examples is a better estimate of a model's true pass rate than one over 25, and with enough examples it gets as close as you like.

The LLN and the Central Limit Theorem (Lesson 5) are two answers to two different questions. The LLN says where the average ends up. The CLT says how it is spread around that destination for a given N: a bell curve whose width is the standard error. We don't re-teach the CLT here; we use its result, the standard error.

Here is how fast an eval settles. Suppose a prompt's true pass rate is 0.80, so each graded example is a 0-or-1 draw with standard deviation √(0.80 × 0.20) = 0.40. The standard error of the measured pass rate is 0.40 / √N:

Eval examples (N)Standard errorTypical range (±2 SE)
250.0800.64 to 0.96
1000.0400.72 to 0.88
4000.0200.76 to 0.84
10,0000.0040.792 to 0.808

The same law powers Monte Carlo estimates. If you want the expected length of a model's reply under sampling, or the chance a sampled answer passes a checker, you generate N replies and average. The estimate converges to the truth, with error shrinking like 1/√N. So 100 times more samples buys only 10 times less error.

Pitfall The LLN converges to the mean of whatever you sampled. If the eval set is unrepresentative, or contains many near-duplicate items (so the draws are not independent), more examples settle on the wrong number with great confidence. The LLN fixes noise. It does not fix bias.

2. The hypothesis-testing framework

You have two prompts and an eval score for each. A hypothesis test is a fixed five-step routine for asking whether the gap is bigger than luck would produce.

PieceWhat it isPrompt A vs B example
Null hypothesis H0The boring claim: no real difference. You assume it and see if the data contradicts it.Both prompts have the same true pass rate.
Alternative H1What you suspect instead.The true pass rates differ (two-sided).
Test statisticOne number summarizing how far the data sits from H0, measured in standard errors.z = (observed gap) / (standard error of the gap)
p-valueIf H0 were true, how often would the statistic land at least this far from zero, by luck of the draw alone?Computed from the Normal curve (below).
Significance level αThe cutoff you fix before looking. If p < α, you reject H0. Usually 0.05.α = 0.05, so reject when |z| > 1.96.

The number 1.96 is the point on the standard Normal curve with 2.5% of the area beyond it on each side, so 5% in total. The CLT is why the Normal curve from Lesson 4 applies to an average or a gap of averages.

What a p-value is, and what it is not

The p-value is the probability of seeing a result at least this extreme, assuming H0 is true. It is a statement about the data under a hypothesis, not a statement about the hypothesis.

The common misreading A p-value of 0.03 does not mean "there is a 3% chance the prompts are equal," or "a 97% chance B is better," or "a 3% chance this result is a fluke." Those are probabilities of the hypothesis given the data, which is the direction Bayes' Theorem (Lesson 3) flips and Lesson 16 returns to. The p-value runs the other way: it is the chance of the data given H0. It also says nothing about how big or how useful the difference is.

Two ways to be wrong

H0 actually true (no real difference)H0 actually false (real difference)
Test rejects H0Type I error (false positive). Probability = α. You ship a prompt that is no better.Correct. Probability = power.
Test does not rejectCorrect.Type II error (false negative). Probability = β = 1 − power. You discard a prompt that really was better.

These mirror the false-positive and false-negative cells of Lesson 9's confusion matrix, applied to a claim instead of a single example. Setting α = 0.05 caps your Type I rate at 5% when H0 is true. Power is the chance of catching a difference that really exists. It depends on three things: how big the true difference is, how noisy the data is, and N. Small eval sets have low power, which is the formal reason a 20-example eval cannot confirm much.

3. Worked example: a two-proportion z-test

A team compares two prompt variants on the same task, each run on its own 800 eval examples and graded pass/fail. Prompt A passes 600 (75.0%). Prompt B passes 640 (80.0%). Is B really better?

Setup. H0: pA = pB. H1: pA ≠ pB. α = 0.05, two-sided.

Under H0 the two prompts share one pass rate, so we estimate it by pooling both groups:

n_A = n_B = 800 successes: A = 600, B = 640
p_A = 600/800 = 0.750 p_B = 640/800 = 0.800
observed gap = 0.800 - 0.750 = 0.050
pooled proportion = (600 + 640) / (800 + 800) = 1240/1600 = 0.775
standard error = sqrt( p(1-p) * (1/n_A + 1/n_B) )
= sqrt( 0.775 * 0.225 * (1/800 + 1/800) )
= sqrt( 0.174375 * 0.0025 )
= sqrt(0.00043594) = 0.02088
z = 0.050 / 0.02088
z = 2.39
p-value (two-sided) = 2 * P(Z > 2.39) = 0.0166

Now the picture. The curve is the distribution of z if H0 were true. The shaded tails are the rejection region: the 5% of outcomes most extreme under H0. Our z = 2.39 falls inside the right tail.

-1.960+1.96 -2.39+2.39 Distribution of z if the prompts are truly equal (H0) reject H0 reject H0 observed z = 2.39 p = 0.0166 Horizontal axis: test statistic z, in standard errors. Red area total = 0.05.

Null distribution of the test statistic. Red tails: rejection region (|z| > 1.96, area 0.05). Yellow: observed z = 2.39; the area beyond ±2.39 is the p-value.

Interpretation. Because 0.0166 < 0.05, reject H0. If the prompts were truly equal, a gap of 5 points or more in either direction would appear in only about 1.7% of eval runs this size. That is decent evidence B is better. It is not proof, and it does not mean B is better with 98.3% probability.

A 95% confidence interval for the gap tells you more than the verdict. Using the unpooled standard error √(0.75×0.25/800 + 0.80×0.20/800) = 0.02084:

0.050 +/- 1.96 * 0.02084 = 0.050 +/- 0.041
gap plausibly between +0.9 and +9.1 points

The interval excludes zero (that is what "significant at 0.05" means), but it is wide. The true gain could be under 1 point or nearly 9.

Same 5-point gap, three eval sizes

Lesson 9 compared 75% vs 80% at N = 20 and N = 500. Here is the full calculation at both sizes, plus the 800 above. At 500 the result is borderline:

N per promptPasses (A / B)Std. errorzp-valueVerdict at 0.05
2015 / 160.13210.380.705No evidence
500375 / 4000.02641.890.058Just misses
800600 / 6400.02092.390.017Significant

Nothing changed except N. The standard error shrank, so the same gap became more standard errors from zero. Also, 0.058 versus 0.049 is no real distinction: 0.05 is a convention, not a cliff.

Power: would this test have caught a real 5-point gain?

Suppose the true gap really is 0.05. With 800 per prompt, the test statistic's typical size is 0.05 / 0.02084 = 2.40. It must beat 1.96, and luck moves it up or down by about one unit, so the chance it clears 1.96 is the Normal area below 2.40 − 1.96 = 0.44, which is about 0.67.

power at N = 800 per arm ≈ Φ(0.05 / 0.02084 − 1.96) = Φ(0.44) ≈ 0.67
Type II error rate β ≈ 1 − 0.67 = 0.33

So even with 800 examples a real 5-point gain is missed one time in three. The usual target is 80% power. Solve for N per arm:

N = (z_alpha/2 + z_beta)^2 * (pA(1-pA) + pB(1-pB)) / gap^2
= (1.96 + 0.84)^2 * (0.75*0.25 + 0.80*0.20) / 0.05^2
= 7.84 * 0.3475 / 0.0025
N is about 1,090 per prompt

Run this before building the eval set. It is the formal version of Lesson 9's rule of thumb.

4. Worked example: a t-test on a continuous metric

Pass rates are 0-or-1, so one proportion fixes the spread. A continuous metric like latency has its own spread, which you must estimate from the data. When you do that with a modest sample, the test statistic is called t instead of z, and its reference curve (the t-distribution) has slightly heavier tails than the Normal. With a few dozen or more observations per group, the two are very close.

A team times two serving configurations, 40 requests each:

ConfignMean latencyStd. dev.
A (baseline)40212 ms38 ms
B (new batching)40198 ms34 ms

H0: the true mean latencies are equal. H1: they differ. α = 0.05, two-sided. This is the Welch version, which does not assume the two configs have equal spread:

gap = 212 - 198 = 14 ms
variance of each mean: 38^2/40 = 1444/40 = 36.10
34^2/40 = 1156/40 = 28.90
standard error of gap = sqrt(36.10 + 28.90) = sqrt(65.00) = 8.06 ms
t = 14 / 8.06
t = 1.74
degrees of freedom (Welch) = 77.05
p-value (two-sided) = 0.086

The critical t for 77 degrees of freedom at α = 0.05 is about 1.99, and 1.74 does not reach it. Do not reject H0. The 95% interval for the gap is 14 ± 1.99 × 8.06 = −2.1 to +30.1 ms, which includes zero.

Key Insight "Not significant" does not mean "no difference." It means this sample cannot separate a 14 ms gain from luck. Here the interval runs from slightly worse to 30 ms better. At 160 requests per config, the same means and spreads would give SE = 4.03 and t = 3.47, which is clearly significant. The difference didn't change; the information did.
Pitfall Lesson 2 showed latency is right-skewed, with a long tail from cold starts and retries. A t-test compares means, and a handful of extreme requests can dominate both the mean and the spread. If users feel the tail, test p95 with a bootstrap (resample your data many times and watch the statistic) instead.

5. Effect size vs. statistical significance

Significance asks "is the gap distinguishable from zero?" It does not ask "is the gap large?" The standard error shrinks as N grows, so with enough data any nonzero gap eventually becomes significant, however trivial.

Take two models with true pass rates 0.800 and 0.802, each evaluated on 1,000,000 examples:

pooled = 0.801
standard error = sqrt( 0.801 * 0.199 * (2/1,000,000) ) = 0.000565
z = 0.002 / 0.000565
z = 3.54, p = 0.0004
95% interval for the gap: 0.09 to 0.31 points

The p-value is tiny and the result is "highly significant," yet the best case is a third of a point. Whether that matters is a product decision, not a statistical one. Compare the earlier latency test: not significant, but a plausible 14 ms gain worth chasing with more data. Report both numbers every time:

Decide in advance the smallest gap worth shipping and size the eval to detect it with good power, instead of testing until something crosses 0.05.

6. Multiple comparisons: test enough things and something will "win"

The 5% false-positive rate applies to one test. A team tries 20 prompt variants against the baseline, and suppose none is truly better. Each test has a 5% chance of a false positive:

expected false positives = 20 * 0.05 = 1.0
P(at least one false positive) = 1 - (1 - 0.05)^20 = 1 - 0.358
P = 0.64

That is a 64% chance of declaring a winner when nothing works. This is how repeated prompt tweaking overfits an eval set (the held-out warning in Lesson 9's checklist), and why "we found a prompt that beats the baseline" claims fall apart on fresh data.

The simplest repair is the Bonferroni correction: divide α by the number of tests. For 20 variants, each must clear 0.05 / 20 = 0.0025, which means |z| > 3.02 instead of 1.96. The total chance of any false positive then stays near 5% (exactly 1 − 0.997520 = 0.049). Our worked example's p = 0.0166 passes at 0.05 but would not survive 20 comparisons. The cost: Bonferroni is conservative and lowers power, so real gains become harder to confirm. Other methods (such as false discovery rate control) trade this off differently, but the habit is the same: count everything you tried, not just the one that worked.

7. Why this matters for building AI systems

Why This Matters Most shipping decisions compare two noisy numbers: prompt vs prompt, model vs model, config vs config. Testing is how you decide without fooling yourself.

Recap

Leads into Lesson 16

A p-value tells you how surprising the data would be if the null were true. It never gives the probability you actually want: how likely is it that B is better, given what we saw? Answering that means flipping the condition with Bayes' Theorem (Lesson 3) and treating the unknown pass rate itself as something with a probability distribution. That is Bayesian inference, the subject of Lesson 16.

✅ Check Yourself

1. A prompt's true pass rate is 0.80. What does the law of large numbers promise about the measured pass rate on an eval set?

Any eval set of 100 or more examples will measure exactly 0.80
Measuring on more examples removes any bias in how the eval set was chosen
As independent examples accumulate, the measured rate tends toward 0.80, with typical error shrinking like 1/√N

2. A comparison of two prompts returns p = 0.03. Which statement is correct?

If the prompts were truly equal, a gap at least this large would appear in about 3% of eval runs
There is a 3% chance the two prompts are actually equal
There is a 97% chance the new prompt is better

3. Your 20-example eval fails to show a significant gain even though the new prompt really is better. What happened?

A Type I error: you rejected a true null hypothesis
A Type II error: the test had too little power to detect a real difference
The p-value was computed incorrectly because N was below 30

4. A 0.2-point accuracy gain is "highly significant" (p = 0.0004) on a 1,000,000-example test set. What should you conclude?

The gain is large and clearly worth shipping
The test must be wrong, since such a small gap can never be significant
The gap is very likely nonzero, but its size is small; judge whether 0.2 points matters using the effect size and its interval

5. You test 20 prompt variants against a baseline at α = 0.05, and none is truly better. Roughly what do you expect, and what does Bonferroni do?

No false positives, since none are truly better; Bonferroni is unnecessary
About 1 false positive on average; Bonferroni requires each test to reach p < 0.0025
About 5 false positives; Bonferroni raises α to 0.25 so fewer are missed