How to run a Kruskal-Wallis test
- Copy a group name column and a measurement column together with the header.
- Select the response and group columns. The Dunn post hoc test is included by default, and you can choose the p-value correction.
- Press Analyze and check the p-value in the test summary and the 'Significant' rows of the Dunn post hoc test.
Worked example with sample data
The sample data are 10 cycle times (s) measured on each of 3 assembly lines. The Line column is the group column and the Cycle time column the response column.
The test summary shows H = 13.02 (2 degrees of freedom) and a p-value of 0.001491, so the cycle time distributions of the three lines differ significantly. The mean ranks are 11.5 for Line 1, 23.7 for Line 2 and 11.3 for Line 3 - only Line 2 stands out.
The Dunn post hoc test (Bonferroni correction) shows Line 1-Line 2 (p=0.005829) and Line 2-Line 3 (p=0.004905) as significant, while Line 1-Line 3 has p=1 and does not differ. In other words, Line 2 alone is slower.
The box plot shows one far-off high value on every line (skewness 1.97 to 2.29) that pulls the mean up. For data like this, the rank-based Kruskal-Wallis test is less affected by outliers than one-way ANOVA. Line 2's median of 47 s is about 5 s longer than the other lines (41.9 and 42.15 s), so its work allocation and equipment settings are worth comparing.
How it is calculated
All values are ranked together, H = 12/(N(N+1))·Σ(Ri²/ni) - 3(N+1) is computed from the rank sums of the groups, and a tie correction is applied. H is tested against the chi-square distribution with (number of groups - 1) degrees of freedom (the same as SciPy's kruskal).
Dunn post hoc test
For each pair of groups, the difference in mean ranks is divided by its standard error (with tie correction) to get z and a two-sided p-value, which is corrected for multiple comparisons with Bonferroni, Holm or Benjamini-Hochberg (FDR) (the same as scikit-posthocs).
What the result shows
Descriptive statistics by group (N, median, mean rank), the test summary, the Dunn post hoc test, a box plot, a violin plot, a dot plot and the medians with confidence intervals.
How to read the Kruskal-Wallis test result
- If the p-value is below the significance level, the location of at least one group's distribution differs. See the Dunn post hoc table for which pairs differ.
- A larger mean rank means the group has larger values overall.
- The intervals in the median + confidence interval chart are each group's own distribution-free interval, so a pair can be significant in the post hoc test even if the intervals overlap.
Frequently asked questions
How is it different from one-way ANOVA?
ANOVA compares means and assumes normality and equal variances; Kruskal-Wallis compares ranks and needs no such assumptions. Use it when the distributions are skewed or contain outliers.
What if I have 2 groups?
With 2 groups, use the Mann-Whitney test. This tool needs 3 or more groups.
Which correction should I choose?
Bonferroni is the most conservative, and Holm keeps the same error rate while being less conservative. In an exploratory stage, Benjamini-Hochberg (FDR) can also be used.