# 克鲁斯卡尔–沃利斯检验

克鲁斯卡尔–沃利斯检验（Kruskal–Wallis test）是一种非参数统计检验，它把所有观测值合在一起排秩，再比较各组的秩和，以此判断三个或更多独立组是否来自同一分布。它是曼–惠特尼U检验背后的逻辑向两组以上情形的推广；若恰好用于两组，它在代数上就化为曼–惠特尼U检验。<sup>[1](https://doi.org/10.1080/01621459.1952.10483441)</sup><sup> • </sup><sup>[2](https://www.casrai.org/guides/kruskal-wallis-test-when-to-use-and-how-to-report)</sup> 当样本相互独立、正态性存疑时，它可充当单因素方差分析的非参数替代方案。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC468904/)</sup>

| 关键事实 | 说明 |
|---|---|
| 提出者 | 威廉·H·克鲁斯卡尔（William H. Kruskal）与W·艾伦·沃利斯（W. Allen Wallis），《美国统计协会杂志》，第47卷，第583–621页，1952年<sup>[1](https://doi.org/10.1080/01621459.1952.10483441)</sup> |
| 检验统计量 | \( H \)，由合并秩计算，近似服从自由度为 \( k-1 \) 的 \( \chi^{2} \) 分布<sup>[4](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)</sup> |
| 原假设 | 平均秩相等（随机同质性）；只有当各组分布形状相同时，才等价于中位数相等<sup>[5](http://biostathandbook.com/kruskalwallis.html)</sup> |
| 卡方经验法则 | 当每组观测数约多于4或5个时，可认为该近似足够<sup>[4](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)</sup> |
| 并列值 | 并列值取平均秩；用一个校正因子去除 \( H \)，所得统计量只会增大<sup>[6](https://biostat.jhsph.edu/~iruczins/teaching/materials/notes/n.av4.pdf)</sup> |
| 标准事后检验 | 邓恩检验（Dunn's test，1964），基于合并秩进行，配合邦费罗尼或霍尔姆校正<sup>[7](https://doi.org/10.1080/00401706.1964.10490181)</sup> |
| 软件 | R 的 `kruskal.test`、Stata 的 `kwallis`、SAS 的 `NPAR1WAY`（配 WILCOXON 选项）、Minitab、SPSS<sup>[8](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/kruskal.test.html)</sup><sup> • </sup><sup>[9](https://www.stata.com/manuals13/rkwallis.pdf)</sup> |

## 原理

把全部 \( k \) 组的所有观测值合并，从1排到 \( N \)，其中 \( N \) 是观测值总数。随后检验要问的是：各组的秩和之间的差异，是否大到不可能来自同一总体。<sup>[4](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)</sup> 在“各组同分布”的原假设下，每组的平均秩应当接近 \( (N+1)/2 \)，而该统计量衡量的正是各组平均秩偏离这一期望的程度。<sup>[10](https://nchenderson.github.io/elements-nonpar-stat/krusk-wallis.html)</sup>

统计量为

\[ H = \frac{12}{N(N+1)} \sum_{i=1}^{k} \frac{R_{i}^{2}}{n_{i}} - 3(N+1) \]

其中 \( R_{i} \) 是第 \( i \) 组的秩和，\( n_{i} \) 是其样本量。<sup>[4](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)</sup> 之所以呈卡方行为，是因为该统计量本质上就是在秩上做单因素方差分析所得的组间平方和，而秩的方差是事先已知的；秩上的组间平方和等于 \( N(N-1)/12 \) 乘以克鲁斯卡尔–沃利斯统计量。<sup>[10](https://nchenderson.github.io/elements-nonpar-stat/krusk-wallis.html)</sup><sup> • </sup><sup>[11](https://digfir-published.macmillanusa.com/psbe4e/psbe4e_ch16_8.html)</sup> 克鲁斯卡尔1952年的姊妹篇论文证明：在相当一般的条件下，原假设成立时 \( H \) 渐近服从自由度为 \( C-1 \) 的卡方分布，并给出了精确小样本零分布所满足的一个差分方程。<sup>[12](https://doi.org/10.1214/aoms/1177729332)</sup>

这个检验究竟检测到了什么，措辞上须格外小心。威尔科克斯（Wilcox）指出，H检验无法以一致递增的检验力检测出任何备择情形，唯有偏离随机同质性的情形除外，而随机同质性等价于秩样本均值的期望值相等；该检验本质上是对秩变换做方差分析。<sup>[13](https://journals.sagepub.com/doi/10.3102/10769986023002170)</sup> “中位数相等”这一解读，只有在各组分布形状相同时才成立。一个刻意构造的例子中，各组均值相同（43.5）、中位数也相同（27.5），但平均秩不同（34.6、27.5和20.4），结果在 \( P = 0.025 \) 水平上显著。<sup>[5](http://biostathandbook.com/kruskalwallis.html)</sup> 当形状明显不同时，显著结果说明的是随机占优，即某一组倾向于产生比其他组更高的值，而并不特指中位数的差异。<sup>[2](https://www.casrai.org/guides/kruskal-wallis-test-when-to-use-and-how-to-report)</sup>

## 操作步骤

实际操作步骤为：<sup>[4](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)</sup><sup> • </sup><sup>[6](https://biostat.jhsph.edu/~iruczins/teaching/materials/notes/n.av4.pdf)</sup>

1. 把所有各组的全部观测值合在一起排秩，忽略组别；并列值取其本应得到的诸秩的平均值（平均秩）。
2. 按上式算出各组的秩和 \( R_{i} \) 与统计量 \( H \)。
3. 若存在并列值，施加校正因子 \( D = 1 - \sum_{i} \frac{T_{i}^{3} - T_{i}}{N^{3} - N} \)，其中 \( T_{i} \) 是某一并列组内并列观测的个数，并使用 \( H' = H/D \)。由于 \( D \le 1 \)，校正后的统计量满足 \( H' \ge H \)。<sup>[6](https://biostat.jhsph.edu/~iruczins/teaching/materials/notes/n.av4.pdf)</sup>
4. 将 \( H \)（或 \( H' \)）与自由度为 \( k-1 \) 的 \( \chi^{2} \) 分布比较，或与小样本的精确表比较；拒绝域是单侧的，当 \( H \) 过大时拒绝原假设。<sup>[4](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)</sup>

算例可以显示典型结果的量级。美国国家标准与技术研究院（NIST）对四家公司的投资比较得出 \( H = 13.678 \)，超过了 \( df = 3 \) 时 \( \chi^{2} \) 的临界值7.812，故拒绝原假设。<sup>[4](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)</sup> 一个血液凝固的例子得出 \( H = 16.86 \)、\( D = 0.991 \)、\( H' = 17.02 \)、\( P \approx 0.0007 \)。<sup>[6](https://biostat.jhsph.edu/~iruczins/teaching/materials/notes/n.av4.pdf)</sup>

\( \chi^{2} \) 近似是大样本手段。NIST指出，只要样本量不太小——譬如所有 \( i \) 都有 \( n_{i} > 4 \)——该近似即成立。<sup>[4](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)</sup> 奥迪亚塞（Odiase）与奥格博姆万（Ogbonmwan）通过穷举枚举生成了精确的置换临界值，他们给出的约定更严格：当 \( p = 3 \) 且 \( n_{i} \ge 6 \)，或 \( p > 3 \) 且 \( n_{i} \ge 5 \) 时，才使用大样本近似；而当 \( n_{i} \le 5 \) 时，卡方近似效果不佳。<sup>[14](https://digitalcommons.wayne.edu/cgi/viewcontent.cgi?article=1250&context=jmasm)</sup> 已有人把 \( H \) 的精确上临界值制成表，涵盖每组至多6个观测、名义显著性水平为0.10、0.05、0.025和0.01的情形；对于 \( k = 3 \) 且各组样本量均大于5，或 \( k > 3 \) 且各组样本量均大于4的情形，这些表则指引使用者改用卡方近似。<sup>[15](https://www.york.ac.uk/depts/maths/histstat/tables/kruskalwallis.pdf)</sup> 崔、李、许、姜四人提出了一种用递推公式计算精确零分布的算法，2003年发表于《统计通讯——模拟与计算》。<sup>[16](https://doi.org/10.1081/sac-120023876)</sup> 迈耶（Meyer）与西曼（Seaman）生成了一批精确概率分布，覆盖三组中每组至多35个观测（总计 \( n \le 105 \)）以及四组中每组至多10个观测的情形；在他们所比较的卡方、伽马与贝塔三种近似中，贝塔近似的均方根误差最小，他们建议当样本量超出其精确表范围时，以此取代常用的卡方近似。<sup>[17](https://doi.org/10.1080/00220973.2012.699904)</sup>

## 源流

该检验由威廉·H·克鲁斯卡尔与W·艾伦·沃利斯在《单因素方差分析中的秩的应用》一文中提出，载《美国统计协会杂志》第47卷第260期，第583–621页，1952年12月，勘误见《美国统计协会杂志》第48卷，第907–911页，1953年。<sup>[1](https://doi.org/10.1080/01621459.1952.10483441)</sup><sup> • </sup><sup>[18](https://garfield.library.upenn.edu/classics1987/A1987K083100001.pdf)</sup> 在后来的评述中，两位作者回忆说基本想法出自沃利斯，克鲁斯卡尔负责理论计算。<sup>[18](https://garfield.library.upenn.edu/classics1987/A1987K083100001.pdf)</sup> 克鲁斯卡尔还于1952年在《数理统计年刊》发表了姊妹篇《多样本问题的一种非参数检验》，其中推导了 \( H \) 的精确小样本分布与渐近性质。<sup>[12](https://doi.org/10.1214/aoms/1177729332)</sup>

1952年那篇论文建立在若干前驱工作之上。弗里德曼（Friedman）1937年的双向秩方法提供了以秩为基础、在方差分析中绕开正态假设的途径。<sup>[19](https://doi.org/10.1080/01621459.1937.10503522)</sup> 克鲁斯卡尔与沃利斯把两样本秩和方法推广到了两个以上样本。<sup>[20](https://doi.org/10.2307/3001968)</sup><sup> • </sup><sup>[21](https://doi.org/10.1214/aoms/1177730491)</sup> 沃利斯本人1939年就提出过相关比的秩版本，<sup>[22](https://doi.org/10.1080/01621459.1939.10503552)</sup> 两位作者还把霍特林（Hotelling）与帕布斯特（Pabst）1936年的秩相关工作，以及由皮特曼（Pitman）和韦尔奇（Welch）加以实现的费希尔（Fisher）置换检验，列为思想来源。<sup>[18](https://garfield.library.upenn.edu/classics1987/A1987K083100001.pdf)</sup>

## 变体

\( H \) 显著只说明各组在某种意义上存在差异；究竟差在何处，要靠后续检验来确定。标准做法是邓恩检验，由奥利夫·琼·邓恩（Olive Jean Dunn）在《用秩和进行多重比较》（《技术计量学》，1964年）中提出，它复用总体检验的合并秩来做两两比较，并配以邦费罗尼或霍尔姆之类的多重比较校正（霍尔姆法较不保守，通常更可取）。<sup>[7](https://doi.org/10.1080/00401706.1964.10490181)</sup><sup> • </sup><sup>[2](https://www.casrai.org/guides/kruskal-wallis-test-when-to-use-and-how-to-report)</sup> 对每一对样本各自重新排秩、再做一系列威尔科克森秩和检验的做法并不被提倡，部分原因是它可能违反传递性；在R中，邓恩检验可通过 `dunn.test` 包获得。<sup>[10](https://nchenderson.github.io/elements-nonpar-stat/krusk-wallis.html)</sup>

具名的变体覆盖了其他设计。约恩克海尔–特普斯特拉检验（Jonckheere–Terpstra test）是克鲁斯卡尔–沃利斯检验针对有序处理的一种变体，与标准正态分布相比较；弗里德曼检验则处理相关样本（重复测量）。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC468904/)</sup> 效应量包括 \( \epsilon^{2} = H/(N-1) \) 和 \( \eta_{H}^{2} = (H-k+1)/(N-k) \)。<sup>[2](https://www.casrai.org/guides/kruskal-wallis-test-when-to-use-and-how-to-report)</sup> 软件实现包括：R 基础包中的 `kruskal.test`，它接受数值向量列表或公式接口，返回统计量、自由度与p值（`coin` 包中的 `wilcox_test` 可给出精确、渐近与蒙特卡洛条件p值，含存在并列值的情形）；<sup>[8](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/kruskal.test.html)</sup> Stata 的 `kwallis`；<sup>[9](https://www.stata.com/manuals13/rkwallis.pdf)</sup> SAS 的 `NPAR1WAY`（配 WILCOXON 选项）；<sup>[5](http://biostathandbook.com/kruskalwallis.html)</sup> 以及 Minitab，后者报告经并列值校正的统计量。<sup>[23](https://www.mathstat.dal.ca/~stat2080/Fall14/Lecturenotes/kruskalwallis.pdf)</sup>

## 应用

当正态性存疑、方差明显不等，或数据为序数性质时，可用一个名义变量配一个测量或秩次变量来做此检验。<sup>[5](http://biostathandbook.com/kruskalwallis.html)</sup> 典型场景见于医学、生物学与生态学：跨病区的ICU住院时长比较，<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC468904/)</sup> 美洲牡蛎中DNA与蛋白质多态性之间 \( F_{\mathrm{ST}} \) 值的比较（\( H = 0.043 \)，1个自由度，\( P = 0.84 \)），以及一个用真实秩次数据的狗的支配等级例子（\( H = 4.61 \)，1个自由度，\( P = 0.032 \)）。<sup>[5](http://biostathandbook.com/kruskalwallis.html)</sup> 与标准单因素方差分析不同，该统计量对数据的单调变换（例如对计数数据取平方根）保持不变。<sup>[10](https://nchenderson.github.io/elements-nonpar-stat/krusk-wallis.html)</sup>

## 局限与替代方案

其假定为：组内与组间观测相互独立；各分布形状相同（但不一定中位数相同）；数据至少是序数性质，且来自随机的独立样本。<sup>[24](https://link.springer.com/article/10.1186/s13040-025-00465-6)</sup> 该检验放宽了方差分析的正态性假定，但保留了独立性与连续分布的要求。<sup>[11](https://digfir-published.macmillanusa.com/psbe4e/psbe4e_ch16_8.html)</sup> 当样本量小或不均衡，或存在大量并列秩时，\( H \) 的卡方近似就不那么准确。<sup>[24](https://link.springer.com/article/10.1186/s13040-025-00465-6)</sup>

异方差性是最主要的失效情形。营养学与肥胖研究中的模拟工作显示，费希尔方差分析与克鲁斯卡尔–沃利斯检验的第一类错误率都偏离了预期显著性水平，且随异质性增大而偏离更甚，样本量不均衡时尤甚；作者由此得出结论：经典非参数检验并不能医治异方差。<sup>[25](https://pmc.ncbi.nlm.nih.gov/articles/PMC7948897/)</sup> 对异方差数据，韦尔奇方差分析（Welch's ANOVA）以各组方差估计值的倒数给观测加权，并采用韦尔奇–萨特思韦特自由度校正，能保持第一类错误率，代价是在方差实际上相等时会损失一些检验力。<sup>[25](https://pmc.ncbi.nlm.nih.gov/articles/PMC7948897/)</sup><sup> • </sup><sup>[26](https://doi.org/10.1093/biomet/38.3-4.330)</sup>

与普通方差分析相比，这种取舍幅度不大，且是双向的。在正态性下，两者检验力差异极小，克鲁斯卡尔–沃利斯约低0.01至0.02，但在非正态分布（例如 \( df = 2 \) 的卡方分布）下，它的检验力明显更高。<sup>[24](https://link.springer.com/article/10.1186/s13040-025-00465-6)</sup> 一项早期实证比较发现，检验均值时，即便假定被违反，方差分析的F检验仍得到支持；而检验关于中位数的假设时，克鲁斯卡尔–沃利斯与F检验不相上下。<sup>[27](https://journals.sagepub.com/doi/10.1177/001316447403400406)</sup> 检验力损失有两个机制：用秩代替数据丢弃了信息；该检验比较的是整体分布而非集中趋势。<sup>[25](https://pmc.ncbi.nlm.nih.gov/articles/PMC7948897/)</sup>

路德维希·A·霍索恩（Ludwig A. Hothorn）在2023年的一篇arXiv评论中主张，克鲁斯卡尔–沃利斯检验“不应被推荐”：它不能对任意备择情形都保持稳健；它是总体检验，对边际假设不提供置信区间；它本质上是双侧的；而且难以改造用于析因设计或协方差分析。他提出的替代方案是双重最大值检验，即把针对总均值的多个对比取最大值，再与三种秩评分（秩变换、安萨里–布拉德利、萨维奇）的最大值相结合，这三种评分分别对位置、尺度与形状效应敏感；在其算例中，克鲁斯卡尔–沃利斯的p值为0.0007，而联合检验给出 \( p < 0.0001 \)，且信息更为详尽。<sup>[28](https://doi.org/10.48550/arxiv.2302.05647)</sup> 2026年《统计与计算》上的一篇论文提出一种基于U统计量的检验，用于在大 \( k \)、小 \( n \) 情形下检验某个标量参数在多个总体间是否相等，并指出在同方差下，经典F统计量及其基于秩的类比当 \( k \to \infty \) 时依分布收敛到正态律，因此当组数多而各组样本量小时，惯用的卡方参照分布需要加以调整。<sup>[29](https://doi.org/10.1007/s11222-026-10924-7)</sup> 这些提议在常规实践中相对克鲁斯卡尔–沃利斯检验表现如何，主流软件是否会采用它们，已发表的比较尚未给出定论。

## References

1. [William H. Kruskal, W. Allen Wallis (1952). Use of Ranks in One-Criterion Variance Analysis. Journal of the American Statistical Association.](https://doi.org/10.1080/01621459.1952.10483441)
2. [The Kruskal-Wallis Test: When to Use It Instead of ANOVA and How to Report It (CASRAI)](https://www.casrai.org/guides/kruskal-wallis-test-when-to-use-and-how-to-report)
3. [Statistics review 10: Further nonparametric methods (Bewick, Cheek, Ball; Critical Care)](https://pmc.ncbi.nlm.nih.gov/articles/PMC468904/)
4. [NIST/SEMATECH e-Handbook: The Kruskal-Wallis (KW) Test for Comparing Populations with Unknown Distributions](https://www.itl.nist.gov/div898/handbook/prc/section4/prc41.htm)
5. [Handbook of Biological Statistics (John H. McDonald): Kruskal–Wallis test](http://biostathandbook.com/kruskalwallis.html)
6. [ANOVA - Non-Parametric Methods (Johns Hopkins Biostatistics course notes)](https://biostat.jhsph.edu/~iruczins/teaching/materials/notes/n.av4.pdf)
7. [Olive Jean Dunn (1964). Multiple Comparisons Using Rank Sums. Technometrics.](https://doi.org/10.1080/00401706.1964.10490181)
8. [R Documentation: kruskal.test, Kruskal-Wallis Rank Sum Test](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/kruskal.test.html)
9. [Stata Manual: kwallis, Kruskal–Wallis equality-of-populations rank test](https://www.stata.com/manuals13/rkwallis.pdf)
10. [Chapter 4: Rank Tests for Multiple Groups (Elements of Nonparametric Statistics)](https://nchenderson.github.io/elements-nonpar-stat/krusk-wallis.html)
11. [Macmillan, The Practice of Statistics in the Life Sciences 4e, §16: The Kruskal-Wallis Test](https://digfir-published.macmillanusa.com/psbe4e/psbe4e_ch16_8.html)
12. [William H. Kruskal (1952). A Nonparametric test for the Several Sample Problem. The Annals of Mathematical Statistics.](https://doi.org/10.1214/aoms/1177729332)
13. [The Kruskal-Wallis Test and Stochastic Homogeneity (Wilcox, Journal of Educational and Behavioral Statistics)](https://journals.sagepub.com/doi/10.3102/10769986023002170)
14. [JMASM20: Exact Permutation Critical Values For The Kruskal-Wallis One-Way ANOVA (Odiase & Ogbonmwan, Journal of Modern Applied Statistical Methods)](https://digitalcommons.wayne.edu/cgi/viewcontent.cgi?article=1250&context=jmasm)
15. [Upper Critical Values for the Kruskal-Wallis Test (k samples)](https://www.york.ac.uk/depts/maths/histstat/tables/kruskalwallis.pdf)
16. [Won Choi and colleagues (2003). An Algorithm for Computing the Exact Distribution of the Kruskal–Wallis Test. Communications in Statistics - Simulation and Computation.](https://doi.org/10.1081/sac-120023876)
17. [J. Patrick Meyer, Michael A. Seaman (2013). A Comparison of the Exact Kruskal-Wallis Distribution to Asymptotic Approximations for All Sample Sizes up to 105. The Journal of Experimental Education.](https://doi.org/10.1080/00220973.2012.699904)
18. [Citation Classic: Kruskal W H & Wallis W A. Use of ranks in one-criterion variance analysis (1987 commentary by Kruskal and Wallis)](https://garfield.library.upenn.edu/classics1987/A1987K083100001.pdf)
19. [Milton Friedman (1937). The Use of Ranks to Avoid the Assumption of Normality Implicit in the Analysis of Variance. Journal of the American Statistical Association.](https://doi.org/10.1080/01621459.1937.10503522)
20. [Frank Wilcoxon (1945). Individual Comparisons by Ranking Methods. Biometrics Bulletin.](https://doi.org/10.2307/3001968)
21. [H. B. Mann, D. R. Whitney (1947). On a Test of Whether one of Two Random Variables is Stochastically Larger than the Other. The Annals of Mathematical Statistics.](https://doi.org/10.1214/aoms/1177730491)
22. [W. Allen Wallis (1939). The Correlation Ratio for Ranked Data. Journal of the American Statistical Association.](https://doi.org/10.1080/01621459.1939.10503552)
23. [Dalhousie University STAT 2080 lecture notes: Kruskal-Wallis test](https://www.mathstat.dal.ca/~stat2080/Fall14/Lecturenotes/kruskalwallis.pdf)
24. [A simple guide to the use of Student's t-test, Mann-Whitney U test, Chi-squared test, and Kruskal-Wallis test in biostatistics (BioData Mining, 2025)](https://link.springer.com/article/10.1186/s13040-025-00465-6)
25. [Persistent confusion in nutrition and obesity research about the validity of classic nonparametric tests in the presence of heteroscedasticity (PMC)](https://pmc.ncbi.nlm.nih.gov/articles/PMC7948897/)
26. [B. L. WELCH (1951). ON THE COMPARISON OF SEVERAL MEAN VALUES: AN ALTERNATIVE APPROACH. Biometrika.](https://doi.org/10.1093/biomet/38.3-4.330)
27. [An Empirical Comparison of the Anova F-Test, Normal Scores Test and Kruskal-Wallis Test Under Violation of Assumptions (1974)](https://journals.sagepub.com/doi/10.1177/001316447403400406)
28. [Hothorn, Ludwig A. (2023). The Kruskal Wallis test can not be recommended. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2302.05647)
29. [M. Romero-Madroñal, M. Remedios Sillero-Denamiel, M. Dolores Jiménez-Gamero (2026). Testing the equality of estimable parameters across many populations. Statistics and Computing.](https://doi.org/10.1007/s11222-026-10924-7)

---
*Initially written Sep 29, 2026 · Edited: 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/kruskal-wallis-test

English original: https://www.edgepedia.org/kruskal-wallis-test
