## Mann-Whitney U‑test

The Mann-Whitney U‑test is a non-parametric test that is used to compare the medians of two populations. You test the null-hypothesis that M_{1 }= M_{2}. Contrary to parametric tests, the Mann-Whitney U‑test do not use the original values in the calculation of the test statistic but rather the ranks of the values.

You need to check the following assumptions before proceeding with the t‑test:

- The observations are independent

Before proceeding with the test calculation of the statistic, the original values must be converted to ranks.

The Mann-Whitney U‑test relies on the test statistic U_{1 }and U_{2}, which are calculated by:

where n_{1 }and n_{2 }are the sample sizes of sample 1 and 2, respectively, and R_{1 }and R_{2 }are the sum of the ranks of each sample. The smallest value of U_{1 }and U_{2 }is selected as the test statistic to be compared with the critical value that is found in a table.

If your calculations are right U_{1 }+ U_{2 }= n_{1}n_{2}

If the calculated test statistic is **less **than the critical, the null-hypothesis is rejected.

**Example**

You want to see if the density of a specific plant species differs between the two habitats forest and meadow.

1. Construct the null-hypothesis

H_{0: }The median number of plants per m^{2 }is the same within a forest and a meadow ( )

2. Do the experiment

You go out and count the number of plants per m^{2 }in a number of frames in each type of habitat.

3. Sort the samples from each habitat and calculate the median of each sample, in this case:

4. Rank the observations:

5. Sum the ranks for each sample

R_{FOREST }= 57.5

R_{MEADOW }= 113.5

6. Calculate the test statistics U_{FOREST }and U_{MEADOW}

U_{FOREST }= 12.5

U_{MEADOW }= 68.5

7. U_{FOREST }+ U_{MEADOW }= n_{FOREST }x n_{MEADOW }= 8

8. Look up the critical value for U at α = 0.05

We check the t‑table at n = 9 where α = 0.05. There we find that U = 17

9. Compare the calculated U statistic with U_{α=0.05 }

We always choose the smallest U statistic from our calculations, which U_{FOREST }= 12.5

U < U_{α=0.05 }= 12.5 < 17

10. Reject H_{0 }or H_{1}

H_{0 }can be rejected; the median density between forest and meadow differ (M_{FOREST }≠ M_{MEADOW})

11. Interpret the result

We are more than 99 % certain that the density of plants is higher within the meadow compared to the forest.

*How to do it in R*

#1. Import the data data<-read.csv("http://www.ilovestats.org/wp-content/uploads/2015/08/U-test1.csv",dec=",",sep=";") #2. Run the test wilcox.test(data$Forest, data$Meadow)