How to Run the Kruskal-Wallis Test

Tests in one go whether three groups differ somewhere, using ranks. Everything is ranked together and the rank sums of the groups are checked for imbalance. It is one-way analysis of variance without the assumption of normality.

This tests in one go whether three or more groups differ somewhere, using ranks. It stands in for one-way analysis of variance where normality cannot be assumed.

All the data are ranked together and the rank sum RiR_i of each group is taken.

H=12N(N+1)Ri2ni3(N+1)H = \dfrac{12}{N(N+1)}\sum\dfrac{R_i^2}{n_i} - 3(N+1)

NN is the total count and nin_i the size of group ii. If the groups do not differ, the ranks should scatter evenly across them and HH stays small. HH is approximated by a chi-square distribution with one fewer degree of freedom than there are groups.

Example

Group A at 12, 15, 18, 20, group B at 22, 25, 27, 24 and group C at 17, 19, 16, 21 give rank sums of 15, 42 and 21. These total 78, matching 12×13÷212 \times 13 \div 2. Then H=7.73H = 7.73 on 2 degrees of freedom, with a p-value of 0.021, beating the 5% critical value of 5.99.

It does not say which groups differ

All this test establishes is that a difference exists somewhere. Finding which groups differ takes a follow-up comparing them in pairs, and without adjusting the significance level for the number of comparisons the chance of a false positive grows.

Notes

Repeated values push HH down. Dividing by a correction for the tied ranks puts that back.

The groups need not be the same size, but very small groups weaken the chi-square approximation.