Explore

Rank tests: Mann–Whitney, Wilcoxon and Kruskal–Wallis

H₀: no group tends to give larger values · H₁: at least one group does

H = 42.6032 · df = 3 · p = 2.99E-9

p = 2.99E-9 ≤ α = 0.05: reject H₀. At least one group tends to give larger or smaller values than the others (H = 42.6032); after Holm's correction, 3 of 6 pairs differ. ε² = 0.0085 says how much of the ranks' variation the groups explain.

How to read the picture

  • For small samples without ties the bars are the exact null distribution of the rank statistic; otherwise the curve is its normal (or χ²) approximation.

  • The vertical line is your statistic; the highlighted bars or the shaded area are the p-value.

  • Kruskal–Wallis's H lands on the χ² curve with k − 1 degrees of freedom.

  • The tables show the ranks behind the statistic.

Your data

Test

Data

Download this dataset (CSV)

Significance level α

A rank test replaces each value by its place in the sorted data, so one huge value counts as the largest and no more. Mann–Whitney compares two independent groups, Wilcoxon's signed-rank test compares paired measurements, and Kruskal–Wallis compares several groups. They ask whether one group tends to give larger values, not whether the means differ.

The estimate and what the data show

Each group's size, median and mean rank
Groupnmedianmean rank
London16892488.12491.3993
Midlands13182097.0952305.736
North10791796.352183.3489
Scotland5771896.742203.3778
Pairwise Mann–Whitney tests with Holm's correction
PairpHolm-adjusted pp ≤ α
London − Midlands0.00010.0006✓
London − North5.96E-93.57E-8✓
London − Scotland9.12E-64.56E-5✓
Midlands − North0.02320.0696✗
Midlands − Scotland0.12480.2496✗
North − Scotland0.76120.7612✗

The worked steps

  1. Rank all the values together, then add each group's ranks

    R(London) = 4207973.5 · R(Midlands) = 3038960 · R(North) = 2355833.5 · R(Scotland) = 1271349
  2. The H statistic

    H = 12 / (N(N + 1)) × Σ Rᵢ² / nᵢ − 3(N + 1) = 42.6032, N = 4663
  3. Correct for ties

    H = 42.6032 / 1 = 42.6032
  4. Degrees of freedom

    df = k − 1 = 3
  5. The p-value

    p = P(χ² ≥ 42.6032) = 2.99E-9
  6. Critical value at α

    α = 0.05: H* = 7.8147
  7. Effect size (ε²)

    ε² = (H − k + 1) / (N − k) = 0.0085

The same in code

scipy
from scipy import stats

stats.kruskal(a, b, c, d)
statsmodels: Holm's correction on the pairwise p-values
from statsmodels.stats.multitest import multipletests

multipletests(pairwise_p, alpha=0.05, method='holm')
Excel has no Kruskal–Wallis test: rank the pooled values with RANK.AVG, compute H by formula and read the tail with CHISQ.DIST.RT.

Formulas

Rank all the values together; if the groups do not differ, each group's average rank sits near the overall average, and H stays small.

Try this

  1. One huge value

    Open the small exact sample and change the last value of the second group from 7.7 to 770.

    Look for: The mean of the second group jumps, but its ranks do not move: U and the p-value stay exactly the same. That is what a rank test buys you.

  2. Three tests, three questions

    Open Meridian's claim amounts by tier here, then the two-means explorer on the same claims.

    Look for: Mann–Whitney asks whether one tier tends to give larger claims (not clearly: p = 0.148); Welch on the raw amounts asks about the arithmetic means, which differ. Different questions, different answers.

  3. After Kruskal–Wallis

    Open Meridian's regions and read the pairwise table.

    Look for: Six pairs are compared, so each p-value is adjusted with Holm's method before it is read against α: three of the six pairs survive.

An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to Hypothesis Testing Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.