Skip to content

About

Statistical rigor, uncertainty quantification, and measurement methodology for LLM, agent, and AI evaluations.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

Repository files navigation

Statistical Evaluation of AI Systems

Statistical methods for evaluating LLMs, agents, and generative AI systems from first principles.

Contents

  1. Motivation
  2. The Binomial Model
  3. Point Estimates
  4. Sampling Uncertainty
  5. Standard Errors and Confidence Intervals
  6. Coverage and the Wilson Interval
  7. Clustered Data and Effective Sample Size
  8. Missing Data and Survivorship Bias
  9. Beyond the Mean: Distributions and Percentiles
  10. Paired Comparisons and McNemar's Test

Motivation

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 $p$ across the tasks we care about ($p_A$ for Model A and $p_B$ for Model B). Running a benchmark produces one finite-sample estimate $\hat{p}$ of that unknown rate, and rerunning the benchmark produces a different estimate.

Unknown true pass rate vs. observed evaluation estimate

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.

The Binomial Model

Consider running Model A on $n = 10$ independent pass/fail tasks and observing 7 passes (1) and 3 failures (0). Each task is a binary outcome (a Bernoulli trial) with an unknown probability $p$ that Model A passes a single task (the estimand).

When the tasks are independent and share the same pass probability $p$, the total number of passes $X$ follows a binomial distribution:

$$X \sim \mathrm{Binomial}(n = 10, p)$$

Binomial model of binary evaluation trials

Point Estimates

We never observe the true probability $p$ directly. We only observe the fraction of tasks that passed in a run (a point estimate, denoted $\hat{p}$):

$$\hat{p} = \frac{\text{successes}}{\text{trials}} = \frac{X}{n}$$

Model A's 78% and Model B's 84% are both point estimates. A bare percentage hides the sample size $n$. Observing 7 out of 10, 70 out of 100, and 7,000 out of 10,000 all yield $\hat{p} = 70%$, even though they carry very different amounts of evidence. As $n$ grows, $\hat{p}$ converges to the true $p$ (the law of large numbers).

Point estimates across sample sizes

Sampling Uncertainty

Because $\hat{p}$ comes from a finite sample, it differs from the unknown $p$ on any given run (sampling error). Rerunning the exact same model therefore produces different point estimates across runs (sampling variability, or sampling uncertainty).

Suppose we run Model A three times on $n = 50$ cases and observe 41/50 (82%), 38/50 (76%), and 43/50 (86%). Model A did not get worse on run 2 and improve on run 3. All three numbers estimate the same underlying pass rate $p$.

Sampling variability across three evaluation runs

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).

Task-level outcomes flipping across two evaluation runs

The size of the evaluation determines how much a single task changes the score. On $n = 10$ tasks, moving from 8/10 (80%) to 9/10 (90%) is a 10 percentage point change. On $n = 1{,}000$ tasks, moving from 800/1,000 (80.0%) to 801/1,000 (80.1%) is a 0.1 percentage point change. Each task carries weight $1/n$ in the average (its single-observation influence).

Effect of flipping one task at n = 10 vs. n = 1,000

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?

Standard Errors and Confidence Intervals

To quantify sampling uncertainty, statisticians use standard errors and confidence intervals.

Return to Model A from run 1 above: 41 passes out of $n = 50$ tasks gives $\hat{p} = 41/50 = 82%$. For $n$ independent Bernoulli trials, the estimated standard error of $\hat{p}$ is:

$$\widehat{\mathrm{SE}}(\hat{p}) = \sqrt{\frac{\hat{p}(1 - \hat{p})}{n}} = \sqrt{\frac{0.82 \times 0.18}{50}} \approx 0.054$$

That is 5.4 percentage points. Because $n$ sits inside the square root, the standard error shrinks at rate $1/\sqrt{n}$. Increasing $n$ by 100x cuts the standard error by 10x. Cutting uncertainty in half requires 4x as many tasks.

Derivation: where the standard error formula comes from

Each binary task has variance $p(1 - p)$. Adding $n$ independent trials multiplies the variance by $n$, and dividing by $n$ to form the average divides the variance by $n^2$. Taking the square root gives the standard error.

First-principles derivation of the binomial standard error

