How to kruskal wallis test
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- It's a non-parametric test, meaning it doesn't assume data follows a specific distribution (like normal distribution).
- It compares the medians of three or more independent groups.
- It ranks all data points from all groups combined and then compares the sum of ranks for each group.
- The null hypothesis states that the medians of all groups are equal.
- The alternative hypothesis states that at least one group's median is different from the others.
What is the Kruskal-Wallis H Test?
The Kruskal-Wallis H test is a powerful, non-parametric statistical method used when you want to compare the medians of three or more independent groups. Imagine you're a researcher studying the effectiveness of different teaching methods on student test scores, or a doctor comparing the outcomes of patients on several different drug treatments. If your data doesn't meet the strict assumptions of parametric tests like the one-way ANOVA (such as the data being normally distributed within each group and having equal variances), the Kruskal-Wallis test becomes your go-to alternative.
The core idea behind the Kruskal-Wallis test is to rank all the data points from all the groups combined, from smallest to largest. It then calculates the sum of these ranks for each individual group. If the medians of the groups are truly different, you would expect the sum of ranks for those groups to be significantly different as well. The test then uses a statistic, often denoted as 'H', to determine if the observed differences in the sum of ranks are large enough to reject the null hypothesis.
When to Use the Kruskal-Wallis Test
The Kruskal-Wallis H test is particularly useful in several scenarios:
- Non-normally Distributed Data: When your data within each group is skewed or does not follow a normal distribution, especially with smaller sample sizes, this test is appropriate.
- Ordinal Data: It's suitable for analyzing ordinal data, where the data can be ranked but the intervals between ranks are not necessarily equal (e.g., survey responses like 'poor', 'fair', 'good', 'excellent').
- Unequal Sample Sizes: Unlike some other tests, the Kruskal-Wallis test can handle groups with different numbers of observations.
- When ANOVA Assumptions are Violated: If you've checked the assumptions for a one-way ANOVA (normality, homogeneity of variances) and found them to be violated, the Kruskal-Wallis test is a robust alternative.
How the Kruskal-Wallis Test Works (The Steps)
While statistical software performs these calculations for you, understanding the underlying process is beneficial:
- State the Hypotheses:
- Null Hypothesis (H₀): The medians of all groups are equal. (There is no difference between the groups.)
- Alternative Hypothesis (H₁): At least one group's median is different from the others.
- Combine and Rank Data: Pool all the observations from all the groups into a single dataset. Rank these pooled observations from the smallest value to the largest value. If there are tied values, assign the average rank to each tied observation.
- Calculate the Sum of Ranks for Each Group: For each group, sum the ranks that were assigned to the observations within that group. Let these sums be R₁, R₂, ..., Rk, where k is the number of groups.
- Calculate the Kruskal-Wallis H Statistic: The formula for the H statistic is:
$$ H = \frac{12}{N(N+1)} \sum_{i=1}^{k} \frac{R_i^2}{n_i} - 3(N+1) $$
Where:- N is the total number of observations across all groups.
- k is the number of groups.
- Rᵢ is the sum of ranks for the i-th group.
- nᵢ is the number of observations in the i-th group.
- Determine Statistical Significance: The calculated H statistic is compared to a critical value from the chi-squared (χ²) distribution with k-1 degrees of freedom. Alternatively, a p-value is calculated. If the p-value is less than your chosen significance level (e.g., α = 0.05), you reject the null hypothesis. This suggests that there is a statistically significant difference between the medians of at least two of the groups.
Interpreting the Results
If you reject the null hypothesis (i.e., your p-value is less than your significance level), it means there's a significant difference *somewhere* among the groups. However, the Kruskal-Wallis test itself doesn't tell you *which* specific groups are different from each other. To find this out, you need to perform post-hoc tests. Common post-hoc tests for Kruskal-Wallis include Dunn's test or pairwise Mann-Whitney U tests with a Bonferroni correction to control for multiple comparisons.
Limitations of the Kruskal-Wallis Test
While versatile, the Kruskal-Wallis test has some limitations:
- Less Powerful than ANOVA when Assumptions Met: If the assumptions for ANOVA are met, ANOVA is generally more powerful (more likely to detect a significant difference if one exists).
- Doesn't Specify Which Groups Differ: As mentioned, it requires post-hoc tests to identify specific group differences.
- Assumes Similar Shape of Distributions: While it doesn't assume normality, it does assume that the distributions of the groups have roughly the same shape and spread (scale). If the shapes are very different, the test might be misleading.
Example Scenario
Suppose a company wants to compare the customer satisfaction ratings (on a scale of 1-5) for three different versions of their website (Version A, Version B, Version C). The satisfaction ratings might not be normally distributed, especially if many customers give the highest rating. The Kruskal-Wallis test would be appropriate here. All ratings would be combined and ranked. The sums of ranks for customers using each version would be calculated, and the H statistic would determine if there's a significant difference in satisfaction across the three website versions.
Conclusion
The Kruskal-Wallis H test is an essential tool in a statistician's or researcher's toolkit, particularly when dealing with data that doesn't conform to the requirements of parametric tests. By ranking data and comparing rank sums, it provides a robust method for identifying differences among three or more independent groups without assuming specific data distributions.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
Missing an answer?
Suggest a question and we'll generate an answer for it.