# Is model A really better? Paired error bars and McNemar's test on one benchmark

A new model scores 15 points higher on a 40-question benchmark. Is that a real gain or luck of the draw? Edit the per-question results, then use McNemar's test and a paired confidence interval to see how much evidence the gap really holds.

<div data-sim="specx" data-spec="{&#34;head&#34;:&#34;Is model A really better? A paired test on one benchmark&#34;,&#34;sub&#34;:&#34;Each row is one question: 1 if the model answered it correctly. Change the confidence, the continuity correction or the benchmark size and see whether the gap survives.&#34;,&#34;params&#34;:[{&#34;id&#34;:&#34;z&#34;,&#34;label&#34;:&#34;z for the interval&#34;,&#34;min&#34;:0.5,&#34;max&#34;:3.5,&#34;step&#34;:0.01,&#34;value&#34;:1.96,&#34;note&#34;:&#34;1.96 gives a 95% interval, 2.58 gives 99%&#34;},{&#34;id&#34;:&#34;cc&#34;,&#34;label&#34;:&#34;Continuity correction&#34;,&#34;min&#34;:0,&#34;max&#34;:1,&#34;step&#34;:1,&#34;value&#34;:1,&#34;note&#34;:&#34;1 = Edwards correction on, 0 = off&#34;},{&#34;id&#34;:&#34;rep&#34;,&#34;label&#34;:&#34;Benchmark size multiplier&#34;,&#34;min&#34;:1,&#34;max&#34;:20,&#34;step&#34;:1,&#34;value&#34;:1,&#34;unit&#34;:&#34;×&#34;,&#34;note&#34;:&#34;What if there were this many times more questions with the same pattern&#34;}],&#34;data&#34;:{&#34;columns&#34;:[&#34;model_a&#34;,&#34;model_b&#34;],&#34;rows&#34;:[[1,1],[1,0],[1,1],[1,1],[0,1],[1,1],[1,0],[1,1],[1,1],[0,0],[1,1],[1,0],[1,1],[1,1],[1,0],[0,1],[1,1],[1,1],[1,0],[1,1],[0,0],[1,1],[1,0],[1,1],[0,1],[1,1],[1,0],[1,1],[0,0],[1,1],[1,0],[1,1],[1,1],[0,0],[1,0],[1,1],[0,0],[1,1],[1,1],[0,0]],&#34;note&#34;:&#34;40 questions scored 1 (correct) or 0 (wrong) for both models. Paste your own per-question scores from an eval run, one row per question.&#34;},&#34;row&#34;:[{&#34;id&#34;:&#34;d&#34;,&#34;label&#34;:&#34;A − B&#34;,&#34;expr&#34;:&#34;model_a - model_b&#34;,&#34;tex&#34;:&#34;d_i = a_i - b_i&#34;},{&#34;id&#34;:&#34;disc&#34;,&#34;label&#34;:&#34;models disagree&#34;,&#34;expr&#34;:&#34;abs(d)&#34;},{&#34;id&#34;:&#34;only_a&#34;,&#34;label&#34;:&#34;only A right&#34;,&#34;expr&#34;:&#34;model_a*(1 - model_b)&#34;},{&#34;id&#34;:&#34;only_b&#34;,&#34;label&#34;:&#34;only B right&#34;,&#34;expr&#34;:&#34;(1 - model_a)*model_b&#34;}],&#34;derived&#34;:[{&#34;id&#34;:&#34;nn&#34;,&#34;label&#34;:&#34;Questions counted&#34;,&#34;expr&#34;:&#34;n*rep&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;acc_a&#34;,&#34;label&#34;:&#34;Accuracy of A&#34;,&#34;expr&#34;:&#34;mean(model_a)&#34;,&#34;fmt&#34;:&#34;p&#34;},{&#34;id&#34;:&#34;acc_b&#34;,&#34;label&#34;:&#34;Accuracy of B&#34;,&#34;expr&#34;:&#34;mean(model_b)&#34;,&#34;fmt&#34;:&#34;p&#34;},{&#34;id&#34;:&#34;diff&#34;,&#34;label&#34;:&#34;Difference A − B&#34;,&#34;expr&#34;:&#34;acc_a - acc_b&#34;,&#34;fmt&#34;:&#34;p&#34;,&#34;tex&#34;:&#34;\\bar d = \\hat p_A - \\hat p_B&#34;},{&#34;id&#34;:&#34;nb&#34;,&#34;label&#34;:&#34;Only A right (b)&#34;,&#34;expr&#34;:&#34;sum(only_a)*rep&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;nc&#34;,&#34;label&#34;:&#34;Only B right (c)&#34;,&#34;expr&#34;:&#34;sum(only_b)*rep&#34;,&#34;fmt&#34;:&#34;i&#34;},{&#34;id&#34;:&#34;se_pair&#34;,&#34;label&#34;:&#34;Paired standard error&#34;,&#34;expr&#34;:&#34;sqrt((mean(disc) - diff^2)/nn)&#34;,&#34;tex&#34;:&#34;SE_{\\text{paired}} = \\sqrt{\\frac{\\frac{b+c}{n} - \\bar d^{\\,2}}{n}}&#34;},{&#34;id&#34;:&#34;se_unp&#34;,&#34;label&#34;:&#34;Unpaired standard error&#34;,&#34;expr&#34;:&#34;sqrt((acc_a*(1 - acc_a) + acc_b*(1 - acc_b))/nn)&#34;,&#34;tex&#34;:&#34;SE_{\\text{unpaired}} = \\sqrt{\\frac{\\hat p_A(1-\\hat p_A) + \\hat p_B(1-\\hat p_B)}{n}}&#34;},{&#34;id&#34;:&#34;ratio&#34;,&#34;label&#34;:&#34;Unpaired SE ÷ paired SE&#34;,&#34;expr&#34;:&#34;se_unp/se_pair&#34;,&#34;note&#34;:&#34;how much pairing tightens the interval&#34;},{&#34;id&#34;:&#34;lo&#34;,&#34;label&#34;:&#34;Interval low&#34;,&#34;expr&#34;:&#34;diff - z*se_pair&#34;,&#34;fmt&#34;:&#34;p&#34;,&#34;tex&#34;:&#34;\\bar d \\pm z\\cdot SE_{\\text{paired}}&#34;},{&#34;id&#34;:&#34;hi&#34;,&#34;label&#34;:&#34;Interval high&#34;,&#34;expr&#34;:&#34;diff + z*se_pair&#34;,&#34;fmt&#34;:&#34;p&#34;},{&#34;id&#34;:&#34;conf&#34;,&#34;label&#34;:&#34;Confidence level&#34;,&#34;expr&#34;:&#34;2*Phi(z) - 1&#34;,&#34;fmt&#34;:&#34;p&#34;},{&#34;id&#34;:&#34;chi2&#34;,&#34;label&#34;:&#34;McNemar statistic&#34;,&#34;expr&#34;:&#34;max(abs(nb - nc) - cc, 0)^2/(nb + nc)&#34;,&#34;tex&#34;:&#34;\\chi^2 = \\frac{(|b-c| - \\text{cc})^2}{b+c}&#34;},{&#34;id&#34;:&#34;pval&#34;,&#34;label&#34;:&#34;p-value&#34;,&#34;expr&#34;:&#34;2*(1 - Phi(sqrt(chi2)))&#34;,&#34;tex&#34;:&#34;p = P(\\chi^2_1 \\ge \\chi^2) = 2\\,(1-\\Phi(\\sqrt{\\chi^2}))&#34;}],&#34;chart&#34;:{&#34;title&#34;:&#34;Where the true accuracy gap probably lies&#34;,&#34;x&#34;:{&#34;var&#34;:&#34;t&#34;,&#34;label&#34;:&#34;Accuracy difference, A minus B&#34;,&#34;from&#34;:-0.3,&#34;to&#34;:0.6},&#34;series&#34;:[{&#34;label&#34;:&#34;Paired estimate&#34;,&#34;expr&#34;:&#34;phi((t - diff)/se_pair)/se_pair&#34;},{&#34;label&#34;:&#34;Same data treated as unpaired&#34;,&#34;expr&#34;:&#34;phi((t - diff)/se_unp)/se_unp&#34;,&#34;dash&#34;:true}],&#34;mark&#34;:&#34;diff&#34;},&#34;steps&#34;:[{&#34;title&#34;:&#34;Score both models on the same questions&#34;,&#34;text&#34;:&#34;A gets {acc_a:p} and B gets {acc_b:p} on {nn} questions: a gap of {diff:p}.&#34;,&#34;show&#34;:[&#34;acc_a&#34;,&#34;acc_b&#34;,&#34;diff&#34;]},{&#34;title&#34;:&#34;Keep only the disagreements&#34;,&#34;text&#34;:&#34;Questions both models got right or both got wrong say nothing about which is better. A alone was right on {nb}, B alone on {nc}.&#34;,&#34;show&#34;:[&#34;nb&#34;,&#34;nc&#34;]},{&#34;title&#34;:&#34;McNemar&#39;s test&#34;,&#34;text&#34;:&#34;If the models were equally good, a disagreement would go either way like a coin flip. The statistic is {chi2} on 1 degree of freedom, giving p = {pval}.&#34;,&#34;show&#34;:[&#34;chi2&#34;,&#34;pval&#34;]},{&#34;title&#34;:&#34;Put an error bar on the gap&#34;,&#34;text&#34;:&#34;The paired standard error is {se_pair}, so the {conf:p} interval runs from {lo:p} to {hi:p}. If it contains 0 the benchmark cannot separate the models.&#34;,&#34;show&#34;:[&#34;se_pair&#34;,&#34;lo&#34;,&#34;hi&#34;]},{&#34;title&#34;:&#34;See what pairing buys&#34;,&#34;text&#34;:&#34;Ignoring the pairing gives a standard error of {se_unp}, {ratio} times wider, because shared easy and hard questions cancel out in the paired difference.&#34;,&#34;show&#34;:[&#34;se_unp&#34;,&#34;ratio&#34;]}]}"><p>Interactive simulation. It needs JavaScript; the text below explains what it shows.</p></div>

