While it's easy to compute the p-value of Krsukal-Wallis non-parametric test using the
kruskal.test() function, I don't know how to compute the mean ranks and standard errors for each group.
For instance suppose the following example:
x <- data.frame(group=rep(1:2,each=10),height=runif(20)) kruskal.test(x$height, g=x$group) # Kruskal-Wallis rank sum test # data: x$height and x$group # Kruskal-Wallis chi-squared = 0.0057, df = 1, # p-value = 0.9397
It returns only p-value, but not the mean ranks and standard errors for each group.
I have also tried the
verboseBarplot() of package "WGCNA", it generates a bar plot with standard errors, but I think the height of bars are not mean of the "ranks", but rather seem to be normal mean values.
I have done the analysis as follows, that computes mean ranks and standard errors for each column of x, based on "group" column which is first. Is it correct?
library(plyr) se <- function(x) sd(x)/sqrt(length(x)) colSe <- function(x) apply(x, 2, se) y <- sapply(2:ncol(x),function(i) rank(x[,i])) y <- cbind(x$group,y) colnames(y)<-colnames(x) y <- data.frame(y) m <- ddply(y, .(group),colMeans) m.se <- ddply(y, .(group), colSe) m.se$group <- m$group