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.
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
| Group | n | median | mean rank |
|---|---|---|---|
| London | 1689 | 2488.1 | 2491.3993 |
| Midlands | 1318 | 2097.095 | 2305.736 |
| North | 1079 | 1796.35 | 2183.3489 |
| Scotland | 577 | 1896.74 | 2203.3778 |
| Pair | p | Holm-adjusted p | p ≤ α |
|---|---|---|---|
| London − Midlands | 0.0001 | 0.0006 | ✓ |
| London − North | 5.96E-9 | 3.57E-8 | ✓ |
| London − Scotland | 9.12E-6 | 4.56E-5 | ✓ |
| Midlands − North | 0.0232 | 0.0696 | ✗ |
| Midlands − Scotland | 0.1248 | 0.2496 | ✗ |
| North − Scotland | 0.7612 | 0.7612 | ✗ |
The worked steps
Rank all the values together, then add each group's ranks
R(London) = 4207973.5 · R(Midlands) = 3038960 · R(North) = 2355833.5 · R(Scotland) = 1271349The H statistic
H = 12 / (N(N + 1)) × Σ Rᵢ² / nᵢ − 3(N + 1) = 42.6032, N = 4663Correct for ties
H = 42.6032 / 1 = 42.6032Degrees of freedom
df = k − 1 = 3The p-value
p = P(χ² ≥ 42.6032) = 2.99E-9Critical value at α
α = 0.05: H* = 7.8147Effect 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')
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
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.
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.
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.