Kruskal-Wallis Test Calculator
Hypothesis tests
- Rank sums 55, 40 and 25 over group sizes 5, 5 and 5 give sum of R squared over n = 1,050.00.
- Kruskal-Wallis H: 12 / (15 x 16) x 1,050.00 - 3 x 16 = 4.50.
- With 2 degrees of freedom the chi-square tail is exp(-H / 2) = 0.1054.
- Mean ranks are 11.0, 8.0 and 5.0; H = 4.50 with p = 0.1054.
Three groups, data that are skewed, ordinal or outlier-ridden - the one-way ANOVA's assumptions are gone but the question remains: do the groups differ? The Kruskal-Wallis test answers it on ranks. Pool everything, rank it, sum the ranks within each group, and ask whether the sums are more unequal than chance shuffling would make them. The H statistic that results is ANOVA's logic transplanted onto ranks, with a chi-square reference distribution.
Enter the three groups' sizes and rank sums. The calculator returns H, the chi-square p-value on 2 degrees of freedom, the groups' mean ranks and the total number of observations. The Mann-Whitney page on this site is the two-group relative; the Friedman page covers the blocked design where the same subjects meet every condition.
Worked examples
Rank sums 55/40/25, H 4.50
(5 · 5 · 5 · 55 · 40 · 25)
| H statistic | 4.50 |
| p-value (chi-square, df 2) | 0.1054 |
| Mean ranks | 11.0, 8.0, 5.0 |
| Total observations | 15 |
Rank sums 75/57/39, H 3.79
(6 · 6 · 6 · 75 · 57 · 39)
| H statistic | 3.79 |
| p-value (chi-square, df 2) | 0.1504 |
| Mean ranks | 12.5, 9.5, 6.5 |
| Total observations | 18 |
Rank sums 58/40/22, H 14.08
(4 · 5 · 6 · 58 · 40 · 22)
| H statistic | 14.08 |
| p-value (chi-square, df 2) | 0.0009 |
| Mean ranks | 14.5, 8.0, 3.7 |
| Total observations | 15 |
ANOVA on ranks
The statistic is H = 12/(N(N+1)) x sum(R_i squared / n_i) - 3(N+1): a scaled variance of the group mean ranks. If the groups are exchangeable, each mean rank hovers near (N+1)/2 and H stays small; if one group hoards the high ranks, its squared term swells and H follows.
With three groups the reference distribution is chi-square on 2 degrees of freedom, whose tail has the exact closed form exp(-H/2) - so the p-values on this page are not approximations of the tail, they are the tail, given H.
Ranks tame what breaks ANOVA: a single wild observation becomes merely the largest rank, and skewed distributions become uniform ones. The price is power when the data really are normal - about 95 % efficiency - which most practitioners gladly pay for the insurance.
- H = 12/(N(N+1)) sum(R_i^2/n_i) - 3(N+1)
- Reference: chi-square with k - 1 = 2 degrees of freedom
- For df 2 the p-value is exactly exp(-H/2)
- Rank sums must total N(N+1)/2 - a built-in audit
Worked examples: three comparisons
Three groups of 5, rank sums 55, 40, 25 (totalling 120 = 15 x 16/2, as they must). Sum of R squared over n is 1,050.00, and H = 12/(15 x 16) x 1,050.00 - 48 = 4.50. The p-value is exp(-4.50/2) = 0.1054, and the mean ranks are 11.0, 8.0 and 5.0. A visible spread that chance produces about a tenth of the time - suggestive, not established.
Three groups of 6, rank sums 75, 57, 39: H = 3.79, p = 0.1504, mean ranks 12.5, 9.5 and 6.5 over 18 observations. More data than the first example, a smaller H - the rank profiles are simply closer together.
Unequal groups of 4, 5 and 6, rank sums 58, 40, 22: H = 14.08, p = 0.0009, mean ranks 14.5, 8.0 and 3.7. The smallest group hoards the top ranks (its mean rank of 14.5 out of 15 possible is near the ceiling) and the test fires decisively. Group size is no protection against a real separation.
The mean ranks exactly as printed: 11.0, 8.0, 5.0 in the first example; 12.5, 9.5, 6.5 in the second; 14.5, 8.0, 3.7 in the third.
The rank-sum identity
Every Kruskal-Wallis calculation carries a built-in audit: the rank sums must total N(N+1)/2. The examples check out - 55 + 40 + 25 = 120, 75 + 57 + 39 = 171 = 18 x 19/2, 58 + 40 + 22 = 120. A set of rank sums failing this identity is wrong before the statistic is computed; the commonest cause is ranking within groups instead of across the pooled sample.
The H formula audits itself at the null too: if every group's mean rank equals (N+1)/2 exactly, each term collapses and H returns 0. Deviations from that centre, weighted by group size, are the entire statistic.
Keep both checks beside any software output; they catch the two errors (wrong ranking pool, mistyped sums) that account for nearly every wrong H in practice.
What the test does and does not say
A significant H says the distributions differ - strictly, that one group stochastically dominates another somewhere. The comfortable translation 'the medians differ' needs an extra assumption: same-shaped distributions across groups, differing only by shift. With similar shapes it is fair; with wildly different spreads, H can fire on shape alone.
It also says nothing about which groups differ. Post-hoc pairwise comparisons (Dunn's test with a multiplicity adjustment) are the standard sequel, and running unadjusted Mann-Whitney tests on every pair spends the error rate the omnibus test just protected.
Read the three examples as the three verdicts: 0.1054 and 0.1504 say 'not established at these sizes', 0.0009 says 'established'. The mean ranks printed with each result show where the separation lives - in the third example, unmistakably in the first group.
Ties, shapes and small samples
Tied values share the average of the ranks they span, which shrinks the rank variance and biases H slightly downward; the standard correction divides H by a factor built from the tie structure. With few ties the correction is cosmetic; with heavily tied data - Likert scales, rounded measurements - it is the difference between a conservative and a correct p-value. This page's examples use untied rank sums, so the printed H is the uncorrected statistic.
Small samples coarsen the chi-square reference: below about 5 per group, exact or permutation p-values earn their keep. The third example's smallest group has 4 - its p of 0.0009 is so far past any threshold that the coarseness cannot rescue the null, which is the right way to read borderline machinery: worry about approximation near the line, not far from it.
Balanced designs behave best, but the third example shows unequal groups (4, 5, 6) working exactly as designed - the formula's n_i denominators are the whole secret.
Kruskal-Wallis in the wild
The test's natural habitats are the places ANOVA's assumptions go to die: patient-reported outcome scores across treatment arms, Likert-scale survey comparisons across departments, environmental concentrations across sites with detection-limit censoring, and any small-sample comparison where a single outlier would own a parametric analysis.
In each habitat the reporting pattern is the same: medians and ranges per group for the descriptive claim, H with its degrees of freedom and p-value for the test, and Dunn comparisons if the omnibus test fires. This page supplies the middle of that pattern; the rest lives in the study itself.
A closing caution from the field: because the test is assumption-light, it is often run as a reflex on data that would have supported ANOVA and yielded estimates in original units. Ranks answer 'do they differ' elegantly and 'by how much' not at all - if the second question matters, plan the analysis that can answer it.
Designing with ranks in mind
Because the test works on ranks, its power depends on the ordering information the measurement carries: coarse ordinal scales with heavy ties spend power, while continuous measurements ranked finely keep nearly all of it. Choosing a finer outcome measure at design time is worth more than any analysis-time refinement.
The examples trace the sample-size logic: 15 observations split evenly produced H 4.50 (p 0.1054); 18 produced a smaller H on closer profiles; 15 again, with a near-ceiling mean rank of 14.5 in one group, produced 14.08 (p 0.0009). It is the separation of the rank profiles, not the headcount, that the statistic prices.
Sample-size folklore: below about 5 per group the chi-square approximation coarsens and exact or permutation p-values earn their keep - except, as the third example shows, when the effect is so large that no reasonable approximation rescues the null.
One sentence to carry away
Rank everything together, ask whether the rank sums are too unequal for chance, and report the mean ranks beside the p-value - that is the whole test, and the examples show it needs nothing more. The mean ranks (11.0, 8.0, 5.0 in the first example) are the descriptive heart; H and its p-value are the certification wrapped around them.
Used that way - description first, certification second - the Kruskal-Wallis test is among the most honest instruments in the applied statistics toolkit: it assumes little, it audits itself through the rank-sum identity, and it refuses, at small samples, to say more than the ranks contain.
A note on what to do with a borderline result like the first example's p of 0.1054: the honest options are more data or a sharper question, not a different test shopped for a smaller p. The rank profile (mean ranks 11.0, 8.0, 5.0) suggests where a larger study should look, and a pre-registered follow-up with adequate group sizes converts the suggestion into evidence. Rank tests reward patience exactly because they refuse to manufacture certainty at small n - the refusal is the feature.
FAQs
What H do rank sums 55, 40, 25 in groups of 5 give?
4.50, p 0.1054.
What about rank sums 75, 57, 39 in groups of 6?
H 3.79, p 0.1504.
And rank sums 58, 40, 22 in groups of 4, 5, 6?
H 14.08, p 0.0009.
How many observations are in the first example?
15, in three groups of 5.
What are the mean ranks of the first example?
11.0, 8.0 and 5.0.
Why is the p-value exact here?
Chi-square on 2 degrees of freedom tails as exp(-H/2).