Mann-Whitney U

# Overview
In statistics, the Mann-Whitney U test (also called the Mann-Whitney-Wilcoxon (MWW), Wilcoxon rank-sum test, or Wilcoxon-Mann-Whitney test) is a non-parametric test for assessing whether two samples of observations come from the same distribution. The null hypothesis is that the two samples are drawn from a single population, and therefore that their probability distributions are equal.  It requires the two samples to be independent, and the observations to be ordinal or continuous measurements, i.e. one can at least say, of any two observations, which is the greater.  More generally, the Wilcoxon-Mann-Whitney two-sample test may be thought of as testing the null hypothesis that the probability of an observation from one population exceeding an observation from the second population is equal to 0.5.  Another alternative interpretation is that the test assesses whether the Hodges-Lehmann estimate of the difference in central tendency between the two populations is zero.  The Hodges-Lehmann estimate for this two-sample problem is the median of all possible differences between an observation in the first sample and an observation in the second sample.  It is commonly thought that the MWW test tests for differences in medians but this is not strictly true.
It is one of the best-known non-parametric significance tests.  It was proposed initially by Wilcoxon (1945), for equal sample sizes, and extended to arbitrary sample sizes and in other ways by Mann and Whitney (1947).  MWW is virtually identical to performing an ordinary parametric two-sample t test on the data after ranking over the combined 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 samples above about 20 there is a good approximation using the normal distribution.  Some books tabulate statistics equivalent to U, such as the sum of ranks in one of the samples.
The 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.
For small samples a direct method is recommended.  It is very quick, and gives an insight into the meaning of the U statistic.
- Choose the sample for which the ranks seem to be smaller (The only reason to do this is to make computation easier).  Call this "sample 1," and call the other sample "sample 2."
- Taking each observation in sample 1, count the number of observations in sample 2 that are smaller than it (count a half for any that are equal to it).
- The total of these counts is U.
For larger samples, a formula can be used:
- Arrange all the observations into a single ranked series. That is, rank all the observations without regard to which sample they are in.
- Add up the ranks in sample 1.  The sum of ranks in sample 2 follows by calculation, since the sum of all the ranks equals N(N + 1)/2 where N is the total number of observations.
- "U" is then given by:
The maximum value of U is the product of the sample sizes for the two samples.  In such a case, the "other" U would be 0.

# Example
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.  The order in which they reach the finishing post (their rank order) is as follows, writing T for a tortoise and H for a hare:
(his original tortoise still goes at warp speed, and his original hare is still lazy, but the others run truer to stereotype).  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.  So U = 6 + 1 + 1 + 1 + 1 + 1 = 11.  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, which means U = 25.  Note that the sum of these two values for "U" is 36, which is 6  6.
- Using the indirect method:
Consulting the table referenced below, we find that this result does not confirm the greater speed of tortoises.  It also does not show any significant speed advantage for hares.

# Approximation
For large samples, the normal approximation:
can be used, where z is a standard normal deviate whose significance can be checked in tables of the normal distribution.  mU and U are the mean and standard deviation of U if the null hypothesis is true, and are given by
All the formulae here are made more complicated in the presence of tied ranks, but if the number of these is small (and especially if there are no large tie bands) these can be ignored when doing calculations by hand.  The computer statistical packages will use them as a matter of routine.
Note that since U1 + U2 = n1 n2, the mean n1 n2/2 used in the normal approximation is the mean of the two values of U.  Therefore, you can use U and get the same result, the only difference being between a left-tailed test and a right-tailed test.

# Relation to other tests
The U test is useful in the same situations as the independent samples Student's t-test, and the question arises of which should be preferred.  U remains the logical choice when the data are ordinal but not interval scaled, so that the spacing between adjacent values cannot be assumed to be constant.  It is much less likely than the t test to give a spuriously significant result because of one or two outliers.  When normality holds, MWW has a Pitman efficiency of \scriptstyle 3/\pi or about 0.95 when compared to the t test.  For distributions sufficiently far from normal and for sufficiently large sample sizes, the MWW can be considerably more efficient than the t. For large samples and the normal, the efficiency loss is only 5%, maybe a small price to pay so one could recommend MWW as the default test for comparing interval or ordinal measurements. The relation between efficiency and power in concrete situations isn't trivial though. For small sample sizes one should investigate the power of the MWW vs t.
On the other hand, the U test is often recommended for situations where the distributions of the two samples are very different.  This is an error: it tests whether the two samples come from a common distribution, and Monte Carlo methods have shown that it is capable of giving erroneously significant results in some situations where samples are drawn from distributions with the same mean and different variances.  In that situation, the version of the t test that allows for the samples to come from populations of different variance is likely to give more reliable results, if normality holds.  Indeed, as an alternative to the U test, some authors (e.g. Conover) suggest transforming the data to ranks (if they are not already 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.  The Brown-Forsythe test has been suggested as an appropriate non-parametric equivalent to the F test for equal variances.
The U test is related to a number of other non-parametric statistical procedures.  For example, it is equivalent to Kendall's  correlation coefficient if one of the variables is binary (that is, it can only take two values).
A statistic called  that is linearly related to U and widely used in studies of categorization (discrimination learning) is calculated by dividing U by its maximum value for the given sample sizes, which is simply n1  n2.   is thus a non-parametric measure of the overlap between two distributions; it can take values between 0 and 1, and it is equal to \scriptstyle P(Y > X) + 0.5 P(Y = X), 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.  is also known as the area under the receiver operating characteristic (ROC) curve.

# Example statement of results
Outcomes of the two treatments were compared using the Wilcoxon-Mann-Whitney two-sample rank-sum test.
The treatment effect (difference between treatments) was quantified using the Hodges-Lehmann (HL) estimator, which is consistent with the Wilcoxon test (ref. 5 below).  This estimator (HL) is the median of all possible differences in outcomes between a subject in group B and a subject in group A.  A non-parametric 0.95 confidence interval for HL accompanies these estimates as does , an estimate of the probability that a randomly chosen subject from population B has a higher weight than a randomly chosen subject from population A.
The median  weight for subjects on treatment A and B respectively are 147  and 151  pounds.  Treatment A decreased weight by HL = 5 lbs. (0.95 CL  lbs., 2P = 0.02,  = 0.58).