Mann–Whitney U test
In statistics, the Mann–Whitney U test is a nonparametric test of the null hypothesis that the probability that a randomly selected value from one population is less than a randomly selected value from a second population is equal to the probability of being greater.
This test can be used to investigate whether two independent samples were selected from populations having the same distribution. The Mann-Whitney U test is often used when the assumptions of the independent samples t-test are violated. A similar nonparametric test used on dependent samples is the Wilcoxon signed-rank test.
Assumptions and formal statement of hypotheses
Although Mann and Whitney developed the Mann–Whitney U test under the assumption of continuous responses with the alternative hypothesis being that one distribution is stochastically greater than the other, there are many other ways to formulate the null and alternative hypotheses such that the Mann–Whitney U test will give a valid test.A very general formulation is to assume that:
- All the observations from both groups are independent of each other,
- The responses are ordinal,
- Under the null hypothesis H0, the distributions of both populations are equal.
- The alternative hypothesis H1 is that the distributions are not equal.
- The probability of an observation from population X exceeding an observation from population Y is different than the probability of an observation from Y exceeding an observation from X; i.e., or.
The Mann–Whitney U test / Wilcoxon rank-sum test is not the same as the Wilcoxon signed-rank test, although both are nonparametric and involve summation of ranks. The Mann–Whitney U test is applied to independent samples. The Wilcoxon signed-rank test is applied to matched or dependent samples.
Calculations
The test involves the calculation of a statistic, usually called U, whose distribution under the null hypothesis is known. In the case of small samples, the distribution is tabulated, but for sample sizes above ~20, approximation using the normal distribution is fairly good. Some books tabulate statistics equivalent to U, such as the sum of ranks in one of the samples, rather than U itself.The Mann–Whitney U test is included in most modern statistical packages. It is also easily calculated by hand, especially for small samples. There are two ways of doing this.
Method one:
For comparing two small sets of observations, a direct method is quick, and gives insight into the meaning of the U statistic, which corresponds to the number of wins out of all pairwise contests. For each observation in one set, count the number of times this first value wins over any observations in the other set. Count 0.5 for any ties. The sum of wins and ties is U for the first set. U for the other set is the converse.
Method two:
For larger samples:
- Assign numeric ranks to all the observations, beginning with 1 for the smallest value. Where there are groups of tied values, assign a rank equal to the midpoint of unadjusted rankings. E.g., the ranks of are .
- Now, add up the ranks for the observations which came from sample 1. The sum of ranks in sample 2 is now determinate, since the sum of all the ranks equals where N is the total number of observations.
- U is then given by:
Properties
Examples
Illustration of calculation methods
Suppose that Aesop is dissatisfied with his classic experiment in which one tortoise was found to beat one hare in a race, and decides to carry out a significance test to discover whether the results could be extended to tortoises and hares in general. He collects a sample of 6 tortoises and 6 hares, and makes them all run his race at once. The order in which they reach the finishing post is as follows, writing T for a tortoise and H for a hare:What is the value of U?
- Using the direct method, we take each tortoise in turn, and count the number of hares it beats, getting 6, 1, 1, 1, 1, 1, which means that. Alternatively, we could take each hare in turn, and count the number of tortoises it beats. In this case, we get 5, 5, 5, 5, 5, 0, so U = 25. Note that the sum of these two values for, which is.
- Using the indirect method:
Illustration of object of test
If we simply compared medians, we would conclude that the median time for tortoises is less than the median time for hares, because the median tortoise here comes in at position 19, and thus actually beats the median hare, which comes in at position 20. However, the value of U is 100. Consulting tables, or using the approximation below, we find that this U value gives significant evidence that hares tend to have lower completion times than tortoises. Obviously these are extreme distributions that would be spotted easily, but in larger samples something similar could happen without it being so apparent. Notice that the problem here is not that the two distributions of ranks have different variances; they are mirror images of each other, so their variances are the same, but they have very different skewness.
Example statement of results
In reporting the results of a Mann–Whitney U test, it is important to state:- A measure of the central tendencies of the two groups
- The value of U.
- The sample sizes
- The significance level.
A statement that does full justice to the statistical status of the test might run,
However it would be rare to find so extended a report in a document whose major topic was not statistical inference.
Normal approximation and tie correction
For large samples, U is approximately normally distributed. In that case, the standardized valuewhere mU and σU are the mean and standard deviation of U, is approximately a standard normal deviate whose significance can be checked in tables of the normal distribution. mU and σU are given by
The formula for the standard deviation is more complicated in the presence of tied ranks. If there are ties in ranks, σ should be corrected as follows:
where, ti is the number of subjects sharing rank i, and k is the number of ranks.
If the number of ties is small ties can be ignored when doing calculations by hand. The computer statistical packages will use the correctly adjusted formula as a matter of routine.
Note that since, the mean used in the normal approximation is the mean of the two values of U. Therefore, the absolute value of the z statistic calculated will be same whichever value of U is used.
Effect sizes
It is a widely recommended practice for scientists to report an effect size for an inferential test.Proportion of concordance out of all pairs
The following three measures are equivalent.Common language effect size
One method of reporting the effect size for the Mann–Whitney U test is with f, the common language effect size. As a sample statistic, the common language effect size is computed by forming all possible pairs between the two groups, then finding the proportion of pairs that support a direction. To illustrate, in a study with a sample of ten hares and ten tortoises, the total number of ordered pairs is ten times ten or 100 pairs of hares and tortoises. Suppose the results show that the hare ran faster than the tortoise in 90 of the 100 sample pairs; in that case, the sample common language effect size is 90%. This sample value is an unbiased estimator of the population value, so the sample suggests that the best estimate of the common language effect size in the population is 90%.The relationship between f and the Mann–Whitney U is as follows:
This is the same as the area under the curve for the ROC curve below.
''ρ'' statistic
A statistic called ρ that is linearly related to U and widely used in studies of categorization, and elsewhere, is calculated by dividing U by its maximum value for the given sample sizes, which is simply. ρ is thus a non-parametric measure of the overlap between two distributions; it can take values between 0 and 1, and it is an estimate of, where X and Y are randomly chosen observations from the two distributions. Both extreme values represent complete separation of the distributions, while a ρ of 0.5 represents complete overlap. The usefulness of the ρ statistic can be seen in the case of the odd example used above, where two distributions that were significantly different on a Mann–Whitney U test nonetheless had nearly identical medians: the ρ value in this case is approximately 0.723 in favour of the hares, correctly reflecting the fact that even though the median tortoise beat the median hare, the hares collectively did better than the tortoises collectively.Area-under-curve (AUC) statistic for ROC curves
The U statistic is equivalent to the area under the receiver operating characteristic curve that can be readily calculated.Note that this is the same definition as the common language effect size from the section above. i.e.: the probability that a classifier will rank a randomly chosen positive instance higher than a randomly chosen negative one.
Because of its probabilistic form, the U statistic can be generalised to a measure of a classifier's separation power for more than two classes:
Where c is the number of classes, and the Rk,l term of AUCk,l considers only the ranking of the items belonging to classes k and l according to the classifier's estimates of the probability of those items belonging to class k. AUCk,k will always be zero but, unlike in the two-class case, generally, which is why the M measure sums over all pairs, in effect using the average of AUCk,l and AUCl,k.
Rank-biserial correlation
A method of reporting the effect size for the Mann–Whitney U test is with a measure of rank correlation known as the rank-biserial correlation. Edward Cureton introduced and named the measure. Like other correlational measures, the rank-biserial correlation can range from minus one to plus one, with a value of zero indicating no relationship.There is a simple difference formula to compute the rank-biserial correlation from the common language effect size: the correlation is the difference between the proportion of pairs favorable to the hypothesis minus its complement. This simple difference formula is just the difference of the common language effect size of each group, and is as follows:
For example, consider the example where hares run faster than tortoises in 90 of 100 pairs. The common language effect size is 90%, so the rank-biserial correlation is 90% minus 10%, and the rank-biserial .
An alternative formula for the rank-biserial can be used to calculate it from the Mann–Whitney U and the sample sizes of each group:
This formula is useful when the data are not available, but when there is a published report, because U and the sample sizes are routinely reported. Using the example above with 90 pairs that favor the hares and 10 pairs that favor the tortoise, U2 is the smaller of the two, so. This formula then gives, which is the same result as with the simple difference formula above.
Relation to other tests
Comparison to Student's ''t''-test
The Mann–Whitney U test tests a null hypothesis of that the probability that a randomly drawn observation from one group is larger than a randomly drawn observation from the other is equal to 0.5 against an alternative that this probability is not 0.5. In contrast, a t-test tests a null hypothesis of equal means in two groups against an alternative of unequal means. Hence, except in special cases, the Mann–Whitney U test and the t-test do not test the same hypotheses and should be compared with this in mind.;Ordinal data: The Mann–Whitney U test is preferable to the t-test when the data are ordinal but not interval scaled, in which case the spacing between adjacent values of the scale cannot be assumed to be constant.
;Robustness:As it compares the sums of ranks, the Mann–Whitney U test is less likely than the t-test to spuriously indicate significance because of the presence of outliers. However, the Mann-Whitney U test may have worse type I error control when data are both heteroscedastic and non-normal.
;Efficiency:When normality holds, the Mann–Whitney U test has an efficiency of 3/π or about 0.95 when compared to the t-test. For distributions sufficiently far from normal and for sufficiently large sample sizes, the Mann–Whitney U test is considerably more efficient than the t. This comparison in efficiency, however, should be interpreted with caution, as Mann-Whitney and the t-test do not test the same quantities. If, for example, a difference of group means is of primary interest, Mann-Whitney is not an appropriate test.
The Mann–Whitney U test will give very similar results to performing an ordinary parametric two-sample t-test on the rankings of the data.
Different distributions
If one is only interested in stochastic ordering of the two populations that is often used in the context.Alternatives
If one desires a simple shift interpretation, the Mann–Whitney U test should not be used when the distributions of the two samples are very different, as it can give erroneous interpretation of significant results. In that situation, the unequal variances version of the t-test may give more reliable results.Similarly, some authors suggest transforming the data to ranks and then performing the t-test on the transformed data, the version of the t-test used depending on whether or not the population variances are suspected to be different. Rank transformations do not preserve variances, but variances are recomputed from samples after rank transformations.
The Brown–Forsythe test has been suggested as an appropriate non-parametric equivalent to the F-test for equal variances.
See also Kolmogorov–Smirnov test.
Related test statistics
Kendall's tau
The Mann–Whitney U test is related to a number of other non-parametric statistical procedures. For example, it is equivalent to Kendall's tau correlation coefficient if one of the variables is binary.Software Implementations
In many software packages, the Mann–Whitney U test has been poorly documented. Some packages incorrectly treat ties or fail to document asymptotic techniques. A 2000 review discussed some of the following packages:- MATLAB has in its Statistics Toolbox.
- R's statistics base-package implements the test in its "stats" package.
- SAS implements the test in its PROC NPAR1WAY procedure.
- Python has an implementation of this test provided by SciPy
- SigmaStat
- SYSTAT
- Java has an implementation of this test provided by Apache Commons
- Julia has implementations of this test through several packages. In the package HypothesisTests.jl, this is found as pvalue
- JMP
- S-Plus
- STATISTICA
- UNISTAT
- SPSS
- StatsDirect implements .
- Stata implements the test in its command.
- StatXact
- PSPP implements the test in its function.
History
In a single paper in 1945, Frank Wilcoxon proposed both the one-sample signed rank and the two-sample rank sum test, in a test of significance with a point null-hypothesis against its complementary alternative. However, he only tabulated a few points for the equal-sample size case in that paper.
A thorough analysis of the statistic, which included a recurrence allowing the computation of tail probabilities for arbitrary sample sizes and tables for sample sizes of eight or less appeared in the article by Henry Mann and his student Donald Ransom Whitney in 1947. This article discussed alternative hypotheses, including a stochastic ordering. This paper also computed the first four moments and established the limiting normality of the statistic under the null hypothesis, so establishing that it is asymptotically distribution-free.