Understand the idea
This test extends the Mann-Whitney comparison of two groups to THREE OR MORE independent groups. Rather than working with the raw numbers, it pools every observation from every group together, ranks them from lowest to highest, and asks whether the average rank in each group differs more than pure chance would produce. Because it only ever uses ranks, it makes no assumption that the underlying data follow a bell curve.
A significant result tells you that AT LEAST ONE group tends to rank differently from the others: it does not by itself tell you WHICH group. Dunn's test, a follow-up comparison of every pair of groups with a correction for running many comparisons at once, is what pinpoints exactly which groups differ.
The test reports TWO different effect-size measures side by side, and this is worth understanding: epsilon-squared does NOT sit at zero when groups truly do not differ; pure chance alone pushes it toward (k-1)/(N-1), which can look surprisingly 'large' with many small groups. Eta-squared-H subtracts that chance level first, so it centers on zero when there's truly no effect, and it can even go slightly BELOW zero (not an error, just meaning the groups differ even less than pure chance would produce, exactly like a negative adjusted R-squared).
The Kruskal-Wallis test is also called the Kruskal-Wallis H test, after its test statistic H.
Practitioner explanation
KernelStats computes H = (12/(N(N+1)))*sum(R_i^2/n_i) - 3(N+1), df=k-1, via scipy.stats.kruskal, with TWO effect sizes reported together: epsilon-squared = H(N+1)/(N^2-1), and eta-squared-H = (H-k+1)/(N-k), which the product explains is deliberately provided as a SECOND measure specifically because epsilon-squared's expected value under the null is (k-1)/(N-1), not zero; with 10 groups of 3 observations each, that chance level is already about 0.31, enough for pure noise to earn a 'large' epsilon-squared label. Eta-squared-H subtracts this chance baseline and CAN legitimately go below zero (meaning the groups differ even less than chance alone would produce), matching R's rstatix::kruskal_effsize() convention, and the product states this is not an error and should be read as 'no effect beyond chance', analogous to a negative adjusted R-squared.
The degenerate case where the pooled response is perfectly constant (every value identical, zero variance) is handled honestly: H becomes a genuine 0/0 and both H and its p-value are reported as UNDEFINED (matching R's kruskal.test, which returns NaN on the same input), rather than letting a computed NaN silently leak into the headline, the APA text, and a fabricated 'large' effect-size label next to a 'no difference' verdict, a specific, previously-fixed defect the product now guards against explicitly.
Dunn's test (pairwise rank comparisons with Bonferroni correction) runs automatically as the default post-hoc when H is significant, but is DELIBERATELY SKIPPED above 50 groups, with the reason stated directly: 51 groups implies 1,275 pairwise comparisons each held to a vanishingly tiny Bonferroni threshold, and that many groups usually signals the 'grouping' column is actually an ID (a subject, sample, or order number) rather than a genuine categorical factor, a data-quality inference baked directly into the post-hoc gating logic.
When to use it
Consider it when
Comparing three or more INDEPENDENT groups on a continuous or ordinal response when normality is doubtful, samples are small, or outliers are present.
Use caution when
Data are roughly normal (one-way ANOVA is more powerful in that case), exactly two groups are being compared (use Mann-Whitney), the same subjects were measured repeatedly across conditions (use Friedman, not Kruskal-Wallis, since this test assumes independent groups), or the grouping column has more than 50 distinct levels, likely signaling an ID column rather than a real factor.
Formulas and symbols
Kruskal-Wallis H statistic
N total sample size, k groups, R_i the rank sum in group i, n_i group i's size. Under H0, H ~ chi-square(k-1).
Epsilon-squared
Proportion of rank variance explained; expected value under H0 is (k-1)/(N-1), NOT zero, which can look inflated with many small groups.
Eta-squared-H (chance-corrected)
Subtracts the chance-level baseline so it centers on 0 under H0; can legitimately be negative.
Assumptions and checks
- Independence of observations. Kruskal-Wallis assumes groups and observations are independent; violating this invalidates the test regardless of the shape check.
In KernelStats: Not checked by KernelStats: assumed from the study design; stated directly as a standing reminder.
- Kruskal-Wallis's result is always a valid test of whether at least one group tends to rank higher than the others, but it can only be read as a difference in MEDIANS specifically when the groups' distributions have similar shape and spread; markedly different spreads make the median interpretation misleading even though the test itself remains valid.
In KernelStats: Checked directly: the card compares the groups' spreads via a Brown-Forsythe-style test and flags a material, statistically-supported difference in spread as a warning against the median interpretation, reported honestly as 'assumed, not checked' when a group is too small or has zero spread to compare.
Alternatives
- One-Way ANOVA. The data are roughly normal, where the parametric ANOVA is more powerful than the rank-based alternative.
- Mann-Whitney U Test. Exactly two groups are being compared rather than three or more.
- Friedman Test. The same subjects or matched blocks were measured under every condition (related, not independent, groups).
Worked example
Scenario
Comparing body mass across three penguin species (151, 68, 123 birds respectively).
Result
H(2) = 217.6, p < .001; epsilon-squared = 0.64; eta-squared-H = 0.64 (closely matching epsilon-squared at this sample size); Dunn's post-hoc (Bonferroni) finds Gentoo different from both Adelie and Chinstrap (p < .001), but Adelie versus Chinstrap is not significant (adjusted p = 1.00; mean ranks differ by under 6).
Interpretation
With a reasonably large sample and only three groups, epsilon-squared and eta-squared-H agree closely, both confirming a large effect, and the post-hoc comparisons show exactly where it lives: Gentoo is heavier than the other two, while Adelie and Chinstrap are indistinguishable in body mass. A significant omnibus test never implies that every pair differs.
Dataset: penguins.csv
Common misconceptions
Misconception
An epsilon-squared of 0.30 always represents a genuinely large effect, the way a Cohen's benchmark table suggests.
Correction
Epsilon-squared does NOT average zero when groups truly do not differ: under the null hypothesis its expected value is (k-1)/(N-1), which with many small groups can already sit well above the conventional 'large' threshold from pure chance alone. Eta-squared-H, which subtracts this chance baseline, is the more honest measure to read when there are many groups relative to the sample size.
Misconception
A negative eta-squared-H value means the calculation is broken.
Correction
Eta-squared-H can legitimately go slightly below zero because it subtracts the chance-level baseline before scaling: a negative value simply means the groups differ even LESS than pure chance would typically produce, directly analogous to a negative adjusted R-squared. It is not an error and should be read as 'no effect beyond chance'.
References
- Use of ranks in one-criterion variance analysis, Kruskal, W. H. and Wallis, W. A. (1952), Journal of the American Statistical Association, 47(260), 583-621.
- Multiple comparisons using rank sums, Dunn, O. J. (1964), Technometrics, 6(3), 241-252.
