0
votes

I am working with a one way anova and want to run a posthoc test. I keep getting an Error:

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

I still cannot find a solution.

My Data looks like this:

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

Then the ANOVA result is:

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
The Tukey posthoc test:

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"

Is anything wrong with my command or dataset? I know this is a very primary question... but if anyone could help me, it would be appreciated! Thanks.

1

1 Answers

0
votes

TukeyHSD works with aov class objects which result from the function aov. The function oneway.test returns an object of class htest. That is the reason of your error. If you want to run TukeyHSD you need to use aov

using your data:

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

data:

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))