🔬  Mann–Whitney U Test (also called the Wilcoxon rank-sum test)

Mann–Whitney U Test (also called the Wilcoxon rank-sum test)#

A nonparametric, rank-based test of whether one group’s values tend to exceed another’s.

Important

✨ AI-generated content. This page was written with the assistance of an AI language model and is provided as a learning aid. Despite careful review, it may still contain mistakes, omissions, or out-of-date information. Whether you are new to the topic, a team lead, or a senior practitioner, treat it as a starting point rather than an authoritative reference: read it critically and independently verify anything you act on (code, commands, figures, and factual claims) against official documentation and primary sources before relying on it.

What it is#

The Mann–Whitney U test (equivalently the Wilcoxon rank-sum test) is a non-parametric test for whether two independent groups come from the same distribution. Unlike the t-test it makes no normality assumption — it works on the ranks of the pooled data, so it is the natural choice for skewed or ordinal data.

Assumptions#

  • The two samples are independent.

  • The outcome is ordinal or continuous.

  • Strictly, it tests stochastic dominance (whether one group tends to be larger); only when the two distributions have the same shape does it become a test of medians.

The U statistic#

Pool both groups, rank everything, and sum the ranks of each group (\(R_1, R_2\)). Then

\[U_1 = n_1 n_2 + \frac{n_1(n_1 + 1)}{2} - R_1, \qquad U_2 = n_1 n_2 + \frac{n_2(n_2 + 1)}{2} - R_2, \qquad U = \min(U_1, U_2).\]

For large samples \(U\) is approximately normal, giving a z-based p-value.

Hypotheses#

  • H₀ — the two groups come from the same distribution.

  • H₁ — one group tends to produce larger (or smaller) values than the other.

Worked example#

Group A = {88, 92, 100, 75, 85}, Group B = {60, 70, 65, 80, 72}. Rank all ten values, sum the ranks, compute \(U\), and look up the p-value; \(p < 0.05\) means the groups differ significantly.

from scipy.stats import mannwhitneyu

U, p = mannwhitneyu(group_a, group_b, alternative="two-sided")

Pitfalls and edge cases#

  • Ties — many tied values need a tie correction (most libraries apply one).

  • The “median” shortcut — only valid under equal-shape distributions; otherwise report it as a test of stochastic dominance.

  • Paired data — for matched samples use the Wilcoxon signed-rank test instead; this test is for independent groups.


Theme: Model Evaluation & Uncertainty  ·  All terminology



See also

Source article Adapted (context, re-expressed) in our own words from: Mann–Whitney U Test (also called the Wilcoxon rank-sum test) (insightful-data-lab.com).

Tags: purpose: reference topic: terminology level: intermediate