pairwise.wilcox.test - 重新格式化输出
这是测试的正常输出:
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
我最近必须进行 10 个因子水平的测试。虽然pairwise.wilcox.test的下三角格式有用且简洁,但我认为以与Tukey HSD输出类似的方式排列它会很方便,其中列出了每个成对组合及其相关的p值。这是我的尝试:
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
如果有人有一些关于如何使这更容易和/或更优雅的提示/技巧/建议,我将不胜感激。
This is the normal output from the test:
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 conduct a test with 10 levels of a factor. While the lower triangular format of the pairwise.wilcox.test is useful and concise, I thought it would be convenient to arrange it in a simlar way to the Tukey HSD output where each pairwise combination is listed along with it's asociated 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 some tips/tricks/advice on how to make this easier and/or more elegant I would be grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将使用
reshape
或reshape2
包来完成此任务,特别是melt()
命令。 pairwise.wilcox.test 返回的对象包含第三个槽中感兴趣的数据,因此像melt(pw[[3]])
这样的东西应该可以解决问题:I would use the
reshape
orreshape2
package for this task, specifically themelt()
command. The object returned by pairwise.wilcox.test contains the data of interest in the third slot, so something likemelt(pw[[3]])
should do the trick: