MathsStatistics & Probability

Kruskal-Wallis H Test
calculator.

The Kruskal-Wallis test compares independent groups using ranks in place of means.

How it's worked out

Pool all the values, rank them from smallest to largest, then ask whether some groups collect more of the high ranks than chance would give. NIST gives the statistic in this form.

H\displaystyle H=12N(N+1)∑Ri2ni−3(N+1)\displaystyle {}= \frac{12}{N(N + 1)} \sum \frac{R_i^2}{n_i} - 3(N + 1)

N is the total number of values, n is the size of one group, and R is the sum of that group’s ranks. Because only ranks count, the test suits ratings and resists wild values. If the groups do not differ, H roughly follows a chi-square distribution with one fewer degree of freedom than there are groups, and the p-value is the area past H.

Tied values each take the average of the ranks they span. Ties shrink H, so it is divided by a factor C, where t is how many values share one tied value. The same correction appears in MedCalc.

C\displaystyle C=1−∑(t3−t)N3−N\displaystyle {}= 1 - \frac{\sum (t^3 - t)}{N^3 - N}

A significant H does not say which groups differ. Dunn’s test turns the gap between two mean ranks into a z score, using a standard error built from both group sizes and the ties. Then the p-values are adjusted for the number of pairs. Bonferroni multiplies each one by that number, and Holm works through them in order, which is never less powerful.

The effect size here is eta squared H, which rstatix gives with k as the number of groups.

ηH2\displaystyle \eta^2_H=H−k+1N−k\displaystyle {}= \frac{H - k + 1}{N - k}

Worked examples

Three teaching methods, five students each

The scores run 12 to 18, 20 to 25 and 10 to 14, so the groups barely overlap. Ranking all 15 gives rank sums of 37, 65, 18. Two pairs of scores tie, so the correction lifts H a little, from 11.18 to 11.2201.

With 2 degrees of freedom, p = 0.0037, so the methods differ at the 0.05 level. Dunn’s test shows the clearest gap between methods 2 and 3, with z = 3.329 and a Holm-adjusted p of 0.0026.

A report might read: H(2) = 11.22, p = 0.004, eta squared H = 0.77. That effect size counts as large.

Open this example in the tool

Mucociliary efficiency, a data set with heavy overlap

R’s documentation for kruskal.test uses data from Hollander and Wolfe on normal subjects, people with obstructive airway disease and people with asbestosis.

The groups overlap heavily: H = 0.7714 and p = 0.68, so there is no evidence of a difference. Note that this is not evidence of no difference, as the groups hold only 5, 4, 5 people. One group has fewer than 5, so read that p-value with care too.

Open this example in the tool

Ratings on a 1 to 5 scale, full of ties

Four groups of six people give ratings from 1 to 5, so most values tie with others. The uncorrected H is 12.44. The correction factor of 0.913 raises it to 13.6248, with p = 0.0035.

With this many ties, the correction changes the answer enough to matter. The clearest pair after adjustment is Group 2 and Group 3, with a Holm p of 0.007.

Open this example in the tool

Reading your result

H is a measure of how far apart the mean ranks are. H of 0 would mean every group has the same mean rank. It is significant when it passes the chi-square critical value for one fewer than the number of groups.

Critical values of H
Groupsα = 0.10α = 0.05α = 0.01
22.7063.8416.635
34.6055.9919.21
46.2517.81511.345
57.7799.48813.277
69.23611.0715.086
710.64512.59216.812
812.01714.06718.475

Check the group sizes first. NIST says each group should have at least 5 values for the chi-square reading to hold, and SciPy’s notes give the same rule of thumb. Smaller groups still run here, with a warning, but exact tables are the safer source.

Be careful saying "medians". McDonald’s Handbook of Biological Statistics stresses that the test compares medians only if every group’s distribution has the same shape. Otherwise, say that values in one group tend to run higher than in another.

Read the effect size as well. rstatix lists eta squared H of 0.01 up to 0.06 as small, 0.06 up to 0.14 as moderate and 0.14 or more as large, after Tomczak and Tomczak (2014). A large sample can make a small effect significant, and a small sample can hide a large one.

Common mistakes

  • Using it on repeated measures. Each value must come from a different person or unit. For the same people measured several times, each person is a block, and the Friedman test is built for blocked data.
  • Choosing it by reflex over ANOVA. McDonald points out that one-way ANOVA is more powerful and not very sensitive to non-normal data. Save this test for truly ranked data and badly behaved groups, and use the one-way ANOVA calculator for the rest.
  • Looking only at unadjusted pairs. With several groups, the pairs add up to many tests. Use the adjusted columns, and name which adjustment you used.
  • Reaching for it with only two groups. The Mann-Whitney calculator is the usual choice there, as the rank test built for two groups.

Questions people ask

Read H and its p-value first, because they say whether any difference exists. Then read the adjusted p-values for the pairs, which say where it is. In the teaching example, H is 11.22, and methods 2 and 3 have the clearest gap.

Sources