The Kruskal-Wallis test is a nonparametric method for comparing three or more independent groups when a one-way ANOVA is not appropriate. It is especially useful when the response variable is ordinal, strongly skewed, or affected by outliers. This cheat sheet helps students identify when to use the test, compute the test statistic, and interpret results correctly.
It also connects the test to post hoc comparisons after a significant result.
The core idea is to rank all observations together, then compare the average ranks across groups. If the groups come from similar distributions, their rank averages should be close. The main statistic is , with a tie correction when needed.
Under the null hypothesis and typical large-sample conditions, is compared to a chi-square distribution with .
Key Facts
- Use the Kruskal-Wallis test to compare independent groups when the response is ordinal or a continuous variable that does not meet ANOVA assumptions.
- The null hypothesis is : all groups have the same distribution, often interpreted as equal population medians when group distributions have similar shapes.
- The alternative hypothesis is : at least one group tends to have larger or smaller values than at least one other group.
- Rank all observations from smallest to largest across all groups, assigning average ranks to tied values.
- For group , let be the group size and be the sum of ranks in that group.
- The Kruskal-Wallis statistic is .
- When ties occur, use the corrected statistic , where is the size of tie group .
- For large enough samples, compare or to and reject when the -value is less than .
Vocabulary
- Kruskal-Wallis test
- A nonparametric hypothesis test used to compare three or more independent groups using ranks instead of raw data values.
- Rank sum
- The rank sum is the total of all ranks assigned to observations in group .
- Degrees of freedom
- For the Kruskal-Wallis test, the degrees of freedom are , where is the number of groups.
- Tie correction
- A tie correction adjusts the statistic when equal data values create tied ranks.
- Post hoc comparison
- A post hoc comparison tests which specific group pairs differ after the overall Kruskal-Wallis test is significant.
- Nonparametric test
- A nonparametric test makes fewer assumptions about the population distribution than a parametric test such as ANOVA.
Common Mistakes to Avoid
- Using Kruskal-Wallis for paired or repeated-measures data is wrong because the test assumes independent groups. Use a related-samples method such as the Friedman test when the same subjects are measured repeatedly.
- Interpreting a significant result as proof that all group medians are different is wrong because the test only shows that at least one group differs in distribution or location.
- Forgetting to rank all observations together is wrong because ranks must be assigned across the full combined sample, not separately within each group.
- Ignoring ties can give an inaccurate test statistic because tied values reduce the variability of ranks. Apply the tie-corrected statistic when ties are present.
- Running many pairwise tests without adjustment is wrong because it inflates the Type I error rate. Use a correction such as Bonferroni, Holm, or Dunn's test with adjusted -values.
Practice Questions
- 1 Three independent groups have , , , and rank sums , , . Compute .
- 2 A Kruskal-Wallis test compares independent groups and gives . What are the degrees of freedom, and how would you use to find or approximate the -value?
- 3 A data set has observations with one tie group of size and another tie group of size . Compute the tie correction denominator factor .
- 4 A researcher compares exam scores from three different classes and finds a significant Kruskal-Wallis result. Explain why this result does not by itself identify which classes differ.
Understanding Kruskal-Wallis Test Reference
A valid analysis begins with the study design. Each observation must come from only one group, and one person or item must not influence another observation. For example, scores from three separate classes can be independent if no student appears twice.
Scores measured from the same students before, during, and after a course are not independent. Those repeated measurements need a different method, such as the Friedman test.
Random sampling or random assignment still matters. A rank based test can handle unusual data shapes, but it cannot repair a biased sample or a poorly controlled experiment.
The interpretation depends on the shapes of the group distributions. When groups have roughly similar spread and shape, a difference in ranks is often described as a difference in typical value or median. If one group is much more spread out, has a long tail, or has two clusters, the result may reflect those broader distribution differences instead.
This is an important limit. A significant result does not automatically prove that one group has a higher median. Students should inspect dot plots, box plots, or histograms before making a claim about medians.
Ranks reduce the effect of extreme values because only order matters. A very large value receives the highest rank, but its exact distance above the next value does not affect the calculation. Ties need care because equal values should receive equal treatment.
Their ranks are averaged, then the correction adjusts for the loss of rank variation caused by many ties. This issue is common with rating scales such as one to five satisfaction scores.
Software usually applies the correction automatically, but students should know that a large number of ties can make the usual large sample approximation less reliable. For small samples, an exact or permutation based p value can be more appropriate when available.
A significant overall result only says that the full set of groups is unlikely to have produced such rank differences by chance under the no difference model. It does not identify the groups responsible. Follow up pairwise rank comparisons can locate the differences.
These comparisons need a multiple testing adjustment, such as Bonferroni or Holm, because testing many pairs raises the chance of a false positive. In a report, include group sizes, a summary of each group, the test statistic, degrees of freedom, p value, and the post hoc method.
Reporting an effect size, such as epsilon squared, helps show whether the difference is practically important rather than merely statistically detectable. A tiny effect can have a small p value when the sample is large.