算法手册/ 实验/医学研究/ Cochran's Q检验

Cochran's Q检验

计算公式

符号

符号含义
Cj第 j 个条件下取 1 的例数
Li第 i 个对象在 k 个条件里取 1 的个数
T全部条件取 1 的总数,T = ΣCj
n有效样本量
k条件数
QCochran's Q 统计量
WKendall'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)} \]

参考文献

  1. Cochran, W. G. (1950). The comparison of percentages in matched samples. Biometrika, 37(3/4), 256–266.
  2. 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.
  3. Kendall, M. G., & Babington Smith, B. (1939). The problem of m rankings. The Annals of Mathematical Statistics, 10(3), 275–287.

算法参数

本方法没有需要额外选择的算法参数:变量的选择属于分析设置,全部计算按上式的定义直接完成。

验证报告

数据与 R 包

数据文件 cochran_q.csv
样本与变量 N = 60;C1–C4 四个 0/1 条件
R 包 DescTools 0.99.60

提示词

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")

对比结果

指标SPSSAUR差值
样本量 N60600
条件数 k4.00000000004.00000000000
Cochran's Q28.239669421528.23966942151.24e−11
自由度330
p 值3.234730e−63.234730e−65.09e−12
Kendall's W0.15688705230.15688705234.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.