Cochran's Q检验
计算公式
符号
| 符号 | 含义 |
|---|---|
| Cj | 第 j 个条件下取 1 的例数 |
| Li | 第 i 个对象在 k 个条件里取 1 的个数 |
| T | 全部条件取 1 的总数,T = ΣCj |
| n | 有效样本量 |
| k | 条件数 |
| Q | Cochran's Q 统计量 |
| W | Kendall's W 一致性系数 |
核心公式
公式 (1.1):Cochran's Q
\[
Q=(k-1)\frac{k\sum_{j=1}^{k}C_j^2-T^2}{kT-\sum_{i=1}^{n}L_i^2},\qquad \mathrm{df}=k-1
\]
公式 (1.2):Kendall's W
\[
W=\frac{Q}{n(k-1)}
\]
参考文献
- Cochran, W. G. (1950). The comparison of percentages in matched samples. Biometrika, 37(3/4), 256–266.
- Friedman, M. (1937). The use of ranks to avoid the assumption of normality implicit in the analysis of variance. Journal of the American Statistical Association, 32(200), 675–701.
- Kendall, M. G., & Babington Smith, B. (1939). The problem of m rankings. The Annals of Mathematical Statistics, 10(3), 275–287.
算法参数
本方法没有需要额外选择的算法参数:变量的选择属于分析设置,全部计算按上式的定义直接完成。
验证报告
数据与 R 包
提示词
C1、C2、C3、C4 是同一批人在四个条件下的 0/1 结果,检验四个条件的阳性率是否相同,做 Cochran's Q 检验。
R 代码
library(DescTools)
options(digits = 15)
d <- read.csv("cochran_q.csv")
y <- as.matrix(d[, c("C1", "C2", "C3", "C4")])
q <- CochranQTest(y)
print(q)
cat("N", nrow(y), "k", ncol(y), "\n")
cat("col sums", colSums(y), "\n")
cat("Q", unname(q$statistic), "df", unname(q$parameter), "p", q$p.value, "\n")
cat("Kendall W", unname(q$statistic) / (nrow(y) * (ncol(y) - 1)), "\n")
对比结果
| 指标 | SPSSAU | R | 差值 |
|---|---|---|---|
| 样本量 N | 60 | 60 | 0 |
| 条件数 k | 4.0000000000 | 4.0000000000 | 0 |
| Cochran's Q | 28.2396694215 | 28.2396694215 | 1.24e−11 |
| 自由度 | 3 | 3 | 0 |
| p 值 | 3.234730e−6 | 3.234730e−6 | 5.09e−12 |
| Kendall's W | 0.1568870523 | 0.1568870523 | 4.16e−11 |
结论:Q、自由度、p 与 Kendall's W 均与 R 一致,最大差 4.2e−11。
引用SPSSAU. Cochran's Q检验:计算公式与参数[EB/OL]. SPSSAU算法手册, 2026-11-20. https://www.spssau.com/algorithm/general/cochran_q.html.