1
$\begingroup$

While performing the Wilcoxon rank sum test in R, I sometimes get W values of 0, but significant p values. Since the way R calculates W is the difference between the rank sum of one group minus the expected rank sum, I don't understand how this can be 0 but then still reject the null hypothesis. If one of the groups rank sum is equal to the expected, shouldn't the other be as well and thus there is no difference, i.e. the null hypothesis holds?

Thanks a lot, Ser

PS I'm new here and I don't know how to cross ref to another post, but the way R calculates W is really well explained a post called 'Wilcoxon rank sum test correct vectors order'

Edit: I have read the topic on what the test statistic indicates, however, I am specifically interested in the W=0 case

$\endgroup$
3
  • 1
    $\begingroup$ Can you show an example? $\endgroup$ Commented Oct 1 at 9:55
  • $\begingroup$ Good question: as I was providing the example, I am now thinking it may have to do with my negative values. I have two groups of n=6 with growth percentages (negative and positive). Group 1 has values -62.1, -72.8, -76.1, -58.5, -70.2, -67.5 Group 2 has values 18.1, 3.2, 10.6, 23.7, 30.3, 8.7 Does ranking from smallest to largest then start 'closest to zero' or with the lowest negative values? Anyway, I get W=0 and p=0.014. I used the wilcox.test funtion with paired=FALSE. I do trust the p value, the samples are clearly very different, I just don't understand how it comes to W=0. $\endgroup$ Commented Oct 1 at 11:52
  • $\begingroup$ Examining the source code of the wilcox.test function will show you it has nothing to do with having negative values. If you don't have time to dissect the code, you can easily construct examples to illustrate your question, for instance: a = c(38.9, 61.2, 73.3, 21.8, 63.4, 64.6, 48.4, 48.8, 48.5);b = a+200;wilcox.test(a,b). @ChristianHennig $\endgroup$
    – J-J-J
    Commented Oct 1 at 12:13

2 Answers 2

4
$\begingroup$

According to its documentation, the ?wilcox.test function returns a statistic that is:

the number of all pairs (x[i], y[j]) for which y[j] is not greater than x[i], the most common definition of the Mann-Whitney test.

If you get $W=0$, it means that there are no rank of $X$ that is larger than the ranks of $Y$, which is is an extreme value if the null hypothesis is true. If you have a large enough sample size, you will then logically get a small p-value.

If you need more details on how this statistic is computed in R, you can refer to these other threads:

As pointed out in comments and in other threads, the function documentation also mentions that:

The literature is not unanimous about the definitions of the Wilcoxon rank sum and Mann-Whitney test.

So if you intend to publish your results, no matter if you use R or something else, be explicit about how you computed the test and which software you used, as it is something that may vary between tools and could confuse readers.

$\endgroup$
2
  • $\begingroup$ Thank you! I will be explicit about it in the methods section indeed $\endgroup$ Commented Oct 4 at 13:07
  • $\begingroup$ @SerHuisman You're welcome. I hope your paper will be successful. If you find that the answer fully addresses your question, you can mark it as accepted (see meta.stackexchange.com/a/5235/1318600). Otherwise feel free to ask for more details, if they are not addressed here or in other threads. $\endgroup$
    – J-J-J
    Commented Oct 4 at 13:59
3
$\begingroup$

There are 3 issues at play here.
The first is that the test actually computes 2 statistics, $R_1$ and $R_2$, namelly the sum of ranks for sample 1, and sample 2. The "custom" is to chose as the statistic reported $Min(R_1,R_2)$; but in fact, one could chose either, as they carry exactly the same information (remember that $R_1+R_2=\frac {(n_1+n_2+1).(n_1+n_2)} {2}$). So if you see $W=0$, that means that "the other W" is quite large. And remember also that, under the null, W will not be equal to 0, but instead to $\frac {(n_1+n_2+1).(n_1+n_2)} {4}$, so $W=0$ is in fact very extreme.
The 2nd is that in your case, all the values of the 2nd sample are larger than all values of the first. That is as "extreme" (against the null) as 2 samples could get. Now if you only had run wilcox.test(b,a), the p-value would have been identical, but W would be larger (36 for your example).
The 3rd, and the major one, is that wilcox.test does not return a sum of ranks. If it did, for your example with 6 values in each sample, the sum of ranks statistic should be in the interval $[21,57]$. It is indeed impossible for a true sum of ranks to be 0 (that would imply that the sample had 0 values?!?). What this R function does instead is subtract the minimum possible value of the statistic (in your example, 21) from the actual, true sum of ranks. It does this, so that what it returns is actually the Mann-Whitney U statistic (remember that $U_1=R_2-\frac {n_2(n_2+1)} {2}$, and vice-versa for $U_2$. But it calls it W (should really call it U), adding to the confusion, as you examplify (the function is called wilcox.test(), but returns the Mann-Whitney statistic?? Yes, they are equivalent, but...)
In fact, if I use other software, I never get $W=0$, for your example, but instead $W=21$, as it should be (e.g. Minitab, this online calculator, or the Real Statistics Excel add-on package, all return $W=21$). And I get W=57 when I test B against A, again as it should be.

$\endgroup$
5
  • 2
    $\begingroup$ From the documentation: "The literature is not unanimous about the definitions of the Wilcoxon rank sum and Mann-Whitney tests. The two most common definitions correspond to the sum of the ranks of the first sample with the minimum value (m(m+1)/2 for a first sample of size m) subtracted or not: R subtracts. It seems Wilcoxon's original paper used the unadjusted sum of the ranks but subsequent tables subtracted the minimum." $\endgroup$
    – Roland
    Commented Oct 2 at 6:15
  • $\begingroup$ Thank you for the useful answer! And the addition about the literature. I agree, quite confusing; I have already read about 4 different ways now to calculate W. I would prefer R to just use Mann Whitney U and provide a U and/or z value for this test, but well. I agree especially with this strange outcome for my sample (the same happened in another sample with less extreme differences; 1 group had neg and pos values in there), I calculated it by hand and got your W's too... I am leaning towards reporting SPSS's U or z for this, but I am hesitant as R is considered the holy grail in my field ;) $\endgroup$ Commented Oct 2 at 9:03
  • 1
    $\begingroup$ @SerHuisman As all these are equivalent, you can give out whatever of these values you want if you say what it actually is. You can even give your hand-calculated value as long as it is correct, with definition, and give the p-value from R. $\endgroup$ Commented Oct 2 at 14:22
  • $\begingroup$ Rather than reporting any W, or U statistic (subtracted or not)), you may simply want to report none. Yes, any of the above are equivalent, but they are also completely redundant with the p-value. These statistic and the p-value are deterministacally related. So reporting their value does not add anything, does not re-inforce the p-value, does not confirm the significance. Rather than confusing your audience with statistics the computatiuons of which they may or not know, just use the p-value (at least most of your audience will think they know what it means). $\endgroup$
    – jginestet
    Commented Oct 2 at 20:02
  • $\begingroup$ Thank you! I will be very explicit in my methods section about where the W comes from. I agree that reporting the W does not add much, however, I am not a fan of only p-values. Ideally, I would report an effect size, I'll look into the options for that! PS I like that last sentence, haha $\endgroup$ Commented Oct 4 at 13:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.