Statistical methods for evaluating LLMs, agents, and generative AI systems from first principles.
- Motivation
- The Binomial Model
- Point Estimates
- Sampling Uncertainty
- Standard Errors and Confidence Intervals
- Coverage and the Wilson Interval
- Clustered Data and Effective Sample Size
- Missing Data and Survivorship Bias
- Beyond the Mean: Distributions and Percentiles
- Paired Comparisons and McNemar's Test
Suppose Company B releases a new model (Model B) and publishes a benchmark showing an 84% pass rate against an existing baseline from Company A (Model A) at 78%, a 6 percentage point lead. Before we conclude that Model B truly outperforms Model A, we need to ask two basic questions: how much could each score change if we reran the benchmark, and did we compare the two models fairly on the same tasks?
Each model has its own unknown true pass rate
We do not need to invent new mathematics to answer this. Over a century of statistics, experimental design, and measurement theory already solves these problems. We start from the simplest case and build up one piece at a time.
Consider running Model A on 1) and 3 failures (0). Each task is a binary outcome (a Bernoulli trial) with an unknown probability
When the tasks are independent and share the same pass probability
We never observe the true probability
Model A's 78% and Model B's 84% are both point estimates. A bare percentage hides the sample size
Because
Suppose we run Model A three times on
Zooming into individual tasks shows why this happens in LLM and agentic evaluations. Even on the exact same set of questions, stochastic decoding, tool calls, and multi-turn trajectories can flip a task between pass and fail across runs (within-item rollout variance).
The size of the evaluation determines how much a single task changes the score. On
This brings us back to Model A (78%) vs. Model B (84%). One model just swung 10 percentage points (76% to 86%) across three runs of 50 tasks. Could a 6 percentage point lead for Model B just be ordinary sampling variability?
To quantify sampling uncertainty, statisticians use standard errors and confidence intervals.
Return to Model A from run 1 above: 41 passes out of
That is 5.4 percentage points. Because
Derivation: where the standard error formula comes from
Each binary task has variance
Research papers usually report a confidence interval rather than a standard error alone. A confidence interval gives a plausible range around
For Model A (41/50 = 82%), the 95% Wald interval is 0.82 ± 0.106, or [0.71, 0.93]. The unknown true pass rate
Aside: from standard error to a 95% confidence interval (test inversion)
Under the central limit theorem, inverting the two-sided test at
Returning to Model A (78%) vs. Model B (84%) makes the impact of sample size immediate. At
A 95% confidence interval promises 95% nominal coverage across repeated runs. Different interval formulas achieve different actual coverage. When actual coverage falls below 95%, the interval suffers from undercoverage and produces false confidence. When actual coverage exceeds 95%, it suffers from overcoverage and is wider than necessary.
The Wald interval suffers from severe undercoverage when [100%, 100%].
The Wilson score interval fixes both failures by inverting the binomial test without plugging [0%, 100%].
Q&A: What if we observe 0 failures in our eval? (The Rule of Three)
Observing 0 failures in
Suppose we evaluate a model on 100 benchmark questions and run each question 10 times. That produces 1,000 rows, but it is not a sample of 1,000 independent observations.
The 10 runs on the same question share the same prompt and difficulty, so their outcomes are correlated (clustered data). Treating all 1,000 rows as independent understates the standard error and produces intervals that are too narrow.
To measure how many independent observations the dataset is actually worth, statisticians divide total rows by the design effect:
Here
When every question gets the same number of runs (
To measure that breakdown across realistic agentic regimes, we run a 5,000-trial Monte Carlo simulation of 100 tasks
Reproduce the simulation (Python and results table)
| Regime | DEFF | Mean |
Naive 95% CI coverage | Cluster-robust 95% CI coverage | Mean half-width (naive vs. cluster) | ||
|---|---|---|---|---|---|---|---|
| Independent (i.i.d.) | 0.0 | 1.0 | 1,000 | 78.02% | 94.7% | 95.0% |
|
| Noisy rollouts | 0.2 | 2.8 | 357 | 78.01% | 75.7% | 94.8% |
|
| Tool-use agents | 0.5 | 5.5 | 182 | 78.03% | 59.5% | 94.5% |
|
| Coding agents | 0.8 | 8.2 | 122 | 77.94% | 51.3% | 94.2% |
|
Run the standalone NumPy script locally (view source):
python3 simulations/clustered_coverage.pyIn practice: computing clustered standard errors without guessing correlation
You do not need to guess
$$\hat{p} = \frac{1}{M}\sum_{q=1}^{M} \bar{y}q, \qquad \widehat{\mathrm{SE}}{\mathrm{cluster}}(\hat{p}) = \sqrt{\frac{1}{M(M - 1)} \sum_{q=1}^{M} (\bar{y}_q - \hat{p})^2}$$
If you use the bootstrap, resample questions with replacement (keeping all
Sample size can also mislead when the evaluation pipeline silently drops failed runs from the denominator. Suppose Model A attempts 100 tasks and produces 70 passes, 10 graded failures, 12 timeouts, and 8 malformed outputs. Across all 100 attempted tasks, the true pass rate is 70/100 (70.0%). If the harness drops the 12 timeouts and 8 malformed outputs as unscored, the reported pass rate jumps to 70/80 (87.5%), an artificial gain of 17.5 percentage points.
In LLM and agentic evaluations, timeouts, context-window overflows, tool loops, and malformed JSON happen disproportionately on hard tasks (Missing Not At Random, or MNAR). Removing those rows selectively deletes hard failures and produces survivorship bias. A related pipeline bug is retrying crashed runs and keeping only the passing retries. If 8 of the 20 errored tasks pass on retry while the remaining 12 are still dropped, the reported score rises to 78/88 (88.6%), silently replacing single-attempt evaluation (pass@1) with hidden multi-attempt selection.
Warning
Watch for the phrase "among completed runs" in evaluation reports. Wording such as "among completed runs", "among valid outputs", or "excluding parser errors" signals survivorship bias. Use intent-to-treat scoring instead: keep every attempted task in the denominator, score model-caused timeouts, infinite loops, and malformed outputs as failures, and report true infrastructure outages separately rather than silently filtering them out.
Sampling theory checklist: other ways evaluation sample sizes mislead
- Near-duplicate and template items (pseudoreplication): A benchmark with 2,000 rows generated from 200 seed templates does not contain 2,000 independent observations. Shared templates create hidden clustering that inflates apparent sample size.
- Benchmark contamination and adaptive overfitting (non-independent test set): Training-data leakage or repeated prompt and scaffold tuning against one static evaluation set breaks independence from the target population. Wider or narrower confidence intervals cannot fix a biased sample.
- Optional stopping (peeking): Checking results after 50 tasks and stopping when a gap looks significant (or adding more tasks when it does not) pushes false-positive rates well above 5%.
-
Shared LLM-as-a-judge error (measurement error): When one model grades all 1,000 outputs, systematic grader bias does not average out as
$n$ grows, and judge variance adds uncertainty missing from binomial standard errors. - Frame and distribution mismatch (covariate shift): Evaluating on an easy convenience sample produces a tight confidence interval around the wrong population pass rate if production traffic consists mostly of harder multi-step tasks.
A point estimate and its confidence interval describe the mean pass rate, not the stability of individual runs. Consider a separate comparison of two candidate models, Model A and Model B, across 7 evaluation runs each. Model A scores 77%, 78%, 79%, 80%, 81%, 82%, and 83%. Model B scores 20%, 70%, 75%, 95%, 100%, 100%, and 100%. Both models have the exact same mean of 80.0%, and Model B even has a higher median (95.0% vs. 80.0%) and three 100% runs.
Looking at the full score distribution tells a different story. Model A stays inside a 6 percentage point band (SD = 2.2 pp). Model B spans 80 percentage points (SD = 29.3 pp) and drops to 20% on its worst run. In production, a high ceiling does not offset catastrophic tail failures.
Percentiles summarize the full distribution without collapsing it to a single average. Lower percentiles such as P5 and P10 (alongside the worst observed run) capture lower-tail reliability, P50 (the median) captures typical performance, and P90 captures the upper tail. Here Model A holds a P10 of 77.6%, while Model B drops to a P10 of 50.0% and a worst run of 20.0%.
In practice: choosing summary metrics for production readiness
- Mean and cluster-robust CI: Tracks overall expected performance across tasks.
- Lower percentiles (P5, P10) and worst-case runs: Catches catastrophic regressions and tail failures, just as systems teams track P95 and P99 latency rather than average latency alone. In binary task evaluations, also inspect the worst-performing task categories or slices, not only repeated full-benchmark runs.
- Spread (IQR or standard deviation): Measures run-to-run and slice-to-slice consistency.
- Sample size for tail percentiles: Lower percentiles require enough runs to stabilize. On 5 to 7 runs, P10 depends heavily on the single worst run, whereas 20 to 50 or more runs produce a more stable lower-tail estimate.
When comparing Model A and Model B head to head, run both models on the exact same set of tasks and score each item side by side. For every task, compute the item-level difference Model B - Model A: +1 when only Model B passes, -1 when only Model A passes, and 0 when both agree. Pairing on the same tasks cancels out shared task difficulty because both models face the same easy and hard items:
Because easy tasks tend to pass for both models and hard tasks tend to fail for both, the covariance term is positive and shrinks the variance of the difference.
McNemar's test is the standard starting point for paired binary outcomes. It ignores concordant ties (tasks where both models pass or both fail) and focuses only on the discordant pairs where the two models disagree: B-only) and A-only). Under the null hypothesis that both models are equal, those disagreements should split roughly 50/50. With Edwards's continuity correction, McNemar's test statistic is:
A large
Two concrete examples show how sensitive this test is to the number of disagreements. Suppose Model A wins 10 discordant tasks and Model B wins 5 (
Derivation: how McNemar's test comes from a fair coin flip
Condition on the
Beyond McNemar: paired tests for multi-run, continuous, and multi-model evals
-
Paired
$t$ -test and cluster-paired bootstrap (clustered or continuous scores): When each task has$m > 1$ runs or a continuous score, compute the per-task difference $d_q = \bar{y}{q,B} - \bar{y}{q,A}$ across all$M$ tasks and apply a paired$t$ -interval or resample tasks with replacement. - Wilcoxon signed-rank test (skewed continuous metrics): Nonparametric paired alternative for heavy-tailed metrics such as latency or token usage.
- Bradley-Terry and Elo ratings (multi-model arenas): Extends pairwise win/loss comparisons across three or more models without requiring every pair to share the same tasks.
-
Power analysis and minimum detectable effect (sample-size planning): Estimates how many paired tasks
$n$ are required before running an evaluation so a target gain (such as 3 to 5 pp) is reliably detectable. - Multiple testing correction (Holm-Bonferroni and Benjamini-Hochberg FDR): Controls false positives when comparing many prompts, scaffolds, or checkpoints at once.
For a side-by-side comparison with Anthropic's statistical evaluation paper (Miller, 2024), curated papers from top statistics and machine learning journals, and a roadmap of future topics, see FURTHER_READING.md.
MIT


















