Pairwise.wilcox.test - formatting output

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])
  }


# order them by ascending p value
v <- order(pw.pval,decreasing = F)
pw.df <- data.frame(pw.diff[v],pw.pval[v])


# display those that are significant at the 5% level
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.

+5
source share
1 answer

reshape reshape2 , melt(). , pairwise.wilcox.test, , , - melt(pw[[3]]) :

    X1  X2       value
1  Jun May 1.000000000
2  Jul May 0.000299639
3  Aug May 0.001208078
4  Sep May 1.000000000
5  Jun Jun          NA
....
+9

All Articles