Kruskal–Wallis Test Calculator
Enter the observations of three or four groups and this calculator runs the Kruskal–Wallis test: it ranks all values together, computes the tie-corrected H statistic, degrees of freedom, p-value and the decision at your chosen significance level.
Compare Three or More Groups by Ranks
Kruskal–Wallis Test Formula
Where:
- \(k\) — number of groups
- \(n_j\) — number of observations in group \(j\)
- \(N\) — total number of observations across all groups, \(N = \sum n_j\)
- \(R_j\) — sum of the ranks of group \(j\), where all \(N\) observations are ranked together from smallest (1) to largest (\(N\)), and tied values share the average of their ranks
- \(t\) — size of each group of tied values (used in the tie correction factor \(C\))
- \(\chi^2_{k-1}\) — chi-square distribution with \(k-1\) degrees of freedom
The statistic \(H\) compares the average rank of each group with the overall average rank \((N+1)/2\). If all groups come from the same distribution, every group should have a similar mean rank and \(H\) will be small; if one group tends to contain larger (or smaller) values, its mean rank departs from the average and \(H\) grows. Under the null hypothesis, \(H'\) approximately follows a chi-square distribution with \(k-1\) degrees of freedom, which yields the p-value.
Kruskal–Wallis Test – Calculation Example
Example: a researcher compares patient satisfaction scores (0–10) under three treatments. Group 1: 7; 8; 9; 9; 10. Group 2: 5; 6; 6; 7; 8. Group 3: 3; 4; 4; 5; 6; 7. Here \(k = 3\), \(N = 16\).
Ranking all 16 observations together (ties get average ranks) gives rank sums \(R_1 = 67.5\), \(R_2 = 41\), \(R_3 = 27.5\).
\[ H = \frac{12}{16 \cdot 17}\left(\frac{67.5^2}{5} + \frac{41^2}{5} + \frac{27.5^2}{6}\right) - 3 \cdot 17 = \frac{12}{272} \cdot 1373.4917 - 51 = 9.5952 \]
The data contain ties (six tie groups with sizes 2, 2, 3, 3, 2, 2), so \(\sum(t^3 - t) = 72\) and \(N^3 - N = 4080\):
\[ C = 1 - \frac{72}{4080} = 0.9824, \quad H' = \frac{9.5952}{0.9824} = 9.7674 \]
With \(\nu = k - 1 = 2\) degrees of freedom, the chi-square approximation gives \(p = 0.0076\).
Result: \(H' = 9.7674\), \(p = 0.0076 \le \alpha = 0.05\), so the null hypothesis is rejected — at least one treatment tends to produce different scores. Group 1 has the highest mean rank (13.5 vs the overall average of 8.5), indicating generally larger values.
How to use the calculator
- Enter the observations of your first group in Group 1 observations. Separate numbers with spaces, new lines or semicolons; decimal commas (e.g. 7,5) are accepted.
- Fill in Group 2 observations and Group 3 observations in the same format. All groups must measure the same variable on the same scale.
- If you have a fourth group, enter it in Group 4 observations (optional); leave it empty when comparing only three groups. Any group you leave empty is simply skipped.
- Set the Significance level (default 0.05) — the threshold below which the p-value counts as statistically significant.
- Press Calculate. You get the tie-corrected statistic \(H'\), the uncorrected \(H\), the degrees of freedom, the p-value, the decision at your chosen \(\alpha\), and a table with each group's size, rank sum, mean rank and median.
What the Kruskal–Wallis test is
The Kruskal–Wallis test is a nonparametric method for comparing three or more independent groups. It extends the Mann–Whitney U test (the two-group case) in the same way that one-way ANOVA extends the t-test. Instead of comparing group means, it pools all observations, replaces each value by its rank, and asks whether the ranks are distributed evenly across the groups. If one group systematically contains the largest values, its mean rank will sit well above the overall average rank of \((N+1)/2\), inflating the statistic \(H\).
Because the test works on ranks, it makes no assumption about the shape of the underlying distributions. It does not require normality, it tolerates skewed data, and it is robust to outliers — a single extreme value can distort a mean but only shifts a rank by a fixed amount. This makes it the standard alternative to a one-way ANOVA when the ANOVA assumptions (approximately normal residuals, similar variances) are doubtful, or when the data are ordinal ratings, ranks, or scores on an arbitrary scale. The logic of rank-based comparison is the same as in the Spearman rank correlation.
The null hypothesis states that all groups are drawn from the same distribution, i.e. no group tends to yield larger or smaller values than the others. A small p-value (at or below \(\alpha\)) means the observed rank differences are unlikely under random sampling, so you reject the null and conclude that at least one group differs. Note what the test does not tell you: which groups differ from which. For that, follow up with a post-hoc procedure such as Dunn's test, or pairwise Mann–Whitney U tests using a Bonferroni-adjusted threshold of \(\alpha / (k(k-1)/2)\). If you are unsure how to read the result, the p-value calculator explains the logic of significance testing in more detail.
The interpretation of medians deserves care. Strictly speaking, the Kruskal–Wallis test compares whole distributions (whether one group's values tend to dominate another's). It can be read as a comparison of medians only when the group distributions have roughly the same shape and spread. The calculator reports each group's median and mean rank so you can see where the differences come from, but the formal conclusion is always about the distributions, not a single summary statistic.
Assumptions, limitations and practical tips
- Independent samples. The groups must be unrelated (different subjects in each). For paired or repeated-measures designs the Kruskal–Wallis test is not appropriate — the Friedman test is the usual choice there.
- Independent observations within groups. Each value should come from a different subject or experimental unit; replicated measurements of the same unit inflate the effective sample size.
- Ordinal or continuous data. Values must at least be rankable. Nominal categories (colors, blood types) cannot be tested this way — use a chi-square test for categorical data instead.
- Chi-square approximation. The p-value comes from approximating \(H'\) with a \(\chi^2_{k-1}\) distribution. This works best when each group has at least 5 observations. With smaller groups, treat the p-value with caution; an exact or permutation-based method is preferable.
- Ties are handled correctly. Tied values receive average ranks and the statistic is adjusted by the correction factor \(C\), so moderate numbers of ties (common with rating scales) are not a problem. The calculator shows both \(H\) and the corrected \(H'\) so you can see the size of the adjustment.
- Similar distributions help interpretation. If the groups have clearly different shapes or variances, a significant \(H'\) reflects a difference in the whole distribution, not necessarily in location alone.
- Group sizes need not be equal. The formula accounts for unequal \(n_j\); only very small groups weaken the chi-square approximation.
Frequently Asked Questions
How do I calculate the Kruskal–Wallis H statistic by hand?
Start by ranking all N observations from all groups together, giving tied values the average of their ranks. Sum the ranks in each group to get \(R_j\), then apply \( H = \frac{12}{N(N+1)} \sum \frac{R_j^2}{n_j} - 3(N+1) \). If there are ties, divide H by the correction factor \( C = 1 - \sum(t^3 - t)/(N^3 - N) \). Compare \(H'\) to a chi-square distribution with \(k-1\) degrees of freedom to get the p-value. Check your manual work against the calculator's intermediate output.
What is a good or typical value of the Kruskal–Wallis H statistic?
There is no universal "good" value — H depends on the number of groups and total sample size. In general, H near 0 means the groups have very similar rank distributions, while larger H values point toward real differences. What matters is whether H exceeds the critical chi-square value at your degrees of freedom: with \(k=3\) groups (2 df), the 0.05 critical value is 5.991, so H′ above that is significant at the 5% level. Always read H together with its p-value.
Can I use the Kruskal–Wallis test with only two groups?
Technically it can be computed, but with two groups it is mathematically equivalent to a two-sided Mann–Whitney U test, and the dedicated Mann–Whitney test is the conventional choice. This calculator requires at least three filled groups. If you have only two groups, use a Mann–Whitney U calculator instead; if you have paired or repeated-measures data across conditions, the Kruskal–Wallis test is not appropriate at all — use the Friedman test.
How should I report Kruskal–Wallis results, for example in a paper?
A typical APA-style sentence is: "A Kruskal–Wallis test showed a statistically significant difference in satisfaction across the three treatments, \(H'(2) = 9.77\), \(p = .008\)." Include the corrected statistic with the tie correction applied, the degrees of freedom in parentheses, and the exact p-value. Report group sizes and medians (or mean ranks) so readers can see where differences lie, and mention any post-hoc comparisons, such as Dunn's test with adjusted p-values.
Does the Kruskal–Wallis test assume equal group sizes or equal variances?
No. The formula handles unequal group sizes \(n_j\) directly, and because the test works on ranks rather than raw values, it does not require equal variances or homoscedasticity the way ANOVA does. The main practical limit is the chi-square approximation, which becomes rough when a group has fewer than about 5 observations — in that case treat the p-value as approximate or use an exact/permutation method. Very unbalanced designs with tiny groups are the riskiest combination.
Why is my H′ larger than H, and does the tie correction matter?
The tie correction always shrinks the correction factor C below 1 when ties exist, so dividing by C can only increase the statistic: \(H' \ge H\). This compensates for the fact that ties make the data less informative and would otherwise deflate H. With many ties — typical on rating scales like 1–5 or 0–10 — the adjustment can change the p-value noticeably, occasionally moving a borderline result across your significance threshold. That is why the calculator reports both H and H′ so you can see the size of the effect.
What are common mistakes when using the Kruskal–Wallis test?
The most frequent errors are: using it on paired or repeated-measures data (use the Friedman test instead); entering the same subjects' measurements as separate groups; treating a significant result as proof that every group differs from every other (it only says at least one differs — run post-hoc tests such as Dunn's test); and claiming it compares medians when the group distributions have clearly different shapes. Also avoid mixing variables measured on different scales within one analysis, and remember that a large p-value is not proof the distributions are identical.