I fit a GLM to a dataset. Now I want to see where the difference between my groups is, so I tried to run a Tukey HSD as a post-hoc test.
Because of it is a GLM, I can't use TukeyHSD()
. So I tried to run a Tukey test with:
summary(glht(my.mod, mcp(treatment="Tukey")))
When I tried this, I get the following error:
Variable(s) ‘treatment’ have been specified in ‘linfct’ but cannot be found in ‘model’!
This is what it looks like in R:
> recol
Sample At..Ind. At.Sp. X treatment
1 C1 1 1 0 C
2 C2 2 2 0 C
3 C3 1 1 0 C
4 FS1 1 1 50 FS
5 FS2 4 3 80 FS
6 FS3 0 0 80 FS
7 FL1 3 3 280 FL
8 FL2 4 3 310 FL
9 FL3 2 2 220 FL
10 VS1 2 2 40 VS
11 VS2 0 0 50 VS
12 VS3 1 1 5 VS
13 VL1 3 3 400 VL
14 VL2 7 6 600 VL
15 VL3 3 3 500 VL
16 MS1 1 1 30 MS
17 MS2 3 3 30 MS
18 MS3 0 0 30 MS
19 ML1 2 1 400 ML
20 ML2 7 7 300 ML
21 ML3 7 7 300 ML
> my.mod=glm(Arachnida~as.factor(treatment),data=soort)
> summary(my.mod)
Call:
glm(formula = Arachnida ~ as.factor(treatment), data = soort)
Deviance Residuals:
Min 1Q Median 3Q Max
-2.3333 -0.3333 0.0000 0.0000 2.6667
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.107e-16 6.901e-01 0.000 1.00000
as.factor(treatment)FL -1.277e-16 9.759e-01 0.000 1.00000
as.factor(treatment)FS -3.511e-16 9.759e-01 0.000 1.00000
as.factor(treatment)ML 3.000e+00 9.759e-01 3.074 0.00825 **
as.factor(treatment)MS 3.333e-01 9.759e-01 0.342 0.73775
as.factor(treatment)VL 2.333e+00 9.759e-01 2.391 0.03141 *
as.factor(treatment)VS 3.333e-01 9.759e-01 0.342 0.73775
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for gaussian family taken to be 1.428571)
Null deviance: 48.571 on 20 degrees of freedom
Residual deviance: 20.000 on 14 degrees of freedom
AIC: 74.571
Number of Fisher Scoring iterations: 2
> glht(my.mod, mcp(treatment="Tukey"))
Error in mcp2matrix(model, linfct = linfct) :
Variable(s) ‘treatment’ have been specified in ‘linfct’ but cannot be found in ‘model’
> summary(glht(my.mod, mcp(treatment="Tukey")))
Error in mcp2matrix(model, linfct = linfct) :
Variable(s) ‘treatment’ have been specified in ‘linfct’ but cannot be found in ‘model’
Could anyone help me with my problem?
glht
in? $\endgroup$glht
is in themultcomp
package. @anne: Please post at least the call of theglm
. It seems as if the variabletreatment
was not in the modell. But without more specific details, we can only speculate. $\endgroup$