Kruskal-Wallis Test Calculator
Calculator
Learn More
Kruskal-Wallis Test
Definition
Kruskal-Wallis Test is a non-parametric method for testing whether samples originate from the same distribution. It's used to determine if there are statistically significant differences between two or more groups of an independent variable on a continuous or ordinal dependent variable. It extends the Mann–Whitney U test, which is used for comparing only two groups. The parametric equivalent of the Kruskal–Wallis test is the one-way analysis of variance(ANOVA).
A significant result indicates that at least one group differs from the others, but it doesn't identify which group is different. Post-hoc tests such as Dunn's test or pairwise Mann-Whitney U test with Bonferroni correction are often used to determine which groups are significantly different.
Test Statistic
Where:
- = total number of observations
- = number of observations in group
- = sum of ranks for group
- = number of groups
Tie Correction
where is the number of tied observations at rank .
The corrected test statistic is then calculated as:
Key Assumptions
Practical Example
Step 1: State the Data
Test scores from three groups:
- Group 1:
- Group 2:
- Group 3:
Step 2: State Hypotheses
- : The distributions are the same across groups
- : At least one group differs in distribution
Step 3: Calculate Ranks
Value | Rank | Group |
---|---|---|
5 | 1 | 1 |
6 | 2.5 | 1 |
6 | 2.5 | 2 |
7 | 4 | 1 |
8 | 6 | 1 |
8 | 6 | 2 |
8 | 6 | 3 |
9 | 8.5 | 2 |
9 | 8.5 | 3 |
10 | 10.5 | 2 |
10 | 10.5 | 3 |
Step 4: Calculate Rank Sums
- Group 1:
- Group 2:
- Group 3:
- Total number of observations:
Step 5: Calculate H Statistic
Here, tied ranks are:- (the tie occurs at rank 2)
Step 6: Draw Conclusion
Referring to the Chi-square distribution table, the critical value for with degrees of freedom at a significance level of is .
The p-value can be found using the Chi-square Distribution Calculator with and , which gives .
Since (critical value), we fail to reject . There is insufficient evidence to conclude that the distributions differ significantly across groups.
Effect Size
Epsilon-squared () measures the proportion of variability in ranks explained by groups:
Where:
- = Kruskal-Wallis statistic
- = total sample size
Interpretation guidelines:
For our example:
This indicates a medium effect size, suggesting a moderate practical significance in the differences between groups.
Code Examples
1library(tidyverse)
2# Creating the dataset
3data <- tibble(
4 Group = c(rep("Group 1", 4), rep("Group 2", 4), rep("Group 3", 3)),
5 Value = c(7, 8, 6, 5, 9, 10, 6, 8, 10, 9, 8)
6)
7
8# Kruskal-Wallis Test
9kruskal.test(Value ~ Group, data = data)
1import pandas as pd
2from scipy.stats import kruskal
3
4# Creating the dataset
5data = pd.DataFrame({
6 "Group": ["Group 1"] * 4 + ["Group 2"] * 4 + ["Group 3"] * 3,
7 "Value": [7, 8, 6, 5, 9, 10, 6, 8, 10, 9, 8]
8})
9
10# Splitting the data by group
11groups = [group["Value"].values for _, group in data.groupby("Group")]
12
13# Kruskal-Wallis Test
14stat, p_value = kruskal(*groups)
15
16# Displaying the results
17print(f"Kruskal-Wallis H-statistic: {stat}")
18print(f"p-value: {p_value}")
Alternative Tests
Consider these alternatives:
- One-way ANOVA: When normality and homogeneity of variance hold
- Median Test: Less powerful but more robust to outliers
- Jonckheere-Terpstra Test: When groups have natural ordering
Related Calculators
One-Way ANOVA Calculator
Mann-Whitney U Test Calculator
Friedman Test Calculator
Dunn's Test Calculator
Help us improve
Found an error or have a suggestion? Let us know!