Model releases are often compared by a single number per benchmark: 77.5% against 62.5%, say. But a benchmark is a sample of questions. With a different sample of the same kind, the gap could shrink, grow or flip. This simulation shows how to measure that uncertainty when two models answer the same questions.

## What you are looking at

Each row of the table is one question, with 1 if the model got it right and 0 if not, for model A and model B. The orange columns mark the difference for that question and whether the models disagreed, and if so which one was right.

The results panel gives each model's accuracy, the gap between them, the counts of questions only A or only B answered correctly, McNemar's statistic and its p-value, and a confidence interval for the gap. The chart draws two bell curves for where the true gap probably lies: the solid one uses the pairing, the dashed one ignores it. The vertical line marks the observed gap.

## The algorithm

Because both models answered the same questions, the right unit is the question, not the model. Split the questions into four groups: both right, both wrong, only A right (call that count b) and only B right (count c). The first two groups carry no information about which model is better: they are easy or hard for both. All the evidence sits in the disagreements.

1. Score both models on every question and compute the gap in accuracy.
2. Count the disagreements b and c.
3. McNemar's test: if the models were equally good, each disagreement would favour A or B with equal chance, like a coin flip. The statistic (|b − c| − 1)² / (b + c) follows a chi-squared distribution with one degree of freedom. The "− 1" is Edwards' continuity correction for small counts; set the correction slider to 0 to remove it.
4. Turn the statistic into a p-value: the chance of a split at least this uneven if the models were really equal.
5. Put an error bar on the gap. The per-question difference d is 1, 0 or −1. Its mean is the accuracy gap, and its standard error is the square root of (share of disagreements − gap²) divided by the number of questions. The interval is the gap plus or minus z standard errors.

