The Mann-Whitney U test (also called the Wilcoxon rank-sum test) compares two independent groups without assuming a normal distribution. It asks whether a randomly chosen value from one group tends to be larger than a randomly chosen value from the other. It is the rank-based partner of the two-sample t-test and is the usual choice for skewed data, outliers and ordinal ratings.
The procedure:
The statistic. Pool both groups, rank every value from smallest to largest, and let $R_1$ be the sum of the ranks of group 1. The U statistic for each group counts, over all pairs with one value from each group, how often that group's value is the larger one, with ties counted as one half:
The two always add to $n_1n_2$, and the test statistic is the smaller of them. If the groups do not differ, $U$ is centred at $n_1n_2/2$; a very small or very large value signals that one group tends to be larger.
Worked example. This continues the etch-rate data from the non-parametric overview. Recipe A gives $10.1,\,10.8,\,11.2,\,11.6,\,12.0,\,12.4$ and recipe B gives $11.9,\,12.6,\,13.1,\,13.5,\,14.2,\,41.0$. In the pooled ranking, A holds ranks $1,2,3,4,6,7$ with $R_1=23$, so $U_1=23-21=2$ and $U_2=36-2=34$. Recipe B beat recipe A in $34$ of the $36$ possible pairs.
With $6$ wafers per group there are $\binom{12}{6}=924$ equally likely ways the ranks could split between groups if the recipes did not differ. Only $4$ of them give $U\le2$, with counts $1,\,1,\,2$ for $U=0,1,2$, and by symmetry another $4$ give $U\ge34$. The exact two-sided p-value is $8/924\approx0.0087$, which matches scipy.
Large samples. Counting becomes impractical as the groups grow, so software switches to a normal approximation with mean and standard deviation:
For the example $\mu_U=18$ and $\sigma_U\approx6.245$, so $z\approx-2.56$ and the two-sided p-value is $0.0104$ (or $0.0131$ with a continuity correction), a little further from the exact $0.0087$. With ties, $\sigma_U$ also needs a tie correction.
Effect size: say how big, not just whether. Two rank-based measures read directly off $U$. The probability of superiority is $U_2/(n_1n_2)=34/36\approx0.944$: a random B wafer beats a random A wafer $94\%$ of the time, where $50\%$ means no difference. The rank-biserial correlation $(U_2-U_1)/(n_1n_2)\approx0.889$ rescales the same information to $-1$ to $+1$. If a shift in the original units is wanted, the Hodges-Lehmann estimate is the median of all pairwise differences $b-a$, which is $1.9$ here.
Reading the result.
- What it tests: whether one group tends to produce larger values. It tests a difference in medians only if the two distributions have the same shape, differing by a shift.
- Unequal spread: if the groups differ in spread as well as location, a significant result can reflect either. Look at the data, not just the p-value.
- Ties: many ties, as with 1-to-5 ratings, reduce the number of distinct ranks and need a tie correction; software applies it automatically.
- Independent groups only: for before-and-after values on the same wafers use the Wilcoxon signed-rank test, and for three or more groups use Kruskal-Wallis.
- Power: on perfectly normal data it loses only about $5\%$ efficiency relative to the t-test, and on heavy-tailed data it can win by a wide margin.
Read the Mann-Whitney U as a head-to-head count: of all pairs formed by one measurement from each group, how often does each side win, and is that split more lopsided than shuffled ranks would produce?