Mann–Whitney U test
A rank-based test of whether values in one independent group tend to be larger than in the other.
What problem am I solving?
Does one group tend to score higher than another when the data are ordinal, like survey ratings, or full of outliers?
Why this method?
It only uses the ranks, so a few extreme values can’t dominate the result and it works for ordinal scales where a mean isn’t meaningful. Its natural effect size, the probability that a random value from one group beats a random value from the other, is easy to explain to non-statisticians.
Why not something else?
- Welch’s t-testBetter when the question really is about means, for example revenue, where totals matter and outliers are real money rather than noise.
- Brunner–Munzel testTests the same probability but stays valid when the two groups have different spreads or shapes. Worth switching to when the distributions clearly differ in more than location.
What has to be true?
- Observations are independent, within and between groups.
- Values can at least be ordered.
- It is not a test of medians. It only becomes one if both groups have the same shape and differ purely by a shift.
How it works
Pool both groups, rank every value, and add up the ranks of one group. If neither group tends to be larger, those ranks should be spread evenly. The U statistic, divided by , estimates
where and are random draws from the two groups. A value of 0.5 means neither group tends to be larger.
In code
from scipy import stats
res = stats.mannwhitneyu(group_a, group_b, alternative="two-sided")
prob_superiority = res.statistic / (len(group_a) * len(group_b))
Open questions
- How should ties be handled for 1 to 5 survey scales with many repeated values?
Compared against this in
References
- Divine et al. (2018), The Wilcoxon–Mann–Whitney procedure fails as a test of medians. The American Statistician.
- scipy.stats.mannwhitneyu