Kruskal-Wallis Calculator

Comparing Three or More Groups Without Normality Assumptions

ANOVA compares three or more group means, but it leans on the assumption that each group's data is roughly normal with similar variance. When that assumption doesn't hold — skewed data, ordinal ratings, or the presence of outliers — the Kruskal-Wallis H test provides a rank-based alternative that tests whether the groups come from the same underlying distribution.

The Formula

H = [12 / (N(N+1))] × Σ(Ri² / ni) − 3(N+1), corrected for ties
where N = total observations, k = number of groups, Ri = sum of ranks in group i, ni = size of group i
df = k − 1, tested against the chi-square distribution

Worked Example

Three groups: (1, 2, 3), (4, 5, 6), (7, 8, 9) — a case with no overlap between groups at all.

Kruskal-Wallis H test result
QuantityValue
k (groups), N (total observations)3, 9
H statistic7.20
df2
p-value0.0273

Computed directly from the calculator's rank-sum formula and chi-square approximation.

With p = 0.027, below the conventional 0.05 threshold, the test correctly detects that these three non-overlapping groups don't share the same distribution.

Where This Calculation Matters

  • Comparing multiple treatment arms — when a study has three or more independent groups (e.g., three dosage levels or three marketing variants) and the outcome data is skewed or ordinal.
  • Small or unbalanced group sizes — rank-based tests are less sensitive to unequal variances across groups than standard ANOVA.
  • Screening before deeper analysis — a significant Kruskal-Wallis result indicates at least one group differs, prompting pairwise post-hoc rank tests such as Mann-Whitney U with a correction for multiple comparisons.

How to Use This Calculator

  1. Enter each group's values as a comma-separated list, with groups separated by semicolons (e.g., 1,2,3; 4,5,6; 7,8,9).
  2. Enter at least two groups, each with at least two values.
  3. Select Calculate to get the H statistic, degrees of freedom, and p-value.

Related Calculations

When group data is well-approximated by a normal distribution, use the parametric ANOVA Calculator instead. For comparing just two independent groups, see the Mann-Whitney U Test Calculator.

Principles of Nonparametric Analysis of Variance: The Kruskal-Wallis H-Test

A Kruskal-Wallis H calculator performs a rank-based nonparametric test to evaluate whether three or more independent groups originate from identical population distributions. Serving as the nonparametric counterpart to the One-Way Analysis of Variance (ANOVA), the Kruskal-Wallis test does not assume normal distribution of residuals or equal population variances (homoscedasticity).

The Fundamental Kruskal-Wallis H Formula

H = [ 12 / ( N · ( N + 1 ) ) ] · ∑j=1k [ Rj2 / nj ] - 3 · ( N + 1 )
Where k = Number of groups  |  nj = Sample size of group j  |  N = Total combined observations (∑ nj)  |  Rj = Sum of ranks for group j

Chi-Square (χ2) Approximation and Degrees of Freedom

When each group sample size nj ≥ 5, the test statistic H closely approximates a Chi-Square Distribution with Degrees of Freedom: df = k - 1.

  • If calculated H > χ2crit, reject the null hypothesis: at least one group stochastically dominates another.
  • Post-Hoc Analysis: Significant results are followed by Dunn's Multiple Comparison Test with Bonferroni Correction to identify specific group pair differences.

Step-by-Step Worked Calculation Example

Example: Comparing Exam Scores Across 3 Teaching Methods

Problem: Three teaching methods are tested (k = 3):
Group 1 (n1 = 3): [ 82, 88, 95 ]
Group 2 (n2 = 3): [ 70, 75, 78 ]
Group 3 (n3 = 3): [ 60, 65, 68 ]
Total N = 9. Test for significant method differences at α = 0.05 (χ2crit with df = 2 is 5.991).

Step 1: Pool and rank all 9 scores in ascending order:

60 (1), 65 (2), 68 (3), 70 (4), 75 (5), 78 (6), 82 (7), 88 (8), 95 (9).

Step 2: Sum ranks per group:

R1 = 7 + 8 + 9 = 24  |  R2 = 4 + 5 + 6 = 15  |  R3 = 1 + 2 + 3 = 6

Step 3: Calculate H Statistic:

Sum term = ( 242 / 3 ) + ( 152 / 3 ) + ( 62 / 3 ) = ( 576 / 3 ) + ( 225 / 3 ) + ( 36 / 3 ) = 192 + 75 + 12 = 279.0

