Chip Foundry Services Request Assessment

Kruskal-Wallis

The Kruskal-Wallis test compares three or more independent groups using ranks instead of raw values. It is the rank-based counterpart of one-way ANOVA. Rather than asking whether group means differ, it asks whether the groups tend to produce larger or smaller values than one another, which makes it robust to outliers, skewed distributions and ordinal scores.

The sequence:

Three or more independent groups
numeric or ordinal outcome, unsure about normality
Rank all N values togetherthe rank analogue of one-way ANOVA
Sum ranks in each group
R1, R2, ..., Rk
Compare group mean ranks
with the overall mean rank (N + 1) / 2
H statistic
large H means ranks cluster by group
Significant H: which groups differ?
follow up with Dunn's test, adjusted for multiple comparisons

The statistic. Pool all $N$ observations and rank them from $1$ to $N$. If group $j$ has $n_j$ observations and rank sum $R_j$, the Kruskal-Wallis statistic measures how far the group rank sums stray from what chance would give:

$$H=\frac{12}{N(N+1)}\sum_{j=1}^{k}\frac{R_j^2}{n_j}-3(N+1)$$

If the groups do not differ, every group's average rank should sit near $(N+1)/2$. Under the null hypothesis and with reasonably large groups, $H$ approximately follows a chi-square distribution with $k-1$ degrees of freedom. With tied values, software divides $H$ by a tie-correction factor.

Worked example. Return to the three etch recipes from the ANOVA entries, with measurements $12,14,13$ (A), $15,17,16,18$ (B), and $20,19,21,22,23$ (C). Pooled, the twelve values take ranks $1$ to $12$, with no ties. The rank sums are $R_A=6$, $R_B=22$, $R_C=50$, which add up to $12\cdot13/2=78$, and the mean ranks are $2,\,5.5,\,10$ against the no-difference expectation of $6.5$. Then:

$$H=\frac{12}{12\cdot13}\left(\frac{6^2}{3}+\frac{22^2}{4}+\frac{50^2}{5}\right)-3(13)=\frac{12}{156}(12+121+500)-39\approx9.69$$

On $k-1=2$ degrees of freedom, the $5\%$ critical value is $5.991$ and the chi-square approximation gives $p=0.0079$. The result matches scipy.

Kruskal-Wallis compares each group's average rank 12 wafers pooled and ranked 1 to 12; three etch recipes 1 2 3 4 5 6 7 8 9 10 11 12 pooled rank (1 = smallest etch shift, 12 = largest) expected mean rank if no difference = 6.5 Recipe A mean rank 2 Recipe B mean rank 5.5 Recipe C mean rank 10 H = 9.69 on 2 df; chi-square approximation p = 0.0079; exact p = 6 / 27720 = 0.0002 complete separation: the three recipes occupy different stretches of the ranking

An important caveat about small groups. With only $3$, $4$ and $5$ wafers the chi-square approximation is rough. Enumerating all $12!/(3!\,4!\,5!)=27{,}720$ ways to deal the ranks into groups of those sizes finds only $6$ with $H\ge9.69$, an exact p-value of $0.0002$. Here the approximation is conservative, but the lesson is general: with tiny groups use an exact or permutation p-value if software offers it.

Effect size and robustness. The epsilon-squared effect size $\varepsilon^2=H/(N-1)\approx0.881$ gives the share of rank variability tied to group membership. The test is also stable under outliers: replace $23$ with $230$ and it is still the largest value, so $H$ stays $9.69$. The ordinary ANOVA, however, drops from $p=0.00007$ to $p=0.462$ because the outlier inflates the within-group variance.

After a significant result. Kruskal-Wallis says only that some groups differ. To find which, run pairwise comparisons such as Dunn's test, which uses the same pooled ranks, and adjust the p-values with Holm or Bonferroni as in the multiple-comparison entries. The Mann-Whitney test run separately on each pair is also acceptable if adjusted.

Reading the result.

  • What is tested: whether the groups differ in their tendency to produce larger values. It becomes a test of medians only if the group distributions have the same shape.
  • Order alternatives: if the groups have a natural order, such as increasing temperature, the Jonckheere-Terpstra test is more powerful than the general Kruskal-Wallis test.
  • Repeated measures: when the same units are measured under every condition, use the Friedman test, not this one.
  • Two groups: with $k=2$ it reduces to the Mann-Whitney U test.
  • Independence: observations must be independent of one another within and between groups.

Read Kruskal-Wallis as asking whether the groups are shuffled together in the ranking or stacked in separate stretches of it; the more the average ranks spread apart, the larger $H$ becomes.