Probability & Statistics

Mann-Whitney U Test

Count cross-sample wins and ties, then compare U with every indexed allocation of two small samples.

By Riano · Published · Updated · Report a correction

Mann-Whitney U Test

The Mann-Whitney U Test (also known as the Wilcoxon rank-sum test) is a non-parametric statistical test used to compare two independent samples. The exact allocation model used here assumes an exchangeable equal-distribution null: the six indexed observations can be assigned to the two independent groups with equal probability. The weaker condition that wins and losses are equally likely alone does not justify this permutation calibration. Unlike the t-test, it does not assume that the data follows a normal distribution.

Worked Example

Let's consider an example with two samples of size 3: Sample A = {10, 20, 30} and Sample B = {15, 25, 35}.

First, we compute the U statistic for Sample A, UA, by comparing every element in A to every element in B. For a pair (a, b), we count 1 if a > b, and 0.5 if a = b.

a \ b152535
10000
20100
30110

Summing these values, UA = 0 + 0 + 0 + 1 + 0 + 0 + 1 + 1 + 0 = 3.

The maximum possible U value for two samples of size nA and nB is nA * nB = 3 * 3 = 9. Thus, UB = 9 - UA = 9 - 3 = 6.

Next, we enumerate all possible ways to allocate these 6 distinct values into two groups of 3. There are (6 choose 3) = 20 possible assignments. For assignment, we can compute the U statistic. Under the exchangeable equal-distribution null hypothesis, each of these 20 assignments is equally likely.

For our observed allocation, UA = 3. The expected U value is 4.5. The absolute extremeness is |UA - 4.5| = |3 - 4.5| = 1.5. Counting the allocations out of the 20 that have an absolute extremeness greater than or equal to 1.5, we find exactly 14 such assignments. The exact two-sided p-value is therefore 14 / 20 = 7/10 (0.7).

Experiment

In the interactive module, you can explore the Mann-Whitney U test with two small samples of size 3.

  1. First, choose an option from the Sample preset select control, such as Separated, Interlaced, or Partial ties, to set the dataset configurations.
  2. Observe the generated 3x3 comparison grid counting wins and ties for every pair (a in A, b in B). Watch the exact 20-allocation distribution of the U statistic render as a graph, highlighting the extremeness of the observed value compared to the null distribution. Note that the equivalent average-rank sum is computationally identical to the U test without replacing tied permutation weights by distinct-value counts.

Limitations

The interpretation of the Mann-Whitney U test is often stated as a test of medians, but a pure median interpretation requires the additional assumption that the two population distributions have identical shapes (i.e., differ only by a shift). Without this shape assumption, use the equal-distribution null and the declared rank-based statistic; the result is not by itself a general test or proof of stochastic dominance.

While exact enumeration works well for very small sample sizes (like 3+3 = 6 observations yielding 20 allocations), the number of indexed allocations grows combinatorially with larger sample sizes. Larger problems may use specialized exact algorithms, asymptotic approximations or a separately qualified Monte Carlo permutation method.

References

The primary reference for the statistical definition of the Mann-Whitney U test used in this module is the SciPy library documentation.

Experience it interactively

Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Mann-Whitney U Test module.

Try Mann-Whitney U Test on Riano →

More in Probability & Statistics