Kruskal-Wallis Test Calculator
Perform a Kruskal-Wallis H test online to compare three or more independent groups. Get instant p-values, test statistics (H), tie correction, and detailed ranking steps.
What is the Kruskal-Wallis Test?
The Kruskal-Wallis H test (sometimes also called the "one-way ANOVA on ranks") is a non-parametric statistical test used to compare three or more independent groups. Unlike the standard one-way Analysis of Variance (ANOVA), the Kruskal-Wallis test does not assume that your data is normally distributed, making it an excellent alternative when dealing with skewed or ordinal data.
The test evaluates whether the medians of the groups are equal. It is essentially an extension of the Mann-Whitney U test (which compares only two independent groups) to three or more groups.
When Should You Use the Kruskal-Wallis Test?
You should choose the Kruskal-Wallis test when your study meets the following conditions:
- Three or More Groups: You are comparing three or more independent groups (e.g., three different study methods, four treatment groups, etc.).
- Independent Observations: The subjects in each group should be separate and not paired or matched (for paired subjects, use the Friedman test instead).
- Non-Normal Data: Your continuous outcome variable is not normally distributed, or your data is measured on an ordinal scale (e.g., Likert items like "Strongly Disagree" to "Strongly Agree" mapped to ranks).
Hypotheses of the Test
- Null Hypothesis ($H_0$): The population medians of all groups are equal. (i.e., there is no statistical difference between the groups).
- Alternative Hypothesis ($H_a$): At least one population median is different from the others.
How the Kruskal-Wallis Statistic ($H$) is Calculated
The calculation ranks all observations across all groups combined, from smallest (rank 1) to largest (rank $N$). If ties occur, they are assigned the average of the ranks they would have occupied. The formula for the test statistic $H$ is:
$$H = \frac{12}{N(N+1)} \sum_{i=1}^{k} \frac{R_i^2}{n_i} - 3(N+1)$$Where:
- $N$ = Total number of observations across all groups.
- $k$ = Number of groups.
- $R_i$ = Sum of ranks for the $i$-th group.
- $n_i$ = Sample size of the $i$-th group.
Tie Correction Factor
If there are many tied values, the test statistic $H$ is corrected by dividing it by a correction factor:
$$\text{Correction Factor} = 1 - \frac{\sum (t^3 - t)}{N^3 - N}$$Where $t$ is the number of observations tied for a particular value. The adjusted statistic is $H_{\text{adj}} = H / \text{Correction Factor}$. This value is then compared to a Chi-Square distribution with $df = k - 1$ degrees of freedom to obtain the p-value.
For related statistical measures, try the Standard Deviation Calculator and Variance Calculator.
Frequently Asked Questions
What is the difference between one-way ANOVA and the Kruskal-Wallis test?
One-way ANOVA is a parametric test that assumes the data is normally distributed and has equal variances across groups. The Kruskal-Wallis test is non-parametric, meaning it makes no assumptions about the distribution of the data. It works by ranking the data points rather than comparing their raw means.
What happens if the Kruskal-Wallis test is significant?
A significant Kruskal-Wallis test tells you that at least one group differs significantly from the others. However, it does not tell you *which* specific groups are different. To determine that, you must run a post-hoc test, such as Dunn's test, with a correction for multiple comparisons (like the Bonferroni correction).
Can Kruskal-Wallis be used for two groups?
Yes, although when comparing exactly two groups, the Kruskal-Wallis test is mathematically equivalent to the Mann-Whitney U test (Wilcoxon rank-sum test). It is standard practice to use the Mann-Whitney U test for two groups, and Kruskal-Wallis for three or more.
How do I interpret the p-value?
If the p-value is less than your chosen significance level (usually α = 0.05), you reject the null hypothesis and conclude that at least one group has a statistically different distribution of ranks. If the p-value is greater than α, you fail to reject the null hypothesis and conclude there is no statistically significant difference between the groups.