[R] mann-whitney test with more groups
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Wed Nov 18 19:05:26 CET 2009
Peter Ehlers wrote:
> Sorry, correction below.
>
> Peter Ehlers wrote:
>>
>> Kim Vanselow wrote:
>>> Dear r-helpers,
>>> I want to test groups of samples for significant differences.
>>> Question: Does Group1 differ significantly from group2.
>>> This is a question to be answered by mann-whitney-u-test.
>>>
>>> I know that I can use wilcox.test with 2 samples.
>>>
>>> My problem: How can r perform the test automatically if there are
>>> more than 2 groups in my data frame.
>>> Test group1 vs. 2, 1 vs. 3, 1 vs. 4, etc.
>>>
>>>
>>> This is my skript:
>>> Deckung <- read.table("Gesamtdeckung.csv", sep=";", header=TRUE,
>>> dec=",", row.names=1)
>>>
>>> x <- Deckung$Gesamtdeckung
>>> y <- Deckung$Klasse
>>>
>>> #U-Test
>>> wilcox.test(x ~ y, paired = FALSE, subset = y %in% c("1", "2"))
>>> wilcox.test(x ~ y, paired = FALSE, subset = y %in% c("1", "3"))
>>> wilcox.test(x ~ y, paired = FALSE, subset = y %in% c("2", "3"))
>>>
>>> Any help would be greatly appreciated!
>>>
>>> Thanks
>>> Kim
>>
>> This sounds like serious data dredging, but if you're
>> sure that it's what you want, try the combn() function:
>>
>> y <- gl(4, 5)
>> x <- rnorm(20)
>> m <- cbind(t(combn(4, 2)), NA)
>> for(i in 1:nrow(idx))
>> m[i, 3] <-
>> wilcox.test(x ~ y, subset = y %in% idx[i,])$p.value
>> m
>>
>> -Peter Ehlers
>>
> y <- gl(4, 5)
> x <- rnorm(20)
> m <- cbind(t(combn(4, 2)), NA)
> for(i in 1:nrow(m)) # change 'idx' to 'm'
> m[i, 3] <-
> wilcox.test(x ~ y, subset = y %in% m[i,])$p.value # ditto
There's also pairwise.wilcox.test, with multiple testing correction and
all. (But someone called Lumley may chime in and remind you of the lack
of guaranteed transitivity of rank tests.)
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list