# 独立性卡方检验

独立性卡方检验（又称皮尔逊卡方检验）是一种非参数统计假设检验，它利用列联表中计得的观察频数，判断两个分类变量是否相关。<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup><sup> • </sup><sup>[2](https://www.jmp.com/en/statistics-knowledge-portal/linear-models/chi-square-test/chi-square-test-of-independence)</sup> 当变量为名义变量时——这在临床研究中十分常见——它是最广泛用于假设检验的统计量之一。<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup>

| 关键事实 | 说明 |
|---|---|
| 用途 | 根据 r × c 列联表中的计数，检验两个分类变量或名义变量是否可能相关<sup>[2](https://www.jmp.com/en/statistics-knowledge-portal/linear-models/chi-square-test/chi-square-test-of-independence)</sup> |
| 检验统计量 | \( \chi^2 = \sum \frac{(O - E)^2}{E} \)，对所有单元格求和，其中 O 为观察频数，E 为期望频数<sup>[3](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/chistest.htm)</sup> |
| 期望计数 | \( E_{ij} = \frac{R_i \cdot C_j}{N} \)，即行合计乘以列合计再除以总计<sup>[2](https://www.jmp.com/en/statistics-knowledge-portal/linear-models/chi-square-test/chi-square-test-of-independence)</sup> |
| 自由度 | r × c 表的自由度为 \( (r - 1)(c - 1) \)<sup>[3](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/chistest.htm)</sup> |
| 样本量准则 | 若期望单元格计数中有超过 20% 低于 5，则应改用费希尔精确检验；任何单元格的期望频数都不应低于 1<sup>[4](https://www.ccjm.org/content/84/9_suppl_2/e20)</sup><sup> • </sup><sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC5426219)</sup> |
| 效应量 | 卡方结果显著之后，最常报告的相关强度指标是克拉默V<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup> |
| 起源 | 由卡尔·皮尔逊于 1900 年提出；到 1904 年已应用于列联表<sup>[6](https://www.numdam.org/item/AFST_2002_6_11_4_563_0.pdf)</sup> |

## 检验的原理

该检验把列联表各单元格中实际观察到的计数，与假定两变量相互独立时的期望计数相比较。第 i 行第 j 列单元格的期望计数，等于行合计乘以列合计再除以总计：\( E_{ij} = R_i \cdot C_j / N \)。<sup>[2](https://www.jmp.com/en/statistics-knowledge-portal/linear-models/chi-square-test/chi-square-test-of-independence)</sup> 一个常见的错误是用总计除以单元格数目；期望值是以行合计与列合计为基础的，而这两者对当前数据而言是固定的。<sup>[2](https://www.jmp.com/en/statistics-knowledge-portal/linear-models/chi-square-test/chi-square-test-of-independence)</sup>

检验统计量把观察计数与期望计数之差的平方加总，每一项再除以其期望计数：

\[ \chi^2 = \sum_{i=1}^{r} \sum_{j=1}^{c} \frac{(O_{ij} - E_{ij})^2}{E_{ij}} \]

对差值取平方，使计数偏多与偏少的单元格获得同等权重；除以期望计数，则使各单元格处于可比的尺度上。<sup>[2](https://www.jmp.com/en/statistics-knowledge-portal/linear-models/chi-square-test/chi-square-test-of-independence)</sup> 该统计量也可写成标准化残差平方和的形式，\( d_{ij} = (O_{ij} - E_{ij})/\sqrt{E_{ij}} \)，由此可看出每个单元格对总和的贡献。<sup>[3](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/chistest.htm)</sup>

在独立性的原假设之下，该统计量近似服从自由度为 \( (r-1)(c-1) \) 的卡方分布。统计量很大，意味着观察值与期望值之间差距很大，说明独立性假定与观察数据不符；当统计量超过所选显著性水平对应的临界值时，即拒绝原假设。<sup>[3](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/chistest.htm)</sup><sup> • </sup><sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC5426219)</sup>

## 假定条件

卡方检验对数据本身有四项条件要求：<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup>

1. 单元格中的数值是频数，即个案计数，而不是百分比或其他变换形式。
2. 每个变量的各水平互斥，因此每个受试者只能归入每个变量的一个且仅一个水平。
3. 每个受试者只贡献给一个且仅一个单元格；对同一批受试者反复测量所得的数据，不能用本检验分析。
4. 各研究组相互独立；若各组相关，则需改用其他检验。

除此之外，本检验还要求大样本卡方近似是恰当的。常用的经验准则是：若期望单元格计数中低于 5 的不超过 20%，可以使用卡方检验；若超过 20% 低于 5，则应改用费希尔精确检验。<sup>[4](https://www.ccjm.org/content/84/9_suppl_2/e20)</sup> 也有观点认为，只有当期望频数低于 5 的单元格不超过 20%、且没有任何单元格的期望频数低于 1 时，结果才被认为有意义。<sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC5426219)</sup> 科克伦指出，若最小期望频数低于 1，或有 20% 的期望频数低于 5，近似可能不佳；康诺弗则认为这一标准大概过于保守，尤其是在表格并不小的时候。<sup>[3](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/chistest.htm)</sup> 当期望频数过小时，有时可以把计数很小的行或列合理地合并，也可以改用费希尔精确检验。<sup>[3](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/chistest.htm)</sup>

## 与费希尔精确检验的关系

费希尔精确检验检验的是同一个独立性原假设，但它直接依据单元格计数的超几何分布计算概率，而不依赖大样本近似。<sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC5426219)</sup> 当样本量或期望频数较小时，它比卡方检验更准确。<sup>[7](https://sjdm.org/~baron/journal/11/11605/jdm11605.html)</sup> 尽管它实际主要用于小样本，但对任何样本量都有效；实际的障碍在于计算，因为精确检验要枚举所有具有相同固定边际的表格，而随着样本增大，这样的表格会变得极多。<sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC5426219)</sup><sup> • </sup><sup>[4](https://www.ccjm.org/content/84/9_suppl_2/e20)</sup> 许多软件包只对 2 × 2 表自动给出费希尔精确检验；例如 SPSS 仅在这种情况下把它与卡方检验并列报告，而网页计算器则可将其扩展到 5 × 5 的表格。<sup>[5](https://pmc.ncbi.nlm.nih.gov/articles/PMC5426219)</sup> 2025 年的一篇综述指出，在此语境下界定“小”样本存在若干经验法则，而皮尔逊卡方检验本身对任何样本量都可以作为精确检验来施行。<sup>[8](https://pubmed.ncbi.nlm.nih.gov/40156377/)</sup>

## 关联强度

卡方结果显著只说明变量之间存在关联，并不说明关联有多强。克拉默V统计量是卡方结果显著之后最常用的强度检验。<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup> SciPy 等软件可由二向表计算克拉默V、楚普罗夫T和皮尔逊列联系数；这些量衡量的是两个名义变量相关的程度，与相关不同，后者衡量的是它们以何种方式相关。<sup>[9](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.contingency.association.html)</sup> 一个已知的局限是，即使结果高度显著，克拉默V也往往给出相对偏低的相关度量。<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup>

## 解释与报告

卡方检验对数据的分布是稳健的：它既不要求各研究组方差齐性，也不要求正态性，并且既能处理二分的自变量，也能处理多组研究。<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup> 由于计算是逐单元格进行的，该检验能提供关于各组表现如何的详细信息，从而支持比许多其他统计量更细致的解释。<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup> 其局限包括对样本量的要求、变量类别达到 20 个或更多时解释困难，以及上文提到的克拉默V值偏低。<sup>[1](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)</sup> 报告时的通行做法是给出卡方值、自由度和 p 值。<sup>[10](https://userpage.fu-berlin.de/~structeng/wiki/doku.php?id=r%3Achi-square-test)</sup>

## 历史

卡尔·皮尔逊在 1900 年的论文《论一组相关变量情形下偏离可能值的给定偏差系统可合理假定由随机抽样产生这一判据》中提出了卡方检验，该文度量了观察数据对期望值的偏离，并给出了不同自由度下的概率表。<sup>[11](https://books.google.com/books/about/On_the_Criterion_that_a_Given_System_of.html?id=N0ZLAAAAMAAJ)</sup><sup> • </sup><sup>[12](https://mathshistory.st-andrews.ac.uk/Strick/pearson.pdf)</sup> 到 1904 年，该检验已被应用于列联表，自由度的概念则由 R. A. 费希尔在 1920 年代提出。<sup>[6](https://www.numdam.org/item/AFST_2002_6_11_4_563_0.pdf)</sup> 皮尔逊的框架把概率分布、拟合优度检验，以及通过流形分类分析列联表的技术结合在了一起。<sup>[13](https://www.sciencedirect.com/science/article/pii/B9780444508713501376)</sup>

## 软件实现

各大统计环境都提供该检验。R 的 `chisq.test` 对计数数据计算皮尔逊卡方检验，在 2 × 2 情形下默认施加耶茨连续性校正，并可用 `simulate.p.value = TRUE` 通过蒙特卡洛模拟计算 p 值。<sup>[14](https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/chisq.test)</sup> SciPy 的 `chi2_contingency` 由列联表计算统计量、p 值、自由度和期望频数，在指定使用校正且自由度为 1 时施加耶茨校正。<sup>[15](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.contingency.chi2_contingency.html)</sup>

## References

1. [Franke TM, Ho T, Christie CA. The Chi-square test of independence. Journal of the American Society for Information Science and Technology (PMC3900058)](https://pmc.ncbi.nlm.nih.gov/articles/PMC3900058/)
2. [Chi-Square Test of Independence, JMP Statistical Knowledge Portal](https://www.jmp.com/en/statistics-knowledge-portal/linear-models/chi-square-test/chi-square-test-of-independence)
3. [CHI-SQUARE INDEPENDENCE TEST, NIST Dataplot Reference Manual](https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/chistest.htm)
4. [Chi-square and Fisher's exact tests, Cleveland Clinic Journal of Medicine](https://www.ccjm.org/content/84/9_suppl_2/e20)
5. [Statistical notes for clinical researchers: Chi-squared test and Fisher's exact test (PMC5426219)](https://pmc.ncbi.nlm.nih.gov/articles/PMC5426219)
6. [The missing early history of contingency tables, Annals of Faculty of Sciences of Toulouse](https://www.numdam.org/item/AFST_2002_6_11_4_563_0.pdf)
7. [A statistical test of independence in choice data with small samples, Journal of Mathematical Psychology](https://sjdm.org/~baron/journal/11/11605/jdm11605.html)
8. [Neuhäuser M, Ruxton GDR. The Choice Between Pearson's χ2 Test and Fisher's Exact Test for 2 × 2 Tables. Pharm Stat. 2025](https://pubmed.ncbi.nlm.nih.gov/40156377/)
9. [scipy.stats.contingency.association, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.contingency.association.html)
10. [r:chi-square-test, Structure of English: Linguistic Resources, FU Berlin](https://userpage.fu-berlin.de/~structeng/wiki/doku.php?id=r%3Achi-square-test)
11. [Karl Pearson (1900). On the Criterion that a Given System of Deviations from the Probable..., Google Books](https://books.google.com/books/about/On_the_Criterion_that_a_Given_System_of.html?id=N0ZLAAAAMAAJ)
12. [Karl Pearson biographical sketch, MacTutor / St Andrews](https://mathshistory.st-andrews.ac.uk/Strick/pearson.pdf)
13. [Karl Pearson, paper on the chi square goodness of fit test (1900), ScienceDirect](https://www.sciencedirect.com/science/article/pii/B9780444508713501376)
14. [chisq.test: Pearson's Chi-squared Test for Count Data, RDocumentation](https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/chisq.test)
15. [scipy.stats.contingency.chi2_contingency, SciPy v1.18.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.contingency.chi2_contingency.html)

---
*Initially written 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/chi-square-test-of-independence

English original: https://www.edgepedia.org/chi-square-test-of-independence
