多样本Friedman
计算公式
符号
| 符号 | 含义 |
|---|---|
| n | 有效样本(行)数 |
| k | 重复测量条件数 |
| Rij | 第 i 行内第 j 个条件的秩 |
| Rj | 第 j 个条件的秩和 |
| t | 同一行内某个结包含的条件数 |
| W | Kendall's W(和谐系数) |
核心公式
公式 (1.1):逐行排秩后的 Friedman 统计量
\[
\chi^2=\frac{12}{nk(k+1)}\sum_{j=1}^{k}R_j^2-3n(k+1)
\]
公式 (1.2):结校正
\[
C=1-\frac{\sum_t\left(t^3-t\right)}{n\left(k^3-k\right)},\qquad \chi_c^2=\frac{\chi^2}{C}
\]
公式 (1.3):p 值、Kendall's W 与效应量
\[
p=P\left(\chi^2_{k-1}\ge\chi_c^2\right),\qquad W=\frac{\chi_c^2}{n(k-1)},\qquad \text{effect size}=\frac{\chi_c^2}{k(n-1)}
\]
参考文献
- 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. Annals of Mathematical Statistics, 10(3), 275–287.
- Field, A. (2018). Discovering Statistics Using IBM SPSS Statistics (5th ed.). Sage.
算法参数
| 参数 | 取值 | 默认 | 影响 |
|---|---|---|---|
| 事后比较 | 不做事后比较 / Nemenyi / Conover / Conover-Bonferroni / Siegel / Miller | 不做事后比较 | 总体 χ² 显著后用于定位哪几个条件不同;本次验证不开启事后比较。 |
验证报告
数据与 R 包
提示词
对 Y1、Y2、Y3 三个重复测量条件做 Friedman 检验,给出 χ²、自由度、p、Kendall's W 与效应量,不做事后比较,结果保留 10 位小数。
R 代码
options(digits = 15)
d <- read.csv("friedman.csv")
m <- as.matrix(d[, c("Y1", "Y2", "Y3")])
r <- friedman.test(m)
print(r, digits = 15)
n <- nrow(m); k <- ncol(m)
cat("chi", r$statistic, "df", r$parameter,
"W", r$statistic / (n * (k - 1)),
"effect", r$statistic / (k * (n - 1)), "\n")
cat("medians", apply(m, 2, median), "\n")
cat("rbar", colMeans(t(apply(m, 1, rank))), "\n")
对比结果
| 指标 | SPSSAU | R | 差值 |
|---|---|---|---|
| 样本量 | 36 | 36 | 0 |
| 条件数 | 3.0000000000 | 3.0000000000 | 0 |
| χ² 值 | 11.5555555556 | 11.5555555556 | 4.44e−11 |
| 自由度 | 2 | 2 | 0 |
| p 值 | 3.095587e−3 | 3.095587e−3 | 6.68e−9 |
| Kendall's W | 0.1604938272 | 0.1604938272 | 3.95e−11 |
| 效应量 | 0.1100529101 | 0.1100529101 | 4.71e−11 |
| 中位数 Y1 | 53.8374315000 | 53.8374315000 | 0 |
| 中位数 Y2 | 55.3125355000 | 55.3125355000 | 0 |
| 中位数 Y3 | 54.9362305000 | 54.9362305000 | 0 |
| 秩均值 Y1 | 1.5555555556 | 1.5555555556 | 4.44e−11 |
| 秩均值 Y2 | 2.1111111111 | 2.1111111111 | 1.11e−11 |
| 秩均值 Y3 | 2.3333333333 | 2.3333333333 | 3.33e−11 |
结论:χ²、自由度、p 值、Kendall's W、效应量、三个条件的中位数与秩均值均与 R 一致;差值列均为 10 位小数输出带来的舍入误差。
引用SPSSAU. 多样本Friedman:计算公式与参数[EB/OL]. SPSSAU算法手册, 2026-11-20. https://www.spssau.com/algorithm/general/friedman.html.