# 麦克尼马尔检验

**麦克尼马尔检验**（McNemar's test）是一种用于配对二值数据的非参数统计检验，仅利用两次测量结果不一致的配对，评估两个相关测量的边际比例是否存在差异。斯坦福大学统计学家奎因·麦克尼马尔（Quinn McNemar）于1947年在《心理测量学》（*Psychometrika*）上发表的一篇关于相关比例之差抽样误差的论文中提出了该检验。<sup>[1](https://www.cambridge.org/core/journals/psychometrika/article/note-on-the-sampling-error-of-the-difference-between-correlated-proportions-or-percentages/698C2461BE63F5848763502D54E534FD)</sup>典型应用包括对同一批患者进行的前后测量、对同一个体实施的两种诊断检验，以及匹配的病例对照研究。<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>

| 关键事实 | 详情 |
|---|---|
| 用途 | 检验配对二值数据中的边际同质性（两个边际比例相等）<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup> |
| 检验统计量 | \( \chi^2 = (b - c)^2 / (b + c) \)，其中 b 和 c 为两个不一致格的计数；自由度为1<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup> |
| 连续性校正形式 | \( (\lvert b - c \rvert - 1)^2 / (b + c) \)<sup>[3](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/mcnemar.htm)</sup> |
| 起源 | 奎因·麦克尼马尔，斯坦福大学，《心理测量学》12(2): 153–157，1947年6月<sup>[1](https://www.cambridge.org/core/journals/psychometrika/article/note-on-the-sampling-error-of-the-difference-between-correlated-proportions-or-percentages/698C2461BE63F5848763502D54E534FD)</sup> |
| 小样本表现 | 当 b + c 较小（约低于25）时，即使总样本量很大，检验功效也很低<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup> |
| 推荐版本 | 在2013年对五个版本的评估中，渐近检验和mid-p检验表现最佳；精确条件检验和连续性校正渐近检验不被推荐<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC3716987/)</sup> |
| 机器学习中的应用 | Dietterich（1998）表明，麦克尼马尔检验在单一测试集上比较两个分类器时第一类错误率较低<sup>[5](https://sci2s.ugr.es/keel/pdf/algorithm/articulo/dietterich1998.pdf)</sup> |

## 检验原理

配对二值数据被排列在一个2×2列联表中，每个格子记录一种结局组合的配对数量。对角线格子 a 和 d 为一致对，即两次测量结果相同（均为阳性或均为阴性）。非对角线格子 b 和 c 为不一致对，即一次测量为阳性而另一次为阴性。<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>

原假设是两个不一致方向出现的频率相等，\( H_0: P_b = P_c \)，这等价于两个测量的边际比例相等。<sup>[3](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/mcnemar.htm)</sup>只有不一致对携带关于差异的信息：一致对影响边际比例之差的估计大小，但不影响是否存在非零差异。<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>经典检验统计量为

\[ \chi^2 = \frac{(b - c)^2}{b + c} \]

参照自由度为1的卡方分布。<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>该统计量本质上是对不一致对施加的符号检验，也是Cochran检验在两条件下的特例。<sup>[3](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/mcnemar.htm)</sup>

## 假设与数据结构

该检验要求配对观测，每个受试者或匹配对恰好贡献两个二值测量，且各对之间相互独立。<sup>[3](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/mcnemar.htm)</sup><sup> • </sup><sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>它不同于独立性卡方检验和Fisher精确检验，后两者分析的是独立组；将那些检验应用于配对数据会忽略对内关系，可能给出不恰当的显著性估计。<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>

该检验评估的是边际同质性，而非一致性。两位评定者可以产生相似的阳性分类总体比例，而在个别案例上存在分歧；测量一致性需要诸如Cohen's kappa等统计量。<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>

## 检验的版本

存在四种主要版本：经典渐近检验、连续性校正渐近检验、精确条件检验和mid-p检验。<sup>[6](https://link.springer.com/article/10.1007/s00265-020-02916-y)</sup>

**连续性校正。** Edwards校正将统计量替换为 \( (\lvert b - c \rvert - 1)^2 / (b + c) \)，以近似精确二项p值。<sup>[3](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/mcnemar.htm)</sup><sup> • </sup><sup>[7](https://pmc.ncbi.nlm.nih.gov/articles/PMC4966396/)</sup>

**精确条件检验。** 以不一致对总数为条件，在原假设下一个不一致格的计数服从概率为1/2的二项分布，因此精确检验归结为对不一致计数的二项检验。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC3716987/)</sup><sup> • </sup><sup>[8](https://oncology.wisc.edu/mstat/help/help/Notes-06.html)</sup>

**mid-p检验。** mid-p方法由Lancaster于1961年提出，作为离散检验统计量精确p值的一种修正，将观测结果在尾部求和中的点概率减半。<sup>[9](https://www.sciencedirect.com/science/article/pii/S0378375803002623)</sup>应用于麦克尼马尔检验时，它降低了精确条件检验的保守性，但其第一类错误率不保证维持在规定水平或以下。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC3716987/)</sup>

## 应选用哪个版本

传统建议是在大样本中使用渐近检验，当 b + c < 25时使用精确检验或连续性校正。<sup>[6](https://link.springer.com/article/10.1007/s00265-020-02916-y)</sup>大规模模拟研究——主要是Fagerland、Lydersen和Laake（2013）——对这一建议提出了挑战。在评估的9595种情形中，精确条件检验严重保守：即使有100个匹配对，其第一类错误率也仅略高于3%，且常常只有名义5%水平的一半或更低。带连续性校正的渐近检验表现类似或更差。作者不建议在任何情况下使用这两种检验。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC3716987/)</sup>

未校正的渐近检验即使在小样本量下也表现良好。它在所考虑情形中有29%违反了名义5%水平，但幅度从未很大：观测到的最大第一类错误率为5.37%。小样本（10至30对）的违反率为3.7%，大样本（65至100对）为52%。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC3716987/)</sup>mid-p检验在9595种情形中均未超过名义水平，尽管不存在水平保持的解析保证，且其功效几乎与渐近检验相当。作者推荐将mid-p检验作为计算复杂的精确无条件检验的一种易于计算的替代方案，并在可以接受对名义水平的小幅频繁违反时使用渐近检验。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC3716987/)</sup>2014年对24种配对二项比例方法的综述同样将渐近麦克尼马尔检验和麦克尼马尔mid-p检验列为最佳的关联性检验。<sup>[10](https://onlinelibrary.wiley.com/doi/10.1002/sim.6148)</sup>

## 功效与样本量

统计功效取决于不一致对的数量，而非总样本量。当 b + c 较小（约低于25）时，即使受试者总数很大，功效也很低，因为一致对不提供关于差异的信息。<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>人们已基于检验的功效函数推导出样本量表达式，尤其针对匹配病例对照研究，其中有若干无条件变体在备择假设下方差的表达方式上有所不同。<sup>[11](https://onlinelibrary.wiley.com/doi/pdf/10.1002/sim.4780110909)</sup>

## 应用

**临床与诊断研究。** 该检验比较配对二值结局，如同一批患者的前后反应，或对同一个体实施的两种诊断检验的结果。显著结果提示边际比例存在差异；这是否反映诊断性能改善或治疗效果，取决于不一致对的方向和临床背景。<sup>[2](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)</sup>

**机器学习。** Dietterich 1998年关于比较监督分类算法的统计检验的综述发现，麦克尼马尔检验的第一类错误率较低，不同于重采样配对t检验，并且它仍然是单一测试集上比较两个分类器的标准选择，作用于一个分类器正确而另一个分类器错误的样本计数。<sup>[5](https://sci2s.ugr.es/keel/pdf/algorithm/articulo/dietterich1998.pdf)</sup>

**扩展。** 对于具有两个以上类别的配对分类数据，该检验推广为方表 r × r 上的Bowker对称性检验和Stuart-Maxwell边际同质性检验。<sup>[12](https://master-statistics.com/hypothesis-testing/mcnemars-test/)</sup>对于同一受试者上的两个以上重复条件，适用Cochran's Q检验，2×2麦克尼马尔检验是其特例。<sup>[3](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/mcnemar.htm)</sup>当同一个体贡献不止一个配对时，如在牙科或眼科研究中，独立性假设不成立；Durkalski及其同事（2003）针对此类聚类匹配对数据提出了方差调整版本的检验。<sup>[13](https://doi.org/10.1002/SIM.1438)</sup>扩展还涵盖误分类的配对结局，其中验证数据被用于估计比例的真实差异和配对优势比。<sup>[14](https://pubmed.ncbi.nlm.nih.gov/15737105/)</sup>

## 软件

R的`mcnemar.test()`对二维列联表的行和列对称性执行卡方检验，在2×2情形下默认应用连续性校正（`correct = TRUE`）。<sup>[15](https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/mcnemar.test)</sup>精确二项版本可通过`exact2x2`（`mcnemar.exact`）等包获得，或直接使用`binom.test(b, b + c, p = 0.5)`。<sup>[16](https://doi.org/10.32614/RJ-2010-008)</sup>SPSS在相关样本的非参数检验下提供麦克尼马尔检验，Stata提供`mcc`和`mcci`命令。<sup>[17](https://casrai.org/guides/mcnemars-test-paired-categorical-data)</sup>mid-p检验可在包括Excel、SAS、SPSS和Stata在内的标准软件包中计算。<sup>[4](https://pmc.ncbi.nlm.nih.gov/articles/PMC3716987/)</sup>

## References

1. [Quinn McNemar (1947). Note on the Sampling Error of the Difference Between Correlated Proportions or Percentages. Psychometrika 12(2): 153–157.](https://www.cambridge.org/core/journals/psychometrika/article/note-on-the-sampling-error-of-the-difference-between-correlated-proportions-or-percentages/698C2461BE63F5848763502D54E534FD)
2. [Collins AC, Sutton AE. McNemar and Mann-Whitney U Tests. StatPearls, NCBI Bookshelf.](https://www.ncbi.nlm.nih.gov/sites/books/NBK560699/)
3. [McNemar Test, NIST/SEMATECH e-Handbook of Statistical Methods (Dataplot reference manual).](https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/mcnemar.htm)
4. [Fagerland MW, Lydersen S, Laake P (2013). The McNemar test for binary matched-pairs data: mid-p and asymptotic are better than exact conditional. BMC Medical Research Methodology 13:91.](https://pmc.ncbi.nlm.nih.gov/articles/PMC3716987/)
5. [Dietterich TG (1998). Approximate Statistical Tests for Comparing Supervised Classification Learning Algorithms. Neural Computation 10: 1895–1923.](https://sci2s.ugr.es/keel/pdf/algorithm/articulo/dietterich1998.pdf)
6. [Effective use of the McNemar test. Behavioral Ecology and Sociobiology (2020).](https://link.springer.com/article/10.1007/s00265-020-02916-y)
7. [Hazra A, Gogtay N (2016). Biostatistics Series Module 4: Comparing Groups – Categorical Variables. Indian Journal of Dermatology.](https://pmc.ncbi.nlm.nih.gov/articles/PMC4966396/)
8. [Notes, Chapter 6: McNemar's test for analysis of paired data, University of Wisconsin-Madison MSTAT program.](https://oncology.wisc.edu/mstat/help/help/Notes-06.html)
9. [The equivalence of the mid p-value and the expected p-value for testing equality of two balanced Binomial proportions. Computational Statistics & Data Analysis.](https://www.sciencedirect.com/science/article/pii/S0378375803002623)
10. [Fagerland MW, Lydersen S, Laake P (2014). Recommended tests and confidence intervals for paired binomial proportions. Statistics in Medicine.](https://onlinelibrary.wiley.com/doi/10.1002/sim.6148)
11. [Lachin JM (1992). Power and sample size evaluation for the McNemar test with application to matched case-control studies. Statistics in Medicine 11: 1239–1250.](https://onlinelibrary.wiley.com/doi/pdf/10.1002/sim.4780110909)
12. [McNemar's Test: Comparing Paired Proportions, Statistics Fundamentals.](https://master-statistics.com/hypothesis-testing/mcnemars-test/)
13. [Durkalski VL, Palesch YY, Lipsitz SR, Rust PF (2003). Analysis of clustered matched-pair data. Statistics in Medicine 22: 2417–2428.](https://doi.org/10.1002/SIM.1438)
14. [Lyles RH et al. (2005). Extending McNemar's test: estimation and inference when paired binary outcome data are misclassified. Biometrics 61(1): 287–294.](https://pubmed.ncbi.nlm.nih.gov/15737105/)
15. [mcnemar.test: McNemar's Chi-squared Test for Count Data, RDocumentation (stats package).](https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/mcnemar.test)
16. [Fay MP (2010). Two-sided Exact Tests and Matching Confidence Intervals for Discrete Data. The R Journal 2(1).](https://doi.org/10.32614/RJ-2010-008)
17. [McNemar's Test: Paired Binary Data Guide, CASRAI.](https://casrai.org/guides/mcnemars-test-paired-categorical-data)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Statistical inference, estimation, sampling, and testing › Hypothesis testing

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/mcnemars-test

English original: https://www.edgepedia.org/mcnemars-test
