简体   繁体   English

如何在R中执行Tukey的成对测试?

[英]How to perform Tukey's pairwise test in R?

I have the following data (dat) 我有以下数据(日期)

I have the following data(dat) 我有以下数据(日期)

V  W  X    Y   Z
1  8  89   3  900
1  8  100  2  800
0  9  333  4  980
0  9  560  1  999

I wish to perform TukeysHSD pairwise test to the above data set. 我希望对上述数据集执行TukeysHSD成对测试。

library(reshape2)
dat1 <- gather(dat) #convert to long form
pairwise.t.test(dat1$key, dat1$value, p.adj = "holm")

However, every time I try to run it, it keeps running and does not yield an output. 但是,每次我尝试运行它时,它都会继续运行,并且不会产生输出。 Any suggestions on how to correct this? 关于如何纠正这一点的任何建议?

I would also like to perform the same test using the function TukeyHSD(). 我还想使用功能TukeyHSD()执行相同的测试。 However, when I try to use the wide/long format, I run into a error that says 但是,当我尝试使用宽/长格式时,我遇到了一个错误,指出

    " Error in UseMethod("TukeyHSD") : 
  no applicable method for 'TukeyHSD' applied to an object of class "data.frame"

We need 'x' to be dat1$value as it is not specified the first argument is taken as 'x' and second as 'g' 我们需要将'x'设为dat1 $ value,因为未指定第一个参数为'x',第二个参数为'g'

pairwise.t.test( dat1$value, dat1$key, p.adj = "holm")
#data:  dat1$value and dat1$key 

#  V       W       X       Y      
#W 1.000   -       -       -      
#X 0.018   0.018   -       -      
#Y 1.000   1.000   0.018   -      
#Z 4.1e-08 4.1e-08 2.8e-06 4.1e-08

#P value adjustment method: holm 

Or we specify the argument and use in any order we wanted 或者我们指定参数并以我们想要的任何顺序使用

pairwise.t.test(g = dat1$key, x= dat1$value, p.adj = "holm")

Regarding the TukeyHSD 关于TukeyHSD

TukeyHSD(aov(value~key, data = dat1), ordered = TRUE)
#Tukey multiple comparisons of means
#    95% family-wise confidence level
#    factor levels have been ordered

#Fit: aov(formula = value ~ key, data = dat1)

#$key
#      diff        lwr       upr     p adj
#Y-V   2.00 -233.42378  237.4238 0.9999999
#W-V   8.00 -227.42378  243.4238 0.9999691
#X-V 270.00   34.57622  505.4238 0.0211466
#Z-V 919.25  683.82622 1154.6738 0.0000000
#W-Y   6.00 -229.42378  241.4238 0.9999902
#X-Y 268.00   32.57622  503.4238 0.0222406
#Z-Y 917.25  681.82622 1152.6738 0.0000000
#X-W 262.00   26.57622  497.4238 0.0258644
#Z-W 911.25  675.82622 1146.6738 0.0000000
#Z-X 649.25  413.82622  884.6738 0.0000034

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM