EZ Statistics

Kruskal-Wallis Test Calculator

Calculator

2. Select Columns & Options

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

H=12N(N+1)i=1kRi2ni3(N+1)H = \frac{12}{N(N+1)}\sum_{i=1}^k \frac{R_i^2}{n_i} - 3(N+1)

Where:

  • NN = total number of observations
  • nin_i = number of observations in group ii
  • RiR_i = sum of ranks for group ii
  • kk = number of groups

Tie Correction

T=1j(tj3tj)N3NT = 1 - \frac{\sum_{j}(t_j^3 - t_j)}{N^3 - N}

where tjt_j is the number of tied observations at rank jj.

The corrected test statistic is then calculated as:

Hcorrected=HTH_{\text{corrected}} = \frac{H}{T}

Key Assumptions

Independent Samples: Groups must be independent
Ordinal Data: Variable should be ordinal or continuous
Similar Shape: Distributions should have similar shapes

Practical Example

Step 1: State the Data

Test scores from three groups:

  • Group 1: 7,8,6,57, 8, 6, 5
  • Group 2: 9,10,6,89, 10, 6, 8
  • Group 3: 10,9,810, 9, 8
Step 2: State Hypotheses
  • H0H_0: The distributions are the same across groups
  • HaH_a: At least one group differs in distribution
  • α=0.05\alpha = 0.05
Step 3: Calculate Ranks
ValueRankGroup
511
62.51
62.52
741
861
862
863
98.52
98.53
1010.52
1010.53
Step 4: Calculate Rank Sums
  • Group 1: R1=13.5 (n1=4)R_1 = 13.5\ (n_1 = 4)
  • Group 2: R2=27.5 (n2=4)R_2 = 27.5\ (n_2 = 4)
  • Group 3: R3=25 (n3=3)R_3 = 25\ (n_3 = 3)
  • Total number of observations: N=11N = 11
Step 5: Calculate H Statistic
H=1211(12)(13.524+27.524+2523)3(12)=4.269H = \frac{12}{11(12)}\left(\frac{13.5^2}{4} + \frac{27.5^2}{4} + \frac{25^2}{3}\right) - 3(12) = 4.269Here, tied ranks are:
  • t2=2t_2 = 2 (the tie occurs at rank 2)
  • t6=3t_6 = 3
  • t8=2t_8 = 2
  • t10=2t_{10} = 2
The tie correction is:T=1(232)+(333)+(232)+(232)11311=0.968T = 1 - \frac{(2^3 - 2) + (3^3 - 3) + (2^3 - 2) + (2^3 - 2)}{11^3 - 11} = 0.968The corrected test statistic is:Hcorrected=4.2690.968=4.4092H_{\text{corrected}} = \frac{4.269}{0.968} = 4.4092
Step 6: Draw Conclusion

Referring to the Chi-square distribution table, the critical value for χ2\chi^2 with df=2df = 2 degrees of freedom at a significance level of α=0.05\alpha = 0.05 is 5.9915.991.

The p-value can be found using the Chi-square Distribution Calculator with df=2df = 2 and χ2=4.4092\chi^2 = 4.4092, which gives p=0.1103p = 0.1103.

Since H=4.4092<5.991H = 4.4092 < 5.991 (critical value), we fail to reject H0H_0. There is insufficient evidence to conclude that the distributions differ significantly across groups.

Effect Size

Epsilon-squared (ε2\varepsilon^2) measures the proportion of variability in ranks explained by groups:

ε2=Hn21\varepsilon^2 = \frac{H}{n^2-1}

Where:

  • HH = Kruskal-Wallis HH statistic
  • nn = total sample size

Interpretation guidelines:

  • Small effect: ε20.010.04\text{Small effect: }\varepsilon^2 \approx 0.01 - 0.04
  • Medium effect: ε20.040.16\text{Medium effect: }\varepsilon^2 \approx 0.04 - 0.16
  • Large effect: ε20.16\text{Large effect: }\varepsilon^2 \geq 0.16

For our example:

ε2=5.9911121=5.991120=0.050\varepsilon^2 = \frac{5.991}{11^2-1} = \frac{5.991}{120} = 0.050

This indicates a medium effect size, suggesting a moderate practical significance in the differences between groups.

Code Examples

R
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)
Python
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!