# Mann-Whitney test for unequal sample sizes

I want to run a Mann-Whitney test. But I got to know to know that for sample more than 20 we need to apply a different formula. My data sample is as follows. Group A contains data of 4 people and group B contains data of 36 people. It seems unequal. Which formula should i use?

• With a group of just 4 you will likely have very little power no matter what test you use. Is the variability very small compared to an effect that might be of interest? If not then you probably should not make any inference. – Michael Lew Aug 19 at 21:46
• With respect to what tests might be most appropriate, you need to tell us what type of measurements you have made. – Michael Lew Aug 19 at 21:46
• Several duplicates and near-duplicates already on site - e.g. stats.stackexchange.com/questions/250353/… and stats.stackexchange.com/questions/90644/… – Glen_b Aug 20 at 2:18

The difference between large and small samples in using the Mann-Whitney-Wilcoxon (rank sum) 2-sample test usually has to do with using either (a) an exact probability table for the test statistic or (b) using a normal approximation. In many statistical software programs, the correct method is chosen to find the P-value of the test (often without notice to the user which choice is made).

For a given total number of samples $$(n_1 + n_2 = N)$$ for Groups 1 and 2 together, the highest power results from having $$n_1 \approx n_2 \approx N/2,$$ so experiments are usually designed with equal sample sizes in the two groups. However, there is ordinarily no difficulty if sample sizes are not equal. The major exception arises when the smaller sample size is very small, as in your Question.

Let's look at two small samples $$(n_1=n_2=10)$$ from slightly right-skewed (i.e., non-normal) distributions with somewhat different locations:

set.seed(1234)
x1 = round(rgamma(10, 5, .1))
x2 = round(rgamma(10, 5, .1)+5)
stripchart(list(x1,x2), ylim=c(.5,2.5), pch=20, meth="stack") The stripchart shows that Sample 2 may be centered a little to the right of Sample 1. Rounding has produced a few ties. The test below does not find a significant difference in location (P-value approximately $$0.17 > 0.05 = 5\%)$$ and there is a warning message about ties. (These warning messages often appear when samples are small and the program has used a normal approximation to find an approximate P-value because ties make an exact P-value impossible.)

wilcox.test(x1, x2)

Wilcoxon rank sum test with continuity correction

data:  x1 and x2
W = 31.5, p-value = 0.1733
alternative hypothesis:
true location shift is not equal to 0

Warning message:
In wilcox.test.default(x1, x2) :
cannot compute exact p-value with ties


Now we look at larger but somewhat unequal samples $$(n_1 = 100, n_2 = 120)$$ from the same two populations, respectively.

set.seed(1234)
x1 = round(rgamma(100, 5, .1))
x2 = round(rgamma(120, 5, .1)+5)
stripchart(list(x1,x2), ylim=c(.5,2.5), pch=20, meth="stack") The stripchart fairly clearly shows that Sample 2 is centered to the right of Sample 1. Rounding has produced many ties. The test below finds a significant difference in location (P-value approximately $$0.17 > 0.05 = 5\%)$$ and there is no warning message about ties. (With samples this large, the program has used a normal approximation.) The test shows a significant difference in locations, P-value below $$0.01 \ 1\%.$$

wilcox.test(x1, x2)

Wilcoxon rank sum test with continuity correction

data:  x1 and x2
W = 4624, p-value = 0.003428
alternative hypothesis:
true location shift is not equal to 0


Finally, lets look at samples of the sizes $$n_1 = 4, n_2 = 36$$ of your Question, with populations that differ more than in the two examples above.

set.seed(1235)
x1 = round(rgamma(4, 5, .1))
x2 = round(rgamma(36, 5, .1) + 10)
stripchart(list(x1,x2), ylim=c(.5,2.5), pch=20, meth="stack") From the stripchart it's hard to say where (tiny) Sample 1 is centered relative to Sample 2. Rounding has produced ties (none in the small sample). The test below finds no significant difference in location (P-value approximately $$0.17 > 0.05 = 5\%)$$ and there is no warning message about ties. The test shows no significant difference in locations, mainly because of a lack of information about Population 1. The P-value is far above $$5\%.$$

wilcox.test(x1, x2)

Wilcoxon rank sum test with continuity correction

data:  x1 and x2
W = 54.5, p-value = 0.4432
alternative hypothesis:
true location shift is not equal to 0

Warning message:
In wilcox.test.default(x1, x2) : cannot compute exact p-value with ties


Notes: (1) Sampling again as in the last example (this time with set.seed(1235)) with samples of the same sizes and from the same populations, a couple of the points in the first sample happen to lie below any of the points in the second, and a significant difference is found. So it is not impossible to reject with samples of sizes $$n_1=4, n_2=36,$$ but the power of the test is not good with such an imbalance in sample sizes. More particularly, a simulation of 100,000 such cases shows a power of about 15%.

set.seed(2020)
pv = replicate(10^5, wilcox.test(rgamma(4,5,.1),
rgamma(36,5,.1)+10)\$p.val)
mean(pv <= .05)
 0.14822


(2) R documentation states that its 2-sample Wilcoxon rank sum test is equivalent to a Mann-Whitney 2-sample test. Also, if $$n_1+n_2 < 50$$ and there are no ties, R gives an exact P-value, otherwise (without modification by parameters) a normal approximation is used.