算法手册/ 实验/医学研究/ fisher卡方

fisher卡方

计算公式

符号

符号含义
Oij第 i 行第 j 列的实际频数
Eij期望频数
N总样本量
R、C行、列类别数
t固定边际下的任意一张同边际表
pFFisher 精确检验的双侧 p 值

核心公式

公式 (1.1):Pearson 卡方与期望频数
\[ \chi^2=\sum_{i=1}^{R}\sum_{j=1}^{C}\frac{(O_{ij}-E_{ij})^2}{E_{ij}},\qquad E_{ij}=\frac{O_{i\cdot}O_{\cdot j}}{N},\qquad \mathrm{df}=(R-1)(C-1) \]
公式 (1.2):2×2 的 Yates 连续校正
\[ \chi^2_{\mathrm{Yates}}=\sum_{i=1}^{2}\sum_{j=1}^{2}\frac{\left(\max\left(0,\ |O_{ij}-E_{ij}|-0.5\right)\right)^2}{E_{ij}} \]

每格先把观测值朝期望值方向移动 min(0.5, |Oij−Eij|),有效偏差即 max(0, |Oij−Eij|−0.5)。

公式 (1.3):Fisher 精确检验的双侧 p 值
\[ p_F=\sum_{\{t:\,P(t)\le P_{\mathrm{obs}}\}}P(t),\qquad P(t)=\frac{\prod_{i=1}^{R}O_{i\cdot}!\prod_{j=1}^{C}O_{\cdot j}!}{N!\prod_{i=1}^{R}\prod_{j=1}^{C}t_{ij}!} \]

参考文献

  1. Fisher, R. A. (1935). The Design of Experiments. Oliver & Boyd.
  2. Cochran, W. G. (1954). Some methods for strengthening the common χ² tests. Biometrics, 10(4), 417–451.
  3. Agresti, A. (2002). Categorical Data Analysis (2nd ed.). Wiley.

算法参数

本方法没有需要额外选择的算法参数:输入一张频数表即可,全部计算按上式的定义直接完成。

验证报告

数据与 R 包

数据文件 summary_chisquare.csv
样本与变量 N = 120;原始数据 X、Y,交叉表 2×3
R 包 stats 4.6.2(R 基础包)

提示词

下面是一张 2×3 的汇总频数表,行 A、B,列 Low、Mid、High:[[38, 9, 5], [62, 4, 2]],请做概要卡方检验,并给出 Fisher 精确检验。

R 代码

options(digits = 15)
d <- read.csv("summary_chisquare.csv")
tab <- table(d$X, d$Y)
print(tab)
cat("N", sum(tab), "\n")
ct <- chisq.test(tab, correct = FALSE)
cat("pearson chisq", unname(ct$statistic), "df", unname(ct$parameter), "p", ct$p.value, "\n")
ft <- fisher.test(tab)
print(ft)
cat("fisher p", ft$p.value, "\n")

对比结果

指标SPSSAUR差值
样本量 N1201200
Pearson χ²6.95917657006.95917657003.63e−11
自由度220
Pearson p0.03082009750.03082009751.69e−11
Fisher 精确 p0.03006838230.03006838234.34e−11

结论:Pearson χ²、自由度与 p、Fisher 精确 p 均与 R 一致,最大差 4.3e−11。

操作手册 问题反馈

引用SPSSAU. fisher卡方:计算公式与参数[EB/OL]. SPSSAU算法手册, 2026-11-20. https://www.spssau.com/algorithm/general/summary_chisquare.html.