[R] qwilcox

Torsten Hothorn Torsten.Hothorn at rzmail.uni-erlangen.de
Wed Jun 11 08:56:08 CEST 2003


On Tue, 10 Jun 2003, Knut M. Wittkowski wrote:

> The function 'wilcox.test' in R and S gives (almost) identical results (see
> below). 'qwilcox' however, does not:
>
>  > qwilcox(p,5,5)
>
> p:      0.025   0.975
> --------------------
> R>       3      22
> S>      18      37
>
> I originally wanted to ask a questions, but then I found the answer. Given
> the confusion I run into, I wonder if this experience is worth reporting.
>
> The S-Plus quantiles are almost correct (they are the limits of the region
> of acceptance, rather than the quantiles). The description in the R help file
>
>          Distribution of the Wilcoxon Rank Sum Statistic
>
> suggests that R:qwilcox also gives quantiles for the rank sum (which the
> Wilcoxon rank sum test is based on). In fact, however, it gives quantiles
> for the u-statistic (which the Mann-Whitney test is based upon). While the
> tests are logically equivalent, the particular test statistics
>
>          - sum(Xi>c(X,Y))        rank sum (Wilcoxon)
>          - sum(Xi>c(  Y))        u statistic (Mann-Whitney)
>
> are different (apologies for the non-standard notation). Since
> "wilcox.test" relates to the rank sums in both R and S,

That is not true. You did not tell us the whole story:
`wilcox.test' in S-PLUS 2000 reports a statistic of `W = 17' for your
example below whereas R says

R> wilcox.test(x1,x2,alternative="two.sided")

        Wilcoxon rank sum test

data:  x1 and x2
W = 2, p-value = 0.03175
alternative hypothesis: true mu is not equal to 0

and as one can find out easily, `wilcox.test' computes the statistic as

STATISTIC <- sum(r[seq(along = x)]) - n.x * (n.x + 1) / 2

So both R and S are consistent and ?qwilcox will tell you what exactly is
meant by `Wilcoxon rank sum':

     This distribution is obtained as follows.  Let `x' and `y' be two
     random, independent samples of size `m' and `n'. Then the Wilcoxon
     rank sum statistic is the number of all pairs `(x[i], y[j])' for
     which `y[j]' is not greater than `x[i]'.  This statistic takes
     values between `0' and `m * n', and its mean and variance are `m *
     n / 2' and `m * n * (m + n + 1) / 12', respectively.


Best,

Torsten

> as does qwilcox in
> S, the name 'qwilcox' in R may be misleading. How about renaming it to
> 'qmannwhitney' instead and adding 'qwilcoxon' for a function that
> corresponds to S:qwilcox?
>
>  > x1 <- c(1,2,3,  5,6         )
>  > x2 <- c(      4,    7,8,9,10)
>  > sum(x1)
> [1] 17
>  > sum(x2)
> [1] 38
>
> R> wilcox.test(x1,x2,alternative="two.sided")
>          Wilcoxon rank sum test: p-value = 0.03175
>
> R> wilcox.exact(x1,x2,alternative="two.sided")
>          Exact Wilcoxon rank sum test: p-value = 0.03175
>
> S> wilcox.test(x1,x2,alternative="two.sided")
>          Exact Wilcoxon rank-sum test: p-value = 0.0317
>
>  > x1 <- c(1,2,  4,5,6         )
>  > x2 <- c(    3,      7,8,9,10)
>  > sum(x1)
> [1] 18
>  > sum(x2)
> [1] 37
>
> R> wilcox.test(x1,x2,alternative="two.sided")
>          Wilcoxon rank sum test: p-value = 0.05556
>
> R> wilcox.exact(x1,x2,alternative="two.sided")
>          Exact Wilcoxon rank sum test: p-value = 0.05556
>
> S> wilcox.test(x1,x2,alternative="two.sided")
>          Exact Wilcoxon rank sum test: p-value = 0.0556
>
>
> Knut M. Wittkowski, PhD,DSc
> ------------------------------------------
> The Rockefeller University, GCRC
> 1230 York Ave #121B, Box 322, NY,NY 10021
> +1(212)327-7175, +1(212)327-8450 (Fax)
> kmw at rockefeller.edu
> http://www.rucares.org/statist/
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>




More information about the R-help mailing list