Research papers usually report a confidence interval rather than a standard error alone. A confidence interval gives a plausible range around $\hat{p}$ that captures its sampling uncertainty. The simplest starting point is the 95% Wald interval:

$$\hat{p} \pm 1.96 , \widehat{\mathrm{SE}}(\hat{p})$$

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 $p$ is fixed, and the interval shifts with each new evaluation run. Across many repeated evaluations under the same setup, 95% of these intervals cover $p$ and 5% miss it.

Wald 95% confidence interval calculation and repeated-run coverage

Aside: from standard error to a 95% confidence interval (test inversion)

Under the central limit theorem, inverting the two-sided test at $\alpha = 0.05$ produces the 95% Wald interval.

Central limit theorem and test inversion for the 95% Wald interval

Returning to Model A (78%) vs. Model B (84%) makes the impact of sample size immediate. At $n = 50$, the 95% intervals are 78.0% ± 11.5% for Model A and 84.0% ± 10.2% for Model B, which overlap heavily. At $n = 1{,}000$, the intervals narrow to 78.0% ± 2.6% and 84.0% ± 2.3%, separating the two models cleanly.

95% confidence intervals for 78% vs. 84% at n = 50 and n = 1,000

Coverage and the Wilson Interval

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 $n$ is small or when $\hat{p}$ is close to 0% or 100%. Consider running the same model and prompt across $n = 20$ repeated trials (each trial is one fresh rollout on that fixed prompt, distinct from running once across $n$ different questions). At 19/20 passes (95%), the Wald interval reaches 104.6%, outside the valid probability range. At 20/20 passes (100%), the estimated standard error becomes zero and the Wald interval collapses to [100%, 100%].

Comparison of Wald and Wilson 95% confidence intervals near 100%

The Wilson score interval fixes both failures by inverting the binomial test without plugging $\hat{p}$ into the denominator first. For a 95% interval ($z = 1.96$), it pulls the center slightly toward 50% (similar to adding about 2 passes and 2 failures), adds a small $z^2 / (4n^2)$ floor so width never collapses to zero, and keeps both endpoints strictly inside [0%, 100%].

Intuition and anatomy of the Wilson 95% confidence interval

Q&A: What if we observe 0 failures in our eval? (The Rule of Three)

Observing 0 failures in $n$ independent trials does not prove the true failure rate $f$ is zero. Asking what failure rate $f$ still has a 5% chance of producing 0 failures gives a quick one-sided 95% upper bound of $3 / n$ (the rule of three). For 0 failures in 200 trials, the true failure rate can still be as high as 1.5%.

Rule of three derivation and zero-failure probability curve for 200 trials

Clustered Data and Effective Sample Size

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:

$$\mathrm{DEFF} = 1 + (m - 1)\rho, \qquad n_{\mathrm{eff}} = \frac{\text{total rows}}{\mathrm{DEFF}}$$

Here $m$ is the number of runs per question and $\rho$ is the correlation between runs on the same question (the intraclass correlation coefficient, or ICC). At $m = 10$ and $\rho = 0.2$, the design effect is 2.8, so 1,000 rows carry the statistical weight of only 357 independent observations.

Clustered evaluation runs and effective sample size

When every question gets the same number of runs ($m = 10$), the overall pass rate $\hat{p}$ remains an unbiased estimate of the true pass rate $p$. Treating all 1,000 rows as independent does not bias $\hat{p}$, but it understates the standard error and causes severe undercoverage.

To measure that breakdown across realistic agentic regimes, we run a 5,000-trial Monte Carlo simulation of 100 tasks $\times$ 10 runs for a baseline model with a true pass rate of 78% (matching Model A). Across every correlation level, the mean $\hat{p}$ stays at 78.0%. Naive 1,000-row 95% confidence intervals hold at 94.7% coverage when runs are independent ($\rho = 0.0$), then drop to 75.7% for noisy rollouts ($\rho = 0.2$), 59.5% for tool-use agents ($\rho = 0.5$), and 51.3% for deterministic coding agents ($\rho = 0.8$). Cluster-robust 95% confidence intervals stay near the 95% target across all four regimes (95.0%, 94.8%, 94.5%, and 94.2%).

