Statistics for evaluation
An evaluation result is a measurement taken on a sample. "Version B passes 84% of the golden set, version A passed 81%" sounds like progress, but another 200 cases, another run of the same cases or another grader would give different numbers. Without an estimate of that variation, nobody can say whether B is better, equal or worse.
This chapter turns evaluation numbers into statements with known uncertainty: confidence intervals for pass rates, correct comparisons of two versions on the same cases, intervals for any metric with the bootstrap, repeated runs of non-deterministic systems, sample sizes and power, many comparisons at once, and release gates that do not fail at random.
Prerequisites: Evaluation methodology and datasets, Code-based scorers and metrics. The sources of randomness in generation are explained in How LLMs generate text.
Where the uncertainty comes from
Four things make an evaluation score move. Statistics deals with the first three; the fourth is a question of validity that no formula repairs.
| Source | What varies | Reduced by | Not fixed by |
|---|---|---|---|
| Case sampling | Which inputs happen to be in the dataset | More cases, stratified sampling of important slices | More runs of the same cases |
| Generation randomness | The output for the same input | Several runs per case, lower temperature where the feature allows it | More cases with one run each |
| Grader noise | The verdict for the same output | Validated scorers, several judges or raters, averaging | More cases alone |
| Dataset validity | Whether the dataset represents real use | Sampling from production, refreshing the dataset | Any amount of statistics |
Even at temperature 0, outputs of hosted models can differ between runs because of batching and floating-point effects (How LLMs generate text), so generation randomness is present in almost every LLM evaluation.
A pass rate is an estimate
If a system passes k of n independent cases, the observed pass rate estimates the rate you would see on the whole population of inputs the cases were drawn from. The binomial model gives its uncertainty:
observed pass rate p = k / n
standard error SE = sqrt(p · (1 − p) / n)
Wald 95% interval p ± 1.96 · SE
Wilson 95% interval (p + z²/2n ± z · sqrt(p · (1 − p)/n + z²/4n²)) / (1 + z²/n), z = 1.96
zero failures in n cases 95% upper bound on the failure rate ≈ 3 / n (the rule of three)The Wald interval is the one most people remember. The script compares it with the Wilson score interval on typical evaluation results:
Run the code to see the result.
Output:
passed/cases rate Wald 95% interval Wilson 95% interval
42/50 84.0% [ 73.8%, 94.2%] [ 71.5%, 91.7%]
9/10 90.0% [ 71.4%, 108.6%] [ 59.6%, 98.2%]
50/50 100.0% [100.0%, 100.0%] [ 92.9%, 100.0%]
1/30 3.3% [ -3.1%, 9.8%] [ 0.6%, 16.7%]
980/1000 98.0% [ 97.1%, 98.9%] [ 96.9%, 98.7%]The Wald interval claims that 50 passes out of 50 prove a pass rate of exactly 100%, allows 108.6% for 9 of 10 and a negative rate for 1 of 30. The Wilson interval stays between 0 and 1 and says what the data supports: 50 of 50 passes are consistent with a true pass rate as low as 92.9%. Report a pass rate with its interval and sample size, for example "84% (95% CI 72–92%, n = 50)".
The rule of three answers a common question about safety tests: if 300 adversarial cases produce no failure, the failure rate is below about 1% (3/300) with 95% confidence, not zero.
Checking an interval method by simulation
A 95% interval method is correct when it contains the true rate in 95% of repeated experiments. This property, coverage, can be checked directly by simulating evaluations of a system whose true pass rate is known:
Run the code to see the result.
Output:
true rate cases Wald covers Wilson covers
95% 30 78.0% 94.7%
80% 30 95.2% 96.5%
95% 300 92.2% 94.8%For a feature that really passes 95% of cases, a "95%" Wald interval from 30 cases misses the truth more than one time in five. Brown, Cai and DasGupta showed that this erratic coverage is not limited to small samples. Good LLM features have pass rates close to 100%, which is exactly where the Wald interval fails, so use the Wilson interval, or the exact Clopper–Pearson interval when an interval must never cover less than promised. Libraries such as statsmodels implement all of them.
Comparing two versions on the same cases
Most comparisons in LLM work are paired: the current version A and the candidate B answer the same cases. Every case then falls into one of four cells, and only two of them carry information about the difference:
| Outcome | B passes | B fails |
|---|---|---|
| A passes | both pass: no information about the difference | only A passes: evidence for A |
| A fails | only B passes: evidence for B | both fail: no information about the difference |
If A and B were equally good, a case that only one of them passes would be equally likely to favour either, like a fair coin. McNemar's test asks whether the split of these discordant cases is too uneven for a fair coin:
discordant cases b = cases only A passes, c = cases only B passes, n = all cases
difference d = (c − b) / n
paired standard error sqrt(b + c − (c − b)² / n) / n
exact McNemar test two-sided p = 2 · P(X ≤ min(b, c)), X ~ Binomial(b + c, 1/2)The script compares the same three-point improvement on 200 and on 1,000 cases, analysed correctly as paired and incorrectly as two unrelated samples:
Run the code to see the result.
Output:
200 cases: A 81.0%, B 84.0%, only A passes 12, only B passes 18
paired: B - A in [-2.4%, +8.4%], McNemar p = 0.362
unpaired: B - A in [-4.4%, +10.4%]
1000 cases: A 79.0%, B 82.0%, only A passes 30, only B passes 60
paired: B - A in [+1.1%, +4.9%], McNemar p = 0.002
unpaired: B - A in [-0.5%, +6.5%]How to read it:
- On 200 cases, three points are noise. Eighteen against twelve discordant cases is an ordinary coin-flip result (p = 0.36), and the interval runs from B being 2.4 points worse to 8.4 points better.
- On 1,000 cases, the paired analysis finds real evidence: B is better by 1.1 to 4.9 points.
- The unpaired analysis of the same data finds nothing, because it treats the difficulty of each case as noise. Both versions share that difficulty, and pairing cancels it. Running both versions on the same cases and analysing them as pairs is the single cheapest way to make comparisons more sensitive.
Dietterich recommended McNemar's test for comparing two classifiers on one test set for the same reason. For comparisons of more than two systems, or for metrics that are not pass rates, use the bootstrap.
Bootstrap intervals for any metric
Many metrics have no simple formula for their uncertainty: a mean judge score from 1 to 5, an F1 computed over the whole dataset, cost per resolved task. The bootstrap estimates the uncertainty by simulation: it draws new datasets of the same size from the cases you have, with replacement, and recomputes the metric on each. The spread of the recomputed values approximates the spread you would see across real samples of cases.
For comparisons, the paired bootstrap resamples cases and keeps the A and B results of each case together, which preserves the benefit of pairing. Koehn introduced it for comparing machine-translation systems.
Run the code to see the result.
Output:
mean score A 3.90, B 4.15, difference +0.250
95% paired bootstrap interval for B - A: [+0.100, +0.400]
share of resamples where B is not better: 0.04%Practical rules for the bootstrap:
- Resample the unit that was sampled. If the dataset holds 50 conversations with 10 turns each, resample conversations, not turns; turns of one conversation are not independent.
- Use enough resamples and a fixed seed: a few thousand for an interval, and record the seed so that the report can be reproduced.
- It cannot rescue a small or unrepresentative dataset. With very few cases the bootstrap interval is too narrow, and no resampling adds cases that the dataset does not contain.
Repeated runs: pass@k, pass^k and clustered errors
When the same case can pass on one run and fail on the next, a single run per case mixes two questions: how often is the system right, and how consistently. Running every case several times separates them. With c passes in n runs of a case, two different summaries answer two different product questions:
pass@k chance that at least one of k attempts passes = 1 − C(n − c, k) / C(n, k)
pass^k chance that all k attempts pass = C(c, k) / C(n, k)
C(n, k) is the number of ways to choose k runs out of n; both are averaged over casesThe pass@k estimator is the unbiased form introduced with the HumanEval benchmark; pass^k was introduced by τ-bench to measure the reliability of agents.
Run the code to see the result.
Output:
k=1: pass@k = 0.70 pass^k = 0.70
k=3: pass@k = 0.91 pass^k = 0.45
k=5: pass@k = 0.97 pass^k = 0.34From the same runs, the system "solves 97% of tasks within five attempts" and "handles a task correctly five times in a row only 34% of the time". Choose the summary that matches how the output is used:
- pass@k fits when a verifier or a person picks among several attempts, as with generated code checked by tests.
- pass^k fits when every interaction must succeed: an agent that a customer uses every day, a support answer that each customer sees once.
Clustered standard errors
Five runs of 100 cases are not 500 independent observations. Runs of the same case share its difficulty, so they agree with each other more than runs of different cases do. A standard error computed as if the 500 runs were independent is too small; the correct one treats the case as the sampled unit:
Run the code to see the result.
Output:
pass rate 82.2% from 100 cases with 5 runs each
naive standard error 1.71%, 95% interval about 82.2% plus or minus 3.4%
clustered standard error 2.87%, 95% interval about 82.2% plus or minus 5.6%The naive interval is almost 40% too narrow. More runs per case reduce the generation noise within cases, but only more cases reduce the uncertainty about which cases the system can handle. Miller's paper on error bars for language-model evaluations describes clustered standard errors, paired differences and other variance-reduction methods in detail.
Sample size and power
Two planning questions decide how big an evaluation dataset must be: how precisely it measures one version, and how small a difference between two versions it can detect.
precision n = z² · p(1 − p) / E² cases for a 95% interval of about ±E
unpaired n = (z_α + z_β)² · (p_A(1 − p_A) + p_B(1 − p_B)) / δ² cases per version
paired n = (z_α · sqrt(π_d) + z_β · sqrt(π_d − δ²))² / δ² cases run by both versions (Connor, 1987)
δ = p_B − p_A, π_d = share of discordant cases, z_α = 1.96 (5% level), z_β = 0.84 (80% power)Power is the chance that a comparison detects a difference that really exists; 80% is a common target.
Run the code to see the result.
Output:
margin 10%: 97 cases at a 50% pass rate, 35 at 90%
margin 5%: 385 cases at a 50% pass rate, 139 at 90%
margin 3%: 1068 cases at a 50% pass rate, 385 at 90%
margin 2%: 2401 cases at a 50% pass rate, 865 at 90%
80% to 85%: 903 cases per version unpaired, 312 cases paired
80% to 83%: 2626 cases per version unpaired, 870 cases paired
90% to 91%: 13493 cases per version unpaired, 7847 cases pairedWhat this means for real evaluation suites:
- A golden set of 50 cases measures a pass rate to within about ±10 points. It catches a collapse, not a three-point regression.
- Pairing cuts the required cases by a factor of two to three here; the gain depends on how often the versions disagree, which you can measure from a previous comparison.
- One-point improvements of a good system need thousands of cases. If the suite cannot be that large, state the smallest difference it can detect and treat smaller changes as unknown, not as "no change". Card and colleagues found that many published NLP comparisons were underpowered in exactly this way.
Many slices and metrics: multiple comparisons
Each test at the 5% level has a 5% chance of a false alarm when nothing changed. Twenty slices, metrics or judges compared at once almost guarantee one:
Run the code to see the result.
Output:
20 slices and no real change: a significant slice in 64% of evaluations
expected 1 - (1 - alpha) ** slices = 64%
lang=uk p = 0.004 significant
feature=refunds p = 0.030 not significant after correction
feature=delivery p = 0.200 not significant after correction
lang=en p = 0.450 not significant after correctionWays to keep false alarms under control:
- Decide the primary metric and the decision rule before the run. Everything else is exploratory.
- Correct for the number of comparisons when a decision is taken per slice. The Holm procedure controls the chance of any false alarm and is never less powerful than the simpler Bonferroni correction.
- Treat surprising slice results as hypotheses. Read the failing cases (Evaluation methodology and datasets) and confirm the effect on fresh cases before acting on it.
Turning statistics into release gates
A gate such as "the candidate must not score lower than the current version" fails about half the time when the two versions are equally good, so teams learn to ignore it. A gate that accounts for noise compares the interval of the difference with a margin that the product team has agreed to accept:
Run A (current) and B (candidate) on the same cases
↓
Any zero-tolerance case failed? → yes: block
↓ no
Paired difference B − A, 95% interval
↓
Lower bound above −δ (the margin)? → yes: ship
↓ no
Upper bound below 0? → yes: block, a regression
↓ no
Inconclusive: add cases or keep AThis is a non-inferiority decision: the candidate ships when the data shows that it is not worse than the current version by more than δ, for example two points. The margin is a product decision made before the run. Hard gates stay outside statistics: one leaked secret or one broken contract blocks the release regardless of averages (Structured output and validation).
A complete evaluation report states:
| Item | Example |
|---|---|
| Sample | 1,000 cases from production, stratified by language |
| Runs | 3 runs per case, temperature 0.2 |
| Estimate with interval | 82.0% (95% Wilson CI 79.5–84.3%) |
| Comparison | B − A = +3.0 points, paired 95% CI +1.1 to +4.9, McNemar p = 0.002 |
| Decision rule | Non-inferiority margin of 2 points, decided before the run |
| Reproducibility | Dataset version, scorer version, random seed |
| Slices | Holm-corrected; surprising slices sent to error analysis |
Example project
The methods of this chapter are implemented and tested in examples/llm-testing/11-eval-statistics: Wald, Wilson and Clopper–Pearson intervals with simulated coverage, the exact McNemar test checked against complete enumeration, the paired bootstrap, pass@k and pass^k, clustered standard errors, sample-size and power calculations, the Holm correction, and a command-line comparison of two recorded runs that ends in a ship, block or inconclusive decision. All tests run offline, without a model or API keys:
uv sync --project examples/llm-testing
uv run --project examples/llm-testing pytest examples/llm-testing/11-eval-statisticsCommon mistakes
- Reporting a pass rate without the number of cases or an interval.
- Using the Wald interval for small samples or for pass rates near 0% or 100%.
- Comparing two versions that ran on the same cases with an unpaired test, or by looking at two averages.
- Treating repeated runs of the same cases as independent cases, which makes intervals too narrow.
- Reporting pass@k when users experience pass^k.
- Testing many slices and acting on the one that came out significant without a correction or a confirmation.
- Release gates without a margin that fail at random when nothing changed.
- Keeping a golden set too small to detect the regressions that matter, without stating the smallest difference it can detect.
Summary
- An evaluation score is an estimate; case sampling, generation randomness and grader noise make it vary, and dataset validity is a separate question.
- Report every pass rate with its sample size and an interval; prefer the Wilson interval, and remember the rule of three for zero failures.
- Compare versions on the same cases and analyse them as pairs: McNemar's test and the paired interval use only the cases where the versions disagree.
- The paired bootstrap gives intervals for any metric; resample the unit that was sampled.
- With repeated runs, choose pass@k or pass^k by how the output is used, and compute standard errors per case.
- Plan sample sizes in advance: small improvements need hundreds to thousands of paired cases.
- Correct for multiple comparisons, and gate releases with a non-inferiority margin plus hard gates for zero-tolerance failures.