Statistics Quest

Kruskal–Wallis test

A rank-based alternative to one-way ANOVA that tests whether k independent groups come from the same distribution.

H=12N(N+1)∑i=1kni(Rˉi−N+12)21−∑(t3−t)N3−N,df=k−1H = \frac{\dfrac{12}{N(N+1)}\displaystyle\sum_{i=1}^{k} n_i\left(\bar R_i - \frac{N+1}{2}\right)^2}{1 - \dfrac{\sum (t^3 - t)}{N^3 - N}},\qquad df = k - 1
p-value = upper tail of χ² with k − 1 df (large-sample approximation). The denominator is the tie correction.
Rˉi\bar R_i
Mean rank of group i in the pooled sample (average ranks for ties).
ni,N,kn_i, N, k
Group size, total size, number of groups.
tt
Size of each group of tied values.
ε2=HN−1\varepsilon^2 = \frac{H}{N - 1}
Effect size (epsilon squared), between 0 and 1.
HH
The Kruskal–Wallis statistic.

When to use

Three or more independent groups with an ordinal outcome or skewed quantitative data with small groups (e.g. delays by airline).

Assumptions

Independent observations; ordinal or continuous outcome. Interpreting it as comparing medians requires similarly shaped distributions. The χ² approximation is rough when groups have fewer than about 5 observations.

How to interpret

A small p-value is evidence that at least one group tends to have larger values than another. Follow up with pairwise Mann–Whitney tests (or Dunn's test) with a multiple-comparison adjustment.

Common mistakes

  • Calling it "ANOVA on medians" without checking shapes.
  • Forgetting the follow-up adjustment for pairwise comparisons.

Example

Groups (2.1, 3.4, 2.8, 3.0), (4.2, 3.9, 4.8, 3.6), (3.1, 2.5, 3.3, 2.7). Mean ranks 4.5, 10.5, 4.5 (overall mean rank 6.5). H=1212⋅13⋅4(4+16+4)=7.38H = \frac{12}{12 \cdot 13}\cdot 4(4 + 16 + 4) = 7.38 on 2 df, p=0.025p = 0.025; ε2=0.67\varepsilon^2 = 0.67. The second group tends to be higher (approximation rough with 4 per group).