Reputation: 11
I built a linear mixed model and did a post hoc test for it. Fixed factors are the phase numbers (time) and the group.
statistic_of_comp <- function (x, df) {
x.full.1 <- lmer(x ~ phase_num + group + (1|mouse), data=df, REML = FALSE)
x_phase.null.1 <- lmer(x ~ group + (1|mouse), data=df, REML = FALSE)
print(anova (x.full.1, x_phase.null.1))
summary(glht(x.full.1, linfct=mcp(phase_num="Tukey")))
}
Now my problem is, that I want to do a post hoc test with more than one fixed factor. I found the following
linfct=mcp(phase_num="Tukey", group="Tukey)
but that doesn't give the result I want. At the moment I get the comparison for the groups with Tukey (every group with every other group) and the comparison between the two phases.
What I want is a comparison of the phase_numbers for every group. e.g. group1 phase1-phase2 ..., group2 phase1-phase2 etc.
Upvotes: 1
Views: 2165
Reputation: 226162
I'm sure you can do this with multcomp
, but let me illustrate how to do it with the emmeans
package. I'm going to use a regular linear model (since you haven't given a reproducible example), but the recipe below should work just as well with a mixed model.
Linear model from ?emmeans
(using a built-in data set):
warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks)
Apply emmeans()
, followed by the pairs()
function:
pairs(emmeans(warp.lm , ~tension|wool))
wool = A:
contrast estimate SE df t.ratio p.value
L - M 20.556 5.16 48 3.986 0.0007
L - H 20.000 5.16 48 3.878 0.0009
M - H -0.556 5.16 48 -0.108 0.9936
wool = B:
contrast estimate SE df t.ratio p.value
L - M -0.556 5.16 48 -0.108 0.9936
L - H 9.444 5.16 48 1.831 0.1704
M - H 10.000 5.16 48 1.939 0.1389
For more information, see ?pairs.emmGrid
or vignette("comparisons",package="emmeans")
(which clarifies that these tests do indeed use Tukey comparisons by default).
Upvotes: 2