Monte Carlo simulation of naive versus cluster-robust 95% confidence interval coverage

Reproduce the simulation (Python and results table)
Regime $\rho$ DEFF $n_{\mathrm{eff}}$ Mean $\hat{p}$ 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% $\pm 2.56$ pp vs. $\pm 2.59$ pp
Noisy rollouts 0.2 2.8 357 78.01% 75.7% 94.8% $\pm 2.56$ pp vs. $\pm 4.34$ pp
Tool-use agents 0.5 5.5 182 78.03% 59.5% 94.5% $\pm 2.56$ pp vs. $\pm 6.07$ pp
Coding agents 0.8 8.2 122 77.94% 51.3% 94.2% $\pm 2.55$ pp vs. $\pm 7.43$ pp

Run the standalone NumPy script locally (view source):

python3 simulations/clustered_coverage.py
In practice: computing clustered standard errors without guessing correlation

You do not need to guess $\rho$ to compute a valid standard error on clustered evaluation runs. Average the $m$ binary outcomes inside each question $q = 1, \dots, M$ to get one score $\bar{y}_q \in [0, 1]$ per question, then compute the standard error across those $M$ independent question means:

$$\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 $m$ runs of each sampled question together) rather than resampling individual rows. Adding more runs per question ($m$) shrinks within-question rollout noise, but only adding more distinct questions ($M$) shrinks between-question difficulty variance.

Missing Data and Survivorship Bias

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.

Missing data, survivorship bias, and retry inflation in evaluation denominators

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
  1. 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.
  2. 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.
  3. 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%.
  4. 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.
  5. 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.

Beyond the Mean: Distributions and Percentiles

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%.

Model A vs. Model B score distributions, worst-run tail risk, and percentiles

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.

Paired Comparisons and McNemar's Test

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:

$$\mathrm{Var}(\hat{p}_B - \hat{p}_A) = \mathrm{Var}(\hat{p}_B) + \mathrm{Var}(\hat{p}_A) - 2,\mathrm{Cov}(\hat{p}_A, \hat{p}_B)$$

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$ tasks where only Model B passes (B-only) and $c$ tasks where only Model A passes (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:

$$\chi^2 = \frac{(|b - c| - 1)^2}{b + c}$$

A large $\chi^2$ produces a low $p$-value (below 0.05), which means the split is too lopsided to be due to chance. A small $\chi^2$ produces a high $p$-value, which means the split is compatible with chance.

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 ($k = 15$). Even though 10 vs. 5 looks 2-to-1, McNemar's test gives $\chi^2 = 1.07$ and $p = 0.302$ (exact two-sided binomial $p = 0.302$), so that split can easily happen by chance. Now return to our opening comparison of Model A (78%) vs. Model B (84%) on $n = 200$ paired tasks: suppose both models pass 152, both fail 28, Model B alone passes 16 ($b = 16$), and Model A alone passes 4 ($c = 4$). An unpaired two-sample test ignores the pairing and yields $p = 0.125$ (inconclusive). McNemar's test yields $\chi^2 = 6.05$ and $p = 0.014$ (exact binomial $p = 0.012$), separating the two models cleanly.

Item-by-item paired comparison and McNemar's test on discordant pairs

Derivation: how McNemar's test comes from a fair coin flip

Condition on the $k = b + c$ tasks where Model A and Model B disagree. If the two models have the same true pass rate, each disagreement is an independent fair coin flip with probability $1/2$ of going to Model B, so standardizing $b \sim \mathrm{Binomial}(k, 0.5)$ and squaring gives $\chi^2_1$.

First-principles derivation of McNemar's test from a fair coin flip

Beyond McNemar: paired tests for multi-run, continuous, and multi-model evals
  1. 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.
  2. Wilcoxon signed-rank test (skewed continuous metrics): Nonparametric paired alternative for heavy-tailed metrics such as latency or token usage.
  3. 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.
  4. 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.
  5. Multiple testing correction (Holm-Bonferroni and Benjamini-Hochberg FDR): Controls false positives when comparing many prompts, scaffolds, or checkpoints at once.

Further Reading

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.

License

MIT

About

Statistical rigor, uncertainty quantification, and measurement methodology for LLM, agent, and AI evaluations.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages