R中的HSD Tukey测试错误

时间:2018-07-02 11:50:15

标签: r

我正在使用一种单因素方差分析,希望进行事后测试。我不断收到错误消息:

  

UseMethod(“ TukeyHSD”)中的错误:     没有将“ TukeyHSD”的适用方法应用于“功能”类的对象

我仍然找不到解决方法。

我的数据如下:

Treatment	IND
T 1	7
T 1	7
T 1	10
T 1	5
T 1	10
T 1	10
T 1	12
T 1	8
T 1	1
T 1	8
T 1	14
T 1	9
T 1	10
T 1	10
T 1	6
T 1	9
T 1	9
T 1	11
T 1	2
T 1	6
T 1	5
T 1	9
T 1	11
T 1	9
T 1	7
T 1	12
T 1	11
T 1	8
T 1	10
T 1	9
T 1	11
T 1	9
T 1	4
T 1	9
T 1	11
T 1	11
T 1	9
T 1	12
T 1	13
T 1	11
T 1	9
T 1	10
T 1	7
T 1	7
T 1	8
T 1	11
T 1	1
T 2	7
T 2	8
T 2	5
T 2	8
T 2	4
T 2	5
T 2	3
T 2	3
T 2	4
T 2	4
T 2	5
T 2	4
T 2	5
T 2	6
T 2	4
T 2	8
T 2	7
T 2	5
T 2	6
T 2	6
T 2	3
T 2	7
T 2	4
T 2	4
T 2	4
T 2	6
T 2	5
T 2	6
T 2	6
T 2	3
T 2	5
T 2	5
T 2	7
T 2	7
T 2	5
T 2	3
T 2	6
T 2	6
T 2	7
T 2	7
T 2	5
T 2	3
T 2	7
T 2	6
T 2	8
T 2	5
T 2	7
T 2	5
T 2	6
T 3	7
T 3	11
T 3	8
T 3	10
T 3	7
T 3	10
T 3	10
T 3	6
T 3	9
T 3	8
T 3	7
T 3	14
T 3	9
T 3	8
T 3	15
T 3	13
T 3	5
T 3	9
T 3	9
T 3	10
T 3	10
T 3	12
T 3	13
T 3	10
T 3	9
T 3	10
T 3	7
T 3	9
T 3	9
T 3	11
T 3	7
T 3	11
T 3	7
T 3	11
T 3	9
T 3	10
T 3	7
T 3	5
T 3	9
T 3	10
T 3	11
T 3	12
T 3	11
T 3	9
T 3	9
T 3	4
T 3	7
T 3	6
T 3	4

则ANOVA结果为:

  

oneway.test(IND〜Umsiedlung)

 
One-way analysis of means (not assuming equal variances)

data:  IND and Treatment
F = 52.778, num df = 2.000, denom df = 86.334, p-value = 1.063e-15
Tukey posthoc测试:

  

tukey.test <-TukeyHSD(x = oneway.test(IND〜Umsiedlung),conf.level = 0.95)

tukey.test

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

我的命令或数据集有问题吗?我知道这是一个非常主要的问题...但是,如果有人可以帮助我,将不胜感激!谢谢。

1 个答案:

答案 0 :(得分:0)

TukeyHSD可处理由功能aov产生的aov类对象。函数oneway.test返回类htest的对象。那就是你出错的原因。如果要运行TukeyHSD,则需要使用aov

使用数据:

TukeyHSD(aov(lm(IND ~ Treatment, data = df1)))

  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = IND ~ Treatment, data = df1)

$`Treatment`
            diff        lwr       upr    p adj
T2-T1 -3.2726878 -4.3935451 -2.151831 0.000000
T3-T1  0.3803734 -0.7404838  1.501231 0.701296
T3-T2  3.6530612  2.5439410  4.762181 0.000000

数据:

df1 <- structure(list(Treatment = c("T1", "T1", "T1", "T1", "T1", "T1", 
"T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", 
"T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", 
"T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", 
"T1", "T1", "T1", "T1", "T1", "T1", "T1", "T1", "T2", "T2", "T2", 
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", 
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", 
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", 
"T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", "T2", 
"T2", "T2", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", 
"T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", 
"T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", 
"T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", "T3", 
"T3", "T3", "T3", "T3", "T3", "T3", "T3"), 
                      IND = c(7L, 7L, 10L, 
5L, 10L, 10L, 12L, 8L, 1L, 8L, 14L, 9L, 10L, 10L, 6L, 9L, 9L, 
11L, 2L, 6L, 5L, 9L, 11L, 9L, 7L, 12L, 11L, 8L, 10L, 9L, 11L, 
9L, 4L, 9L, 11L, 11L, 9L, 12L, 13L, 11L, 9L, 10L, 7L, 7L, 8L, 
11L, 1L, 7L, 8L, 5L, 8L, 4L, 5L, 3L, 3L, 4L, 4L, 5L, 4L, 5L, 
6L, 4L, 8L, 7L, 5L, 6L, 6L, 3L, 7L, 4L, 4L, 4L, 6L, 5L, 6L, 6L, 
3L, 5L, 5L, 7L, 7L, 5L, 3L, 6L, 6L, 7L, 7L, 5L, 3L, 7L, 6L, 8L, 
5L, 7L, 5L, 6L, 7L, 11L, 8L, 10L, 7L, 10L, 10L, 6L, 9L, 8L, 7L, 
14L, 9L, 8L, 15L, 13L, 5L, 9L, 9L, 10L, 10L, 12L, 13L, 10L, 9L, 
10L, 7L, 9L, 9L, 11L, 7L, 11L, 7L, 11L, 9L, 10L, 7L, 5L, 9L, 
10L, 11L, 12L, 11L, 9L, 9L, 4L, 7L, 6L, 4L)), 
class = "data.frame", 
row.names = c(NA, -145L))