With the example data, A scores 77.5% and B 62.5%, a gap of 15 points. A alone was right on 9 questions and B alone on 3. McNemar's statistic is 2.08 with p = 0.149, and the 95% interval runs from −1.3 to 31.3 points. It contains zero, so 40 questions cannot tell these models apart. These numbers match the statsmodels implementation of McNemar's test and a direct NumPy calculation.

## Things to try

- Set the benchmark size multiplier to 4: the same pattern on 160 questions gives p = 0.0009 and an interval of 6.8 to 23.2 points. More questions, not a bigger gap, made the result clear.
- Turn the continuity correction off. The statistic rises from 2.08 to 3.00 and the p-value falls from 0.149 to 0.083: on small counts the correction matters.
- Compare the solid and dashed curves. Ignoring the pairing makes the standard error about 1.2 times larger here, because questions both models find easy or hard add noise to each score but cancel in the difference.
- Change a few rows where both models were right into rows where only A was right. The accuracy gap and the evidence both grow.
- Make b and c equal while keeping both accuracies high. The p-value goes to 1: identical totals mean no evidence either way.
- Paste per-question results from your own eval run, two columns of 0s and 1s, and download the table with the computed columns.

## How it works in real systems

Evan Miller's paper "Adding Error Bars to Evals" asks for language model evaluations to report their statistical uncertainty, and gives formulas for analysing eval data and measuring differences between two models. The paired analysis shown here is one of those tools: when two models answer the same questions, the difference per question has lower variance than either score on its own.

In practice, several details change the picture. Many benchmarks group questions that share a passage or a source document, and those questions are not independent, so standard errors should be clustered by group. When a model is sampled at a temperature above zero, its score on each question is itself noisy, and averaging several samples per question reduces that noise. When many models or many benchmarks are compared at once, some differences will look significant by chance alone.

For very small numbers of disagreements, use the exact binomial version of McNemar's test, which statsmodels offers through its exact option. For the example data the exact p-value is 0.146, close to the corrected chi-squared value. For rankings built from human votes rather than fixed questions, see the [arena ratings simulation](/ai-simulations/arena-bradley-terry-ratings); for threshold metrics such as precision and recall, see [precision and recall against the threshold](/ai-simulations/precision-recall-threshold).

## Sources

- [Miller (2024): Adding Error Bars to Evals, a statistical approach to language model evaluations](https://arxiv.org/abs/2411.00640)
- [statsmodels: mcnemar](https://www.statsmodels.org/stable/generated/statsmodels.stats.contingency_tables.mcnemar.html)
- [Wikipedia: McNemar's test](https://en.wikipedia.org/wiki/McNemar%27s_test)
