This is a normal test result:
attach(airquality)
pw <- pairwise.wilcox.test(Ozone, Month, p.adj = "bonf")
pw
data: Ozone and Month
May Jun Jul Aug
Jun 1.0000 - - -
Jul 0.0003 0.1414 - -
Aug 0.0012 0.2591 1.0000 -
Sep 1.0000 1.0000 0.0074 0.0325
I recently had to do a test with 10 factor levels. Although the bottom triangular file format pairwise.wilcox.test is useful and concise, I thought it would be convenient to place it as a simlar to the Tukey HSD output, where each pairwise combination would be indicated with it as an associated p value. This was my attempt to do this:
pw.df <- as.data.frame(pw$p.value)
pw.diff <- vector("character")
pw.pval <- vector("numeric")
for (i in 1:ncol(pw.df) )
for (j in i:length(pw.df) ) {
pw.diff <- c(pw.diff,paste(colnames(pw.df[i]),"-",rownames(pw.df)[j]))
pw.pval <- c(pw.pval,pw.df[j,i])
}
v <- order(pw.pval,decreasing = F)
pw.df <- data.frame(pw.diff[v],pw.pval[v])
pw.df[pw.df$pw.pval<0.05,]
pw.diff.v. pw.pval.v.
1 May - Jul 0.000299639
2 May - Aug 0.001208078
3 Jul - Sep 0.007442604
4 Aug - Sep 0.032479550
If anyone has any tips / tricks / tips on how to make this easier and / or more elegant, I would be grateful.
source
share