My question is how do I run a post hoc on a type 2 Anova (mixed-effects model)? So far I am using the glmer()
from the "lme4" package, the Anova()
from the "car" package, and trying to run a HSD test from the "agricolae" package.
After searching for some time this is the best that I could find, however, I receive an error message when doing so. Does anyone know how to get around this or what I am doing wrong? Or a different way of doing this?
library(lme4)
totaldiversity.model <- glmer(totaldiversity ~ focalspecies + (1|site), family = "poisson", data = data, na.action=na.fail)
library(car)
totaldiv.anova = Anova(totaldiversity.model, type = "II")
library(agricolae)
totaldiv.tukey = HSD.test(totaldiv.anova, "focalspecies", group=TRUE, console=TRUE)
Error message that comes up: Error in HSD.test(totaldiv.anova, "focalspecies", group = TRUE, console = TRUE, : argument "MSerror" is missing, with no default
Thank you in advance!
I followed the link posted by Ben Bolker (Post-hoc test for glmer) which led me to use the glht()
function in the multcomp package. This is what the solution looked like for a multiple comparisons analysis (Tukey) on a glmer()
mixed effects model, with a type 2 Anova. Need "multcomp", "lme4", and "car" packages.
totaldiversity.model <- glmer(totaldiversity ~ focalspecies + (1|site), family = "poisson", data = data, na.action=na.fail)
summary(totaldiversity.model)
Anova(totaldiversity.model, type = "II")
summary(glht(totaldiversity.model, mcp(focalspecies="Tukey")))
Thanks everyone!