Skip to content
Prev 300304 / 398503 Next

Mann-Whitney by group

On Mon, Jul 16, 2012 at 3:39 PM, Oxenstierna <david.chertudi at gmail.com> wrote:
I think there are a few things at play here.

1) coin uses so-called S4 objects, so `[[` style subsetting isn't
going to work. The "right way" is, as you have found to use the
pvalue() function.

2) It looks like you need to use the formula intervace for
wilcox_test. Unfortunately, this makes things a little more
complicated as you'll need to construct the formula programmatically.

A one liner looks something like this.

lapply(LETTERS[1:8], function(x)
pvalue(wilcox_test(as.formula(paste(x, "~ Group ")), Dtb)))

Where lapply loops over the letters A,B, etc. and makes the string `A
~ Group`, converts it to a formula, passes that to wilcox_test, then
gets the pvalue and returns it.

In two lines you could do:

thing <- lapply(LETTERS[1:8], function(x)
wilcox_test(as.formula(paste(x, "~ Group")), Dtb))
thing2 <- lapply(thing, pvalue)

Where thing has all the test result objects, and thing2 collects the pvalues.

Hope this helps,
Michael