
Statistical Significance in LLM Evals
Learn how to apply statistical significance, confidence intervals, and bootstrap methods to validate LLM evaluation results with proper sample sizes.
When you run an evaluation on a Large Language Model (LLM), you are not measuring a fixed property of the model. You are sampling from a probability distribution. The output of an LLM is influenced by temperature, top-p, and inherent randomness in the token generation process. Consequently, two runs of the same model on the same dataset will rarely yield identical scores. This variance is not a bug; it is a feature of the architecture.
Treating a single evaluation run as ground truth is a fundamental error. If Model A scores 85% accuracy and Model B scores 86% on a 50-prompt test set, you cannot conclude Model B is better. The difference might be within the noise floor of the evaluation harness. To distinguish signal from noise, you must apply statistical significance testing. This shifts evaluation from "what happened" to "what is likely true about the population."
The Variance Problem in Generative Metrics
In traditional software engineering, a unit test is deterministic. assert add(2, 2) == 4. In LLM evaluation, metrics like accuracy, BLEU, or human preference scores are random variables. While fixing the random seed makes generation deterministic for a specific run, variance still arises from non-deterministic system factors such as concurrency, hardware scheduling, or floating-point non-associativity in large context windows. This introduces variance in how different models interpret ambiguous instructions across different runs or environments.
The core challenge is that the metric of interest (e.g., binary accuracy) is a Bernoulli trial. If you evaluate prompts, the total score follows a Binomial distribution , where is the true accuracy. As grows, the distribution of the sample mean approaches a Normal distribution due to the Central Limit Theorem (CLT). However, for small or extreme values (near 0 or 1), the normal approximation fails.
This means that a reported score of 90% is actually a point estimate with an associated error margin. Ignoring this margin leads to false positives: adopting a model that appears better but is statistically indistinguishable from the baseline.
Confidence Intervals: Quantifying Uncertainty
The first step in rigorous evaluation is calculating the confidence interval (CI). A 95% CI does not mean there is a 95% probability that the true mean lies within the interval. Rather, it means that if you repeated the experiment infinite times, 95% of the calculated intervals would contain the true population mean.
For a simple accuracy metric, you can estimate the standard error (SE) using:
The 95% CI is then approximately .
Consider two models evaluated on prompts.
- Model A: 85/100 correct (). . CI: .
- Model B: 88/100 correct (). . CI: .
The intervals overlap significantly. While Model B has a higher point estimate, the data is consistent with Model A being equal to or even slightly better than Model B. You cannot reject the null hypothesis that the models are equal based on this data alone.
To reduce the width of the CI, you must increase . Because the margin of error scales with , doubling the sample size only reduces the error by ~30%. This is why small evals (n<50) are dangerously misleading. For robust LLM evals, aim for for each model, depending on the expected effect size.
Hypothesis Testing: Paired Comparisons
When comparing two models, you should not treat them as independent samples. The same prompt tests both models. This pairing reduces variance because the difficulty of the prompt is a constant factor. Using an independent t-test or Z-test ignores this correlation, which inflates the variance of the difference estimator by failing to account for the positive correlation between paired observations. This increases the standard error, making it harder to detect real differences.
Instead, use McNemar’s Test for binary outcomes (correct/incorrect) or a Paired t-test for continuous scores (like LLM-as-a-judge scores).
McNemar’s Test Mechanism
McNemar’s test focuses on the discordant pairs: cases where Model A is correct and Model B is wrong, and vice versa. Let be the count where A is correct and B is wrong, and be the count where A is wrong and B is correct. The test statistic is:
This follows a Chi-squared distribution with 1 degree of freedom. If and are small, use the exact binomial version.
Example Scenario: You evaluate 100 prompts.
- Both correct: 80
- Both wrong: 5
- A correct, B wrong (): 10
- A wrong, B correct (): 5
Here, . The test statistic is . The critical value for is 3.84. Since $1.67 < 3.84$, we fail to reject the null hypothesis. Despite Model A having more correct answers overall (90 vs 85), the difference is not statistically significant because the discordant pairs are too few to rule out chance.
Bootstrap Resampling for Complex Metrics
Not all metrics are binary. LLM-as-a-judge scores, latency, or token counts often have skewed distributions. The normal approximation may not hold. In these cases, bootstrap resampling is the most robust method.
Bootstrap works by empirically estimating the sampling distribution of your metric.
Algorithm:
- Start with your original dataset of results (e.g., scores for Model A and Model B).
- Resample the dataset with replacement to create a new dataset of size .
- Calculate the metric of interest (e.g., mean difference in scores) for this bootstrap sample.
- Repeat steps 2-3 thousands of times (e.g., 10,000 iterations).
- The distribution of these 10,000 differences approximates the true sampling distribution.
- The 2.5th and 97.5th percentiles of this distribution form the 95% CI for the difference.
If the 95% CI for the difference between Model A and Model B does not include zero, you have statistical significance.
Code Example (Python/Pandas):
import numpy as np
import pandas as pd
def bootstrap_ci(scores_a, scores_b, n_bootstrap=10000, alpha=0.05):
diff_means = []
for _ in range(n_bootstrap):
# Resample with replacement
sample_a = np.random.choice(scores_a, size=len(scores_a), replace=True)
sample_b = np.random.choice(scores_b, size=len(scores_b), replace=True)
# Calculate difference in means
diff_means.append(np.mean(sample_a) - np.mean(sample_b))
# Calculate CI
lower = np.percentile(diff_means, 100 * alpha / 2)
upper = np.percentile(diff_means, 100 * (1 - alpha / 2))
return lower, upper
# Example usage
scores_a = [0.8, 0.9, 0.7, 0.85, ...] # List of judge scores
scores_b = [0.82, 0.88, 0.75, 0.84, ...]
ci_lower, ci_upper = bootstrap_ci(scores_a, scores_b)
print(f"95% CI for difference: [{ci_lower}, {ci_upper}]")Sample Size Planning
Determining the required sample size beforehand prevents underpowered studies. The key parameter is the Effect Size. How large a difference do you care about detecting? If Model A is 80% and Model B is 80.1%, the difference is statistically detectable with a huge sample, but practically irrelevant.
Use power analysis to determine . For a two-proportion z-test, the formula involves:
- (significance level, usually 0.05)
- (power, usually 0.80, so )
- (expected proportions)
If you expect a small effect size (e.g., 2% improvement), will be large (hundreds or thousands). If you expect a large effect size (e.g., 10%), can be smaller. Always plan your evals with the minimum detectable effect in mind.
Conclusion
Statistical significance is not optional in LLM evaluation. It is the mechanism that separates signal from the inherent stochasticity of generative models. By using confidence intervals to quantify uncertainty, paired tests to leverage correlated data, and bootstrap methods for complex metrics, you ensure that your model selection decisions are defensible. Never report a point estimate without its error margin. If the intervals overlap, the models are effectively tied. If they don’t, you have evidence of improvement.
Related posts
Ragas, DeepEval, and TruLens Compared
A comparison of Ragas, DeepEval, and TruLens for RAG evaluation, helping ML engineers choose the right metric framework.
Why Your Eval Suite Is Lying to You
Discover why LLM evaluation suites often produce misleading results due to variance and insufficient sample sizes, and learn how to build more reliable benchmarks.
Evaluating a Fine-Tune Against the Base Model
A practical guide for ML engineers on fine-tune evaluation, using held-out sets and regression testing to compare performance against the base model.