Rank tests: Mann–Whitney, Wilcoxon and Kruskal–Wallis
H₀: neither group tends to give larger values · H₁: one group tends to give larger values
U = 47 · p = 0.0070
p = 0.0070 ≤ α = 0.05: reject H₀. One group tends to give larger values than chance alone would easily produce: a value from group 1 beats one from group 2 in 0.2089 of pairs.
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
Alternative hypothesis
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
| Group | n | median | mean rank |
|---|---|---|---|
| A | 15 | 5.3 | 11.1333 |
| B | 15 | 12 | 19.8667 |
The worked steps
Rank all the values together; R₁ is group 1's rank sum
n₁ = 15, n₂ = 15 · R₁ = 167The U statistic
U₁ = R₁ − n₁(n₁ + 1)/2 = 167 − 120 = 47 · U₂ = n₁ n₂ − U₁ = 178Mean and standard deviation of U under H₀ (tie-corrected)
μ_U = n₁ n₂ / 2 = 112.5 · σ_U = 24.1011The z statistic (with the continuity correction)
z = (U − μ_U − ½) / σ_U = 2.697The p-value
p = 2 × P(Z ≥ 2.697) = 0.0070Effect size (rank-biserial correlation)
r = 2 U₁ / (n₁ n₂) − 1 = -0.5822Chance a value from group 1 beats one from group 2
U₁ / (n₁ n₂) = 0.2089
The same in code
- scipy
from scipy import stats stats.mannwhitneyu(a, b, alternative='two-sided')- Excel (the normal approximation by formula)
=RANK.AVG(A2, $A$2:$A$100, 1) (rank every value together) =NORM.S.DIST(z, TRUE)
Formulas
U₁ counts the pairs in which the value from group 1 is the larger: about half of all pairs if the groups do not differ.
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.