Kruskal-Wallis Test Calculator
Run a Kruskal-Wallis H test on up to four groups and get the statistic, degrees of freedom, and p value.
What it does
The Kruskal-Wallis test is the nonparametric answer to a one-way analysis of variance. It asks whether several independent groups come from the same distribution, without assuming that the data are normal. Instead of comparing means, it ranks every value from smallest to largest across all groups, then checks whether the rank sums are too different to be explained by chance.
The test is useful when the data are ordinal, when the sample is small, or when outliers would distort a mean. It is also common in biology, education, and survey work where a normal distribution is hard to justify. If the test is significant, at least one group tends to sit at a different part of the combined ranking, but the test does not say which one.
The statistic H grows when the group rank sums differ from what equal groups would produce. With three groups of five, the average rank sum under the null is 40 for each group. A group with a much larger or smaller sum pushes H up. The p value comes from the chi-square distribution with k minus 1 degrees of freedom, which is an approximation that works best when each group has more than four values.
Ties matter. If two or more values are equal, they share the average of the ranks they would have received. That reduces the variance of the rank sums, so the raw H is slightly too small. The correction divides H by a factor C that is less than 1, which raises H a little. With many ties, the difference can change a conclusion near the 5 percent line.
This page accepts up to four groups as comma-separated text. It ranks the combined data, applies the tie correction, and returns H, the degrees of freedom, and the p value. It also reports the decision at the 5 percent level. A significant result should be followed by a post hoc comparison with a multiplicity adjustment, because running many pairwise tests without one inflates the false positive rate.
How to use
- Enter the raw values for each group, separated by commas or spaces.
- Leave group 3 or group 4 blank if you do not need them.
- Check that every group has at least 2 values and that the total is at least 5.
- Read H, the degrees of freedom, and the p value.
- If p is below your cutoff, run a post hoc test to find which groups differ.
- Report the group sizes, the medians, H, df, and p so the result can be checked.
Formula
- N
- Total number of values across all groups.
- k
- Number of groups.
- ni
- Number of values in group i.
- Ri
- Sum of ranks for group i.
- t
- Number of values tied at one rank.
- C
- Tie correction factor, at most 1.
The p value uses the chi-square distribution with k - 1 degrees of freedom. The approximation is usually acceptable when each group has more than four values. The tie correction sums t cubed minus t over every tied set, then divides by N cubed minus N. If there are no ties, C equals 1 and the corrected H equals the raw H. The test assumes independent groups and similar distribution shapes; a significant result points to a difference in location, not necessarily in median alone.
Worked example
Example: three groups of five values
Group 1 is 18, 20, 22, 24, 26. Group 2 is 10, 12, 14, 16, 18. Group 3 is 2, 4, 6, 8, 10.
- Combine and rank all 15 values. The two 10s share rank 5.5, and the two 18s share rank 10.5.
- Rank sums: group 1 = 64.5, group 2 = 40, group 3 = 15.5.
- Compute the sum of Ri squared over ni: 832.05 + 320 + 48.05 = 1200.1.
- Raw H = 12 / (15 x 16) x 1200.1 - 3 x 16 = 12.005.
- Tie correction C = 1 - 12 / 3360 = 0.9964.
- Corrected H = 12.005 / 0.9964 = 12.05.
- With 2 degrees of freedom, p = 0.002, so reject the null at the 5 percent level.
Reference table
| Degrees of freedom | 5 % critical value | 1 % critical value |
|---|---|---|
| 1 | 3.841 | 6.635 |
| 2 | 5.991 | 9.210 |
| 3 | 7.815 | 11.345 |
| 4 | 9.488 | 13.277 |
Limits
- The chi-square approximation is weak when groups are very small.
- The test compares distributions, and a significant result does not identify which group differs.
- The test assumes independent groups, not paired or repeated measures.
- It is sensitive to differences in distribution shape, not only to medians.
Common mistakes
- Entering ranks instead of raw values.
- Using k degrees of freedom instead of k minus 1.
- Skipping the tie correction when many values are equal.
- Running several pairwise tests after a significant H without adjusting for multiplicity.
- Treating a non-significant result as proof that all groups are identical.
Try it yourself
Quick checks. Answers sit tucked under each question.
Group A is 1, 2, 3 and group B is 4, 5, 6. What are H and p?
Ranks are 1 to 6. Rank sums are 6 and 15. H = 3.857, displayed as 3.86, with df = 1. The p value is 0.0495, displayed as 0.05, so reject at the 5 percent level.
Group A and group B both contain 10, 12, 14. What is H?
Every rank sum is equal, so H = 0 and p = 1. The tie correction does not change the conclusion.
Group A is 1, 1, 1 and group B is 2, 2, 2. What is H?
Raw H = 3.857, tie correction C = 0.7714, corrected H = 5.00, df = 1, p = 0.025, so reject at 5 percent.
Questions
When should I use Kruskal-Wallis?
When you compare two or more independent groups and cannot assume normal distributions, or when the data are ordinal.
What are the assumptions?
Independent groups, at least ordinal data, and similar distribution shapes if you want to describe the result as a median difference.
How do I enter the data?
Put raw values in each group box, separated by commas or spaces. Do not enter ranks.
What does the p value mean?
It is the probability of an H at least this large if all groups came from the same distribution.
What if the test is significant?
Run a post hoc comparison such as Dunn's test with a multiplicity adjustment to find which groups differ.
Can I use it for two groups?
Yes, but the Mann-Whitney U test is the more common choice for two independent groups.