Skip to content
Prev 299406 / 398503 Next

Mann-Whitney by group

This works. First we assign the results of dput() to a variable
So we can use it. Then we eliminate the groups we don't need.
Third we remake the factors to eliminate the groups and genes
that do not appear in the data subset. Finally, compute the tests.


Dta <- structure(list(Gene = structure(c(1L, 12L, 19L, 20L, 21L,
     ....................lines omitted..........................
"Group", "A", "B", "C", "D", "E", "F", "G", "H"), row.names = c(NA, 
25L), class = "data.frame")

# Pull out just groups 5 and 6
Dtb <- Dta[Dta$Group %in% c(5, 6), ]

# Check the resulting data frame - 8 observations, 
# four in each group, all measurements in B are 1
Dtb

# Eliminate factor levels that do not exist in the reduced
# data set
Dtb$Gene <- factor(Dtb$Gene) 
Dtb$Group <- factor(Dtb$Group)

# Mann-Whitney is the same as Wilcoxon Rank Sum test (see manual page)
?wilcox.test

# Compute test for A
wilcox.test(A~Group, Dtb)

# Compute all the tests
apply(Dtb[,3:10], 2, function(x) wilcox.test(x~Dtb$Group))

# Error relates to column B which is constant

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352