Kruskal-Wallis test
Ranks (nonparametric) · Three or more independent groups · reference distribution: χ²(k−1)
When to use it
Compare three or more independent groups without assuming normality: it is the ANOVA done on ranks.
Null hypothesis
All groups come from the same distribution.
Assumptions
- Independent groups
- At least ordinal variable
Test statistic
H = \dfrac{12}{N(N+1)} \sum_j \dfrac{R_j^2}{n_j} - 3(N+1)Effect size
ε²: the rank version of η².
\varepsilon^2 = \dfrac{H}{N - 1}How to report it
H(2) = 8.43, p = .015, ε² = .19
In R and Python
R
kruskal.test(y ~ group, data = df)
Python
stats.kruskal(a, b, c)
In Python, stats is scipy.stats and np is numpy.
Variants and alternatives
- After rejecting H₀: Dunn’s test
- Parametric version: One-way ANOVA
Where it sits in the catalog
Ranks (nonparametric). Nonparametric tests assume no distribution for the data. They replace each value by its rank, its position in order (1st, 2nd, 3rd…), which protects them from extreme values and makes them fit ordinal data.
Three or more independent groups. Several groups of different individuals, tested at once: one test per pair would inflate the type I error.
In the decision tree
- What do you want to do? Compare groups, or one group with a reference value
- What kind of response did you measure? Numeric: a measurement, such as weight, time or score
- How many groups or measurements? Three or more groups
- Are the groups made of different individuals or the same individuals? Different individuals (independent)
- Are the residuals approximately normal? No, or the response is ordinal