0
votes

I'm trying to run TukeyHSD on an anova and keep getting this error message: Error in UseMethod("TukeyHSD") : no applicable method for 'TukeyHSD' applied to an object of class "c('anova', 'data.frame')"

Can anyone tell me what this message means? I'm very new to R so any help would be appreciated! Thanks!

Script that is producing this error:

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)
1
You should read the documentation: aov <- aov(group.1), but of course you'd need factor variables on the RHS.Roland

1 Answers

1
votes

The error message says it all. Read the help page. That function was expecting an aov-fit object not an anova object.

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