Mann-Whitney U Test
Question: Are the distributions of two independent groups significantly different? (Equivalently: if you randomly pick one observation from each group, what's the probability that group A's value exceeds group B's?)
Use it when: Two independent groups, normality is violated. This is the nonparametric analog of the independent t-test. Sometimes called the Wilcoxon rank-sum test — note: different from the Wilcoxon signed-rank test.
How it works:
- Combine all observations and rank them in ascending order (average ranks for ties).
- Sum the ranks for each group separately.
- Compute U statistics from the rank sums; take the smaller as the test statistic.
In Python: scipy.stats.mannwhitneyu(group1, group2)
Pool all observations from both groups into one list and sort them from smallest to largest. Assign ranks 1, 2, 3… to each value. When two values tie, average their ranks.
| Position | Group | Value (ms) | Rank |
|---|---|---|---|
| 1 | Treatment | 186 | 1 |
| 2 | Treatment | 188 | 2 |
| 3 | Treatment | 193 | 3 |
| 4 | Treatment | 195 | 4 |
| 5 | Treatment | 197 | 5 |
| 6 | Control | 198 | 6 |
| 7 | Treatment | 200 | 7 |
| 8 | Treatment | 201 | 8 |
| 9 | Treatment | 204 | 9 |
| 10 | Control | 205 | 10 |
| 11 | Treatment | 208 | 11 |
| 12 | Control | 210 | 12 |
| 13 | Treatment | 212 | 13 |
| 14 | Control | 215 | 14 |
| 15 | Control | 220 | 15 |
| 16 | Control | 228 | 16 |
| 17 | Control | 231 | 17 |
| 18 | Control | 235 | 18 |
| 19 | Control | 242 | 19 |
| 20 | Control | 249 | 20 |
Walk through the three steps of the Mann-Whitney U test on real data. Switch datasets to see how the combined ranks and U statistics change.
Don't Confuse The Two
The Wilcoxon signed-rank test is for paired data. The Wilcoxon rank-sum test (Mann-Whitney U) is for independent groups. They share a name and similar mechanics but answer different questions. Check which one you need before running.