我正在尝试在anova上运行TukeyHSD并不断收到此错误消息:UseMethod(“TukeyHSD”)中出错: 没有适用于'TukeyHSD'的方法适用于“c('anova','data.frame')类的对象”
有人能告诉我这个消息是什么意思吗? 我对R很新,所以任何帮助都会受到赞赏!谢谢!
产生此错误的脚本:
a <- data.frame(list(rep(1,100),rnorm(100,50)))
colnames(a) <- c("ID","FeretMinimum")
b <- data.frame(list(rep(2,100),rnorm(100,50)))
colnames(b) <- c("ID","FeretMinimum")
c <- data.frame(list(rep(3,100),rnorm(100,50)))
colnames(c) <- c("ID","FeretMinimum")
d <- data.frame(list(rep(4,100),rnorm(100,50)))
colnames(d) <- c("ID","FeretMinimum")
ColumnFilter = "FeretMinimum"
IDFilter = "ID"
groups <- rbind(a, b ,c ,d)
group.1 <- lm(groups[[ColumnFilter]]~groups[[IDFilter]], data=groups)
aov<- anova(group.1)
print(aov)
posthoc <- TukeyHSD(x=aov, as.factor(groups[[ColumnFilter]]), conf.level=0.95)
答案 0 :(得分:1)
错误消息说明了一切。阅读帮助页面。该函数期待aov-fit对象而不是anova对象。
aov.fit1 <- aov(FeretMinimum ~ factor(ID), data=groups)
posthoc <- TukeyHSD(x=aov.fit1, conf.level=0.95)
posthoc
#----------
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = FeretMinimum ~ factor(ID), data = groups)
$`factor(ID)`
diff lwr upr p adj
2-1 -0.139461021 -0.4988176 0.2198956 0.7487518
3-1 -0.125291199 -0.4846478 0.2340654 0.8050820
4-1 -0.138264399 -0.4976210 0.2210922 0.7537054
3-2 0.014169822 -0.3451868 0.3735264 0.9996226
4-2 0.001196622 -0.3581600 0.3605532 0.9999998
4-3 -0.012973200 -0.3723298 0.3463834 0.9997102