H = [ 12 / ( 9 × 10 ) ] × 279 - 3( 10 ) = [ 12 / 90 ] × 279 - 30 = ( 0.1333 × 279 ) - 30 = 37.20 - 30 = 7.20

Step 4: Evaluate Statistical Significance:

Calculated H = 7.20 > Critical χ2 (5.991) &implies; Reject Null Hypothesis (p < 0.05)

Conclusion: Teaching methods produce statistically significant differences in student performance.

Tie-Corrected Kruskal-Wallis Test Statistic (Hcorrected)

When tied data values exist across multiple treatment groups, the unadjusted H statistic underestimates true significance. The test statistic is adjusted by dividing by the Tie Correction Multiplier (C):

C = 1 - [ ∑i=1g ( ti3 - ti ) / ( N3 - N ) ]
Hcorrected = H / C

Effect Size: Epsilon-Squared (ε2)

To measure the proportion of variance in ranks explained by the categorical independent grouping variable, statisticians compute Epsilon-Squared (ε2):

ε2 = ( H - k + 1 ) / ( N - k )
  • ε2 = 0.01 to 0.05: Small group effect.
  • ε2 = 0.06 to 0.13: Moderate group effect.
  • ε2 ≥ 0.14: Large statistical effect.

Post-Hoc Dunn's Test with Bonferroni Correction

When the omnibus Kruskal-Wallis test rejects the null hypothesis (p < 0.05), researchers perform Dunn's Post-Hoc Pairwise Comparisons with an adjusted alpha: αadjusted = 0.05 / [ k · ( k - 1 ) / 2 ].

Post-Hoc Pairwise Dunn-Bonferroni Test Matrix

Following a statistically significant Kruskal-Wallis result, researchers calculate standard error differences across rank sums to isolate which pairs differ:

Standard Error: SEi-j = √[ ( N · ( N + 1 ) / 12 ) · ( 1/ni + 1/nj ) ]
Pairwise Z-Score: Zi-j = ( R-bari - R-barj ) / SEi-j

Comparing calculated pairwise Z-values against the adjusted Bonferroni significance threshold identifies specific treatment group superiority.

Jonckheere-Terpstra Test for Ordered Alternatives

When independent groups possess an a priori natural monotonic ordering (such as Drug Dosages: 0 mg, 25 mg, 50 mg, 100 mg), the standard Kruskal-Wallis test tests only for general heterogeneity.

Biostatisticians instead utilize the Jonckheere-Terpstra Ordered Trend Test, which exhibits significantly higher statistical power for detecting directional dose-response relationships.

Comparison with the Parametric One-Way ANOVA F-Test

Statistical Feature Kruskal-Wallis H-Test (Nonparametric) One-Way ANOVA F-Test (Parametric)
Data Distribution Assumption Distribution-Free (No Normality Assumed) Assumes Normal Gaussian Distribution
Variance Homogeneity Robust against unequal group variances Requires equal group variances (Homoscedasticity)
Outlier Sensitivity Immune to extreme outlier values (Uses Ranks) Highly vulnerable to mean and variance skewing
Measurement Scale Ordinal, Ranked, or Continuous Data Continuous Interval or Ratio Data Only

Nonparametric Two-Way Factorial Extensions

While the standard Kruskal-Wallis test is strictly restricted to one-way independent groupings, researchers analyzing multi-factor factorial experiments with blocking employ:

  • Friedman's ANOVA Test: For two-way repeated measures or randomized complete block designs.
  • Scheirer-Ray-Hare Extension: A ranked two-way factorial ANOVA extension estimating main and interaction effects across multiple categorical factors.

Conover-Iman Post-Hoc Test Alternative

In statistical computing environments (R and Python SciPy), researchers frequently implement the Conover-Iman Post-Hoc Test following a significant Kruskal-Wallis result.

The Conover-Iman procedure leverages Student's t-distribution on rank-transformed data, offering slightly greater statistical power than standard Dunn's tests for discovering subtle pairwise group contrasts.

Visual Representation with Boxplots and Notches

Researchers visualize Kruskal-Wallis datasets using Notched Box-and-Whisker Plots. Non-overlapping 95% median notches across group boxes provide immediate visual evidence of statistically significant rank median differences.

Software Implementation in Python and R

In computational data science, the Kruskal-Wallis test is executed via scipy.stats.kruskal() in Python and kruskal.test() in base R.