Kruskal–Wallis Test
The Kruskal–Wallis test is the non-parametric counterpart of one-way ANOVA. It tests whether three or more independent groups are drawn from the same population, without requiring the data to be normally distributed or the variances to be equal across groups. The test works by replacing the original observations with their ranks across the combined sample and then comparing the mean ranks between groups. It is the method of choice when the ANOVA assumptions cannot be satisfied — particularly with small samples, ordinal outcomes, or distributions that are markedly skewed or heavy-tailed. A significant result indicates that at least one group differs from the others; post-hoc pairwise comparisons identify which groups are responsible.
Ranking Procedure
The analysis begins by pooling all observations from all $k$ groups into a single list of $n$ values and ranking them from 1 (smallest) to $n$ (largest). Tied observations receive the average of the ranks they would have occupied. Once ranks are assigned, the original values play no further role; all subsequent calculations use only the ranks.
For each group $i$, let $n_i$ be the number of observations and $R_i$ the sum of ranks assigned to that group. The mean rank for group $i$ is $\bar{R}_i = R_i / n_i$. If all groups come from the same population, the mean ranks should be approximately equal. The Kruskal–Wallis test quantifies how far the observed mean ranks deviate from this expectation.
The H-Statistic
The test statistic is:
$$ H = \frac{12}{n(n+1)} \sum_{i=1}^{k} \frac{R_i^2}{n_i} \;-\; 3(n+1) $$Intuitively, $H$ measures the weighted variability of the group rank sums around the overall mean rank. Under the null hypothesis that all groups come from the same population, $H$ follows approximately a chi-squared distribution with $k - 1$ degrees of freedom, provided the group sizes are not too small (at least 5 per group is a common guideline).
Correction for Ties
When tied observations are present, the formula above slightly underestimates $H$. A correction is applied by dividing $H$ by:
$$ C = 1 - \frac{\displaystyle\sum_j \left(t_j^3 - t_j\right)}{n^3 - n} $$where the sum runs over every group of tied values and $t_j$ is the number of observations sharing the $j$-th tied value. The corrected statistic $H_c = H / C$ is always at least as large as the uncorrected value. When there are no ties, $C = 1$ and the correction has no effect. The corrected $H_c$ is compared to the same chi-squared distribution.
Post-Hoc Comparisons
A significant Kruskal–Wallis result establishes only that at least one group differs; it does not identify which. Two post-hoc procedures are available for pairwise comparisons.
Dunn's test (1964) works directly with the mean ranks from the Kruskal–Wallis analysis. For each pair of groups, a standardised test statistic is computed from the difference in mean ranks, scaled by a standard error that accounts for group sizes and the tie correction. The resulting $z$-values are compared to the normal distribution, with the significance threshold adjusted for the number of comparisons using the Bonferroni correction. Dunn's test is straightforward to apply and widely reported.
Conover's test (1999) uses the same ranks but frames each pairwise comparison as a two-sample $t$-test on the rank data, with a pooled error term derived from the overall rank variance. This approach tends to be more powerful than Dunn's test, particularly when group sizes are unequal, and yields $P$ values from the $t$-distribution with $n - k$ degrees of freedom.
Both tests control the family-wise error rate across all pairwise comparisons. Conover's test is generally preferred when maximum power is needed; Dunn's test is the more conservative and historically more common choice.
Worked Example
Fifteen patients with COPD are classified by disease severity (mild, moderate, or severe; five per group) and their six-minute walk distance (metres) is recorded:
| Mild | Moderate | Severe |
|---|---|---|
| 420 | 315 | 170 |
| 445 | 345 | 210 |
| 460 | 370 | 250 |
| 480 | 390 | 280 |
| 510 | 425 | 305 |
All 15 values are distinct, so there are no ties. Sorting them and assigning ranks:
| Value (m) | Group | Rank |
|---|---|---|
| 170 | Severe | 1 |
| 210 | Severe | 2 |
| 250 | Severe | 3 |
| 280 | Severe | 4 |
| 305 | Severe | 5 |
| 315 | Moderate | 6 |
| 345 | Moderate | 7 |
| 370 | Moderate | 8 |
| 390 | Moderate | 9 |
| 420 | Mild | 10 |
| 425 | Moderate | 11 |
| 445 | Mild | 12 |
| 460 | Mild | 13 |
| 480 | Mild | 14 |
| 510 | Mild | 15 |
The rank sums and mean ranks are:
| Rank sum $R_i$ | Mean rank $\bar{R}_i$ | |
|---|---|---|
| Mild | $10+12+13+14+15 = 64$ | $12.8$ |
| Moderate | $6+7+8+9+11 = 41$ | $8.2$ |
| Severe | $1+2+3+4+5 = 15$ | $3.0$ |
The H-statistic with $n = 15$ and $k = 3$ groups is:
$$ H = \frac{12}{15 \times 16}\left(\frac{64^2}{5} + \frac{41^2}{5} + \frac{15^2}{5}\right) - 3 \times 16 = 0.05 \times \frac{4096 + 1681 + 225}{5} - 48 = 0.05 \times 1200.4 - 48 = 12.02 $$There are no ties, so no correction is needed. With $\text{df} = 2$, the chi-squared table gives $P = 0.0025$.
Post-hoc pairwise comparisons (Conover's test) show that all three groups differ significantly from each other (mild vs moderate $P = 0.016$; mild vs severe $P < 0.001$; moderate vs severe $P = 0.016$). Six-minute walk distance decreases with increasing COPD severity, and the rank-based analysis confirms this gradient without requiring any distributional assumptions about the data.
MedCalc computes the Kruskal–Wallis test with both Dunn and Conover post-hoc comparisons in its Kruskal–Wallis test procedure.