Mann-Whitney U Test (go to the calculator)

Mann-Whitney U test calculator

The Mann-Whitney U test, also called the Wilcoxon rank-sum test, is a non-parametric test. It checks continuous or ordinal data for a significant difference between two independent groups. The test merges the data from the two groups. Then, it sorts the data by the value. Unlike the t-test that compares the groups' averages, the rank test compares the entire distributions.
When the two groups' distributions have a similar shape, the test will also compare the median of each group.
For symmetrical distribution, the median is the average.

When to use?

The test usually comes as a failsafe option to a Two-sample T-test or Two-sample Z-test when the test doesn't meet the normality assumption or contains many outliers.
A t-test compares the means of the two groups, while a Mann-Whitney U test compares the ranks. If the two groups have a similar distribution curve, the test will also compare the medians of the two groups.
A Two-sample T-test is slightly stronger than a Mann-Whitney U Test. A Mann-Whitney U test has 95% efficiency in comparison to a Two-sample T-test. If the population is similar to a normal distribution and reasonably symmetric, it is better to use a Two-sample T-test. A Two-sample T-test compares the means of the two groups

What does a higher rank mean?

Higher rank, Ri, for group i (lower Ui), says that the probability to get higher value from this group is higher.
Following an example:

RB > RC, μB < μC.
The rank of group B, 108, is greater than the rank of group C, 63. But the mean of group B, 20, is less than the mean of group C, 65.67.
There is a high probability that a random value from group B will be greater than random value from group C, but if you repeat this process 20 times, most likely you will accumulate a greater total from group C.

MedA = MedB, RB > RA.
The median of group A, 20, equals to the median of group B, 20. But the rank of group B, 101.5, is greater than the rank of group A, 69.5. There is a high probability that the random value from group B will be greater than the random value from group A.

GroupValuesAverageMedianRank over
ABC
A01,02,03,04,20,21,22,23,2413.332069.580
B14,15,17,19,20,31,32,33,3524.0020101.5108
C13,13,13,13,13,13,13,200,30065.67139163

Assumptions

U Calculation

Calculation method

Exact

Calculated the distribution, p(U<u), under the null assumption of equal probability to get higher value from Group1 or to get higher value from Group2. It calculates the U for all the combinations:
$$p(U = u) = \frac{Combination\ with\ U=u}{All\ combinations}$$ The method requires high calculation power, the calculation duration grows exponentially to the total sample size (n1 + n2).
The calculation is accurate only when the data does not have ties. The tool uses pre-calculated data to save performance time.

Corrected normal approximation

To get more accurate results, the tool uses the ties corrections, and optionally use the continuity correction and. ties is a group of observations with the same value. $$ Z = \frac { U_2 - \mu_u + C_{continuity}} {\sigma_u}$$ $$ \mu= \frac {n_1 n_2} {2}$$ $$ \sigma^2= \frac {n_1 n_2(n_1 + n_2 + 1)} {12} (1 - C_{ties})$$

Ties correction

$$n = n_1 + n_2
\\ C_{ties} = \sum_{i=1}^{t}{\frac{f_t^3-f_t}{n^3-n}}$$ t - group number of ties.
f_t - number of values in group t.

Continuity correction

When using continuous distribution to calculate discrete data it is better to use continuity correction.
P(X < a) => P(X < a - 0.5)
P(X > a) => P(X > a + 0.5)

As a result:
Right tail, or two tails with positive Z, (U2 > μ) , Ccontinuity = -0.5 .
Left tail, or two tails with negative Z, (U2 < μ) , Ccontinuity = 0.5 .
When we don't correct the data, Ccontinuity = 0.

Choose the method

The tool will use the exact method or the normal approximation per the method definition:

Automatic

This is the recommended method!.
When n is small, n1 ≤ 20 and n2 ≤ 20, and the data doesn't have ties the tool will use the exact value from the pre-calculated data. Otherwise, the tool will use the normal approximation.

Exact

Using the 'Exact' method force the tool to use the exact method even when having ties.
When n is small, n1 ≤ 20 and n2 ≤ 20, the tool will use the exact value from tables. Otherwise, the tool will use the normal approximation.


Z approximation

The tool uses the normal approximation.

Effect Size

The common language effect size is the probability that a random value from Group1 is greater than random value from Group2.
$$f=\frac{U_1}{n_1n_2}\\ r=\frac{Z}{\sqrt{n_1+n_2}}$$

Example

The following example checks the number of questions answered correctly by two independent groups. One group completed training before performed the test and the other group didn't do the training. Following the test results. The sample sizes: n1=8, n2=10. The significant level (α) is 0.05.

AB
423
76
83
924
1317
1314
1724
1129
13
33

Indirect method

I prefer the indirect method which I find easier with big samples, and not much more complex with small samples.

Direct method

Exact calculation

The Mann-Whitney U distribution is discrete. We can calculate the exact cumulative probability, but we can not have critical value for the exact significance level. Hence we calculate the critical value that get the maximum significance level which is not greater than the required significance level (α).
When the statistic equal the critical value, you should reject the null assumption.
Since the data in this example contains ties, the exact calculation is not accurate. Therefore you should use the normal approximation with continuous correctiom.

Statistical tables

Two-tailed (H0: Group a = Group b)

α / 2 = 0.025.

Left tail (H0: Group a ≥ Group b)

Right tail (H0: Group a < Group b)

Corrected normal approximation

Two tailed (H0: Group a = Group b)

Left tail (H0: Group a ≥ Group b)

Right tail (H0: Group a < Group b)

Exact Example2

n1=4, n2=3, α=0.1.
U20123456789101112Total
Number of combinations112344544321135
$$total=\frac{(n_1+n_2)!}{n_1!n_2!}\\ total=\frac{7!}{4!3!}$$

Two-tailed (H0: Group a = Group b)

α / 2 = 0.05. $$P(X \leq 0)=\frac{U_2(0)}{total}=\frac{1}{35}=0.029\\ P(X \leq 1)=\frac{U_2(0)+U_2(1)}{total}=\frac{1+1}{35}=0.057$$ The left critical value - the first value that gets a cumulative probability greater than 0.05 is x=1 $$P(X \geq 12)=\frac{U_2(12)}{total}=\frac{1}{35}=0.029\\ P(X \geq 11)=\frac{U_2(11)+U_2(12)}{total}=\frac{1+1}{35}=0.057$$ The right critical value - the first value that gets cumulative probability which is greater than 0.05 is for x=11. Since the distribution is symmetrical you may get the same result as following: 12 - 1 = 11.

Left tail (H0: Group a ≥ Group b)

$$P(X \leq 1)=\frac{1+1}{35}=0.057\\ P(X \leq 2)=\frac{1+1+2}{35}=0.114$$ Critical value - the first value that gets cumulative probability which is greater than 0.1 is for x=2.

Right tail (H0: Group a < Group b)

$$P(X \geq 11)=\frac{1+1}{35}=0.057\\ P(X \geq 10)=\frac{1+1+2}{35}=0.114$$ Critical value - the first value that gets cumulative probability which is greater than 0.1 is for x=10.