Skip to content
Prev 324547 / 398506 Next

wilcox_test function in coin package

Janh,

Janh Anni skrev 2013-06-01 04:27:
Admittedly, 'coin' is being actively developed and has a lot more bells 
and whistles.  But for something as simple as this, that wouldn't bother 
me at all.  In any case, the 'exactRankTests' package still gets bug 
fixes and the algorithm used in the Wilcoxon case is exactly the same 
for both packages.

However, if you want to stay with 'coin' you can just wrap up Greg's 
proposal in a function:

wilcox_test.default <- function(x, y, ...) {
     data <-
         data.frame(values = c(x, y),
                    group = rep(c("x", "y"), c(length(x), length(y))))
     wilcox_test(values ~ group, data = data, ...)
}

Assuming that both 'coin' and 'exactRankTests are loaded, we can now 
check that it works:

 > set.seed(123)
 > x <- rpois(10, 3)
 > y <- rpois(11, 3.1)
 >
 > wilcox_test(x, y, alternative = "less", distribution = "exact")

         Exact Wilcoxon-Mann-Whitney Test

data:  values by group (x, y)
Z = -0.0715, p-value = 0.4844
alternative hypothesis: true mu is less than 0

 > wilcox.exact(x, y, alternative = "less")

         Exact Wilcoxon rank sum test

data:  x and y
W = 54, p-value = 0.4844
alternative hypothesis: true mu is less than 0


HTH,
Henric