# Wilcoxon Rank-Sum: computing the exact $p$-value

I have two groups of data: $\{7, 9, 11\}$, $\{3, 8, 4\}$. I am performing Wilcoxon Rank-Sum on these data, based on the first group. Aggregated, we have $\{3, 4, 7, 8, 9, 11\}$. The test statistic is clearly $3 + 5 + 6 = 14$. I'm trying to figure out how to compute the exact two-sided $p$-value, but I don't understand my professor's explanations.

If I want a larger test statistic, the only way that can happen is if I have ranks $4$, $5$, and $6$. I get this. I also have to include the observed ranks $3$, $5$, and $6$. But what I don't understand is why ranks $1$, $2$, $3$ and $1$, $2$, $4$ are the only ones taken into account when calculating the other side of the $p$-value. Why not $1$, $2$, $5$ as well? This gives a rank less than $14$.

Here are the possible sets of ranks in sample 1, and their sum, from largest to smallest

4 5 6 = 15  <-- more extreme than your sample
3 5 6 = 14  <-- your sample is here
3 4 6 = 13
2 5 6 = 13
3 4 5 = 12
2 4 6 = 12
1 5 6 = 12
2 4 5 = 11
2 3 6 = 11
1 4 6 = 11 /______ the center is here, expected rank sum under H0 = 10.5
1 4 5 = 10 \
1 3 6 = 10
2 3 5 = 10
2 3 4 =  9
1 3 5 =  9
1 2 6 =  9
1 3 4 =  8
1 2 5 =  8
1 2 4 =  7 <- exactly as far from the center as your sample
1 2 3 =  6 <- more extreme than your sample, but in the other direction


The ranks of the two groups are $\lbrace 3,5,6\rbrace$ and $\lbrace 1,2,5\rbrace$, giving a statistic of 14, as you said. You have to consider every way of taking 3 values from the ranks 1,2,3,4,5,6, as each of these is equally-likely under the null hypothesis of equal distributions. So, in the worse case, list all ${6\choose 3} = 20$ of them and compute the test statistic for each possible sample. This will give the null distribution of the statistic.