Reputation: 111
I estimated a mixed model with the GENLINMIXED command in SPSS. In the model options I specified that I want to estimate simple contrasts for my interaction variable (category*group) by the variable "group". The output of the "simple contrasts" looks like this:
I would like to get the same output in R where I estimate the model with glmer
from the lme4
package. Does anyone know how to do that?
Upvotes: 0
Views: 66
Reputation: 226742
In general you would use the emmeans
package for this. Here's an example using lm()
and a built-in data set: it should work equally well for a glmer
model, substituting ~group | category
in the emmeans()
statement and ref="0"
(or something like that) in the contrast()
statement.
library(emmeans)
warp.lm <- lm(breaks ~ wool*tension, data = warpbreaks)
warp.emm <- emmeans(warp.lm, ~ tension | wool)
cc <- contrast(warp.emm, "trt.vs.ctrl", ref = "L")
summary(cc, infer = TRUE) ## infer = TRUE to get CIs
You can choose the method of multiple comparisons correction using the adjust
argument to summary()
; I think you might use adjust = "tukey"
to match your SPSS results, but I'm not sure.
wool = A:
contrast estimate SE df lower.CL upper.CL t.ratio p.value
M - L -20.556 5.16 48 -32.4 -8.74 -3.986 0.0005
H - L -20.000 5.16 48 -31.8 -8.19 -3.878 0.0006
wool = B:
contrast estimate SE df lower.CL upper.CL t.ratio p.value
M - L 0.556 5.16 48 -11.3 12.37 0.108 0.9863
H - L -9.444 5.16 48 -21.3 2.37 -1.831 0.1338
Confidence level used: 0.95
Conf-level adjustment: dunnettx method for 2 estimates
P value adjustment: dunnettx method for 2 tests
Upvotes: 3