Mann-Whitney U test (Wilcoxon rank-sum test)
Tests whether values in one of two independent groups tend to be higher than in the other, using ranks instead of raw values. Used for skewed measurements and ordered scores.
Statistically reviewed by Daniel Wolff on 5 November 2026.
Clinical example
A pain score from 0 to 10 compared between two randomized treatment arms. Each patient is in one arm only, and the scores have many ties.
When to use it
- The outcome is a skewed measurement or an ordered score such as a pain score.
- You compare exactly two groups, and each patient is in only one of them.
- You want to know whether a patient from one group tends to have a higher value than a patient from the other. That is often the right question for an ordered score.
- For a skewed measurement where the mean matters (length of stay or costs: total bed days, budget), Welch's t-test with enough patients, a bootstrap CI or a log transform answers the actual question better.
- You don't need to adjust for other variables. In observational comparisons, such as between wards, case mix is usually a confounder.
Assumptions to check
Independent observations
One value per patient. Repeated measurements or clustered patients need a mixed model.
It tests whether values tend to be higher
The test asks whether the probability that a patient from one group has a higher value than a patient from the other differs from one half. It is a comparison of medians only when the two distributions have a similar shape. Groups with different distributions but a probability of one half, for example the same median and a very different spread, are not detected (Divine et al. 2018).
Not robust to unequal spreads
With clearly different spreads and unequal group sizes, the false-positive rate is off when the test is read as 'tends to be higher'. The Brunner-Munzel test handles this.
Check first
- Consider a log transform first if the data are right-skewed and you also plan regression analyses; keep one approach throughout the paper
What to report
- Median with interquartile range, and the number of patients analyzed, per group, and a box plot or dot plot of both groups so that readers can see whether the shapes are similar
- The probability of superiority, U / (n1 × n2), with a 95% CI. For example: a patient in arm A has a 64% chance of a higher score than a patient in arm B (ties count half)
- The Hodges-Lehmann estimate with 95% CI, if the shapes are similar, and its direction (which group minus which). It is the median of all pairwise differences between the groups, and only a 'shift' when the shapes are similar
- The exact p-value, and whether it is exact or a normal approximation (with ties it is always approximate)
Common mistakes
Don't run a normality test to decide
With small samples it rarely flags a problem; with large ones it flags harmless deviations. Look at the histograms and think about the measurement instead.
Be careful treating a score as a measurement
The steps of an ordinal score aren't necessarily equal. Means and t-tests assume they are.
'The medians differ' when the shapes differ
A significant result can occur with equal medians, and the other way round. Say that values in one group tend to be higher.
It is not a non-parametric t-test
The test does not compare means.
Not a fix for unequal spreads
It is not robust to unequal spreads. Use Welch's t-test for means, or the Brunner-Munzel test.
Not for paired data
Use the Wilcoxon signed-rank test for the same patients measured twice.
A shift only when the shapes are similar
Reporting the Hodges-Lehmann estimate as a 'shift', or as the difference in medians, when the distributions clearly have different shapes.
Unadjusted comparisons are not quality differences
Differences in case mix between wards drive length of stay. An unadjusted test cannot support a conclusion about quality of care.
Alternatives
| If your situation is… | Use |
|---|---|
| Roughly symmetric data or larger groups, and the mean is what matters (a bootstrap CI for the mean difference is another option) | Welch's t-test |
| Skewed, always-positive measurement and the mean matters (ratio of geometric means) | Unpaired t-test on log-transformed data |
| Skewed measurement and you need to adjust for other variables (regression on the log scale, or quantile regression for medians) | Linear regression |
| Ordered score and you need to adjust for other variables | Proportional odds (ordinal logistic) regression |
| Same patients measured twice | Wilcoxon signed-rank test |
| Three or more groups | Kruskal-Wallis test |
| Patients are clustered | Linear mixed model |
In your software
# R (the same test as the Wilcoxon rank-sum test)
d$arm <- factor(d$arm, levels = c("control", "treatment")) # the order sets the direction
# exact = FALSE: with ties an exact p-value and CI cannot be computed, and without it R warns
res <- wilcox.test(pain ~ arm, data = d, conf.int = TRUE, exact = FALSE)
res # W is the Mann-Whitney U of the first group.
# "difference in location" is the Hodges-Lehmann estimate (the median of all
# pairwise differences), not the difference in medians
tapply(d$pain, d$arm, quantile, c(.25, .5, .75), na.rm = TRUE) # median and IQR per group
# probability of superiority (ties count half), with a bootstrap 95% CI
d2 <- d[complete.cases(d$pain, d$arm), ]
ps <- function(x, y) mean(outer(x, y, ">") + 0.5 * outer(x, y, "=="))
x <- d2$pain[d2$arm == "control"]; y <- d2$pain[d2$arm == "treatment"]
ps(x, y)
set.seed(1)
boot <- replicate(2000, ps(sample(x, replace = TRUE), sample(y, replace = TRUE)))
quantile(boot, c(0.025, 0.975))
* NPTESTS shows its results in the model viewer: double-click it to see U, Z and the p-value.
* The grouping variable must have measurement level nominal or ordinal, or NPTESTS does not run.
* EXAMINE gives the medians and quartiles per group.
EXAMINE VARIABLES=pain BY arm
/PLOT=BOXPLOT
/STATISTICS=DESCRIPTIVES
/PERCENTILES(25,50,75) HAVERAGE.
NPTESTS
/INDEPENDENT TEST (pain) GROUP (arm) MANN_WHITNEY.