Your question is can be answered by fully understanding what the
coefficients of the linear (mixed-effects) model mean, which I discuss
in the code files of the 2013 book (but, for lack of space, not in the
printed book. Here's how it works:
#####################################
# I apparently don't understand how best to specify interaction terms
in a mixed effects model with lmerTest::lmer (which is a light wrapper
for lme4::lmer). With an interaction term between 'discrete_var *
gradient_var', when I change the rm(list=ls(all=TRUE)); set.seed(1)
library(lme4); library(effects)
PERSON <- factor(rep(LETTERS, 100))
DV <- sample(1:10, length(PERSON), replace=TRUE)
IVCAT1 <- factor(rep(c("consonant", "vowel"), length(PERSON)/2),
levels=c("consonant", "vowel"))
IVCAT2 <- factor(rep(c("consonant", "vowel"), length(PERSON)/2),
levels=c("vowel", "consonant"))
IVNUM <- runif(length(PERSON))
summary(EXMPL <- data.frame(DV, PERSON, IVCAT1, IVCAT2, IVNUM))
# fixed-effects modeling
model.1.lm <- lm(DV ~ IVCAT1 * IVNUM, data=EXMPL)
model.2.lm <- lm(DV ~ IVCAT2 * IVNUM, data=EXMPL)
allEffects(model.1.lm, xlevels=list(IVNUM=seq(0, 1, 0.25)))
summary(model.1.lm)
# coef 1 / the intercept is the predicted value of the DV when IVCAT
is "consonant" and IVNUM is 0
# coef 2 is what you need to add to the intercept to get the
prediction for when IVCAT is "vowel" and IVNUM is 0
# coef 3 is what you need to add to the intercept to get the
prediction for when IVCAT is "consonant" and IVNUM is 1
# coef 4 is what you need to add to the all previous coefs to get the
prediction for when IVCAT is "vowel" and IVNUM is 1
allEffects(model.2.lm, xlevels=list(IVNUM=seq(0, 1, 0.25)))
summary(model.2.lm)
# coef 1 / the intercept is the predicted value of the DV when IVCAT
is "vowel" and IVNUM is 0
# coef 2 is what you need to add to the intercept to get the
prediction for when IVCAT is "consonant" and IVNUM is 0
# coef 3 is what you need to add to the intercept to get the
prediction for when IVCAT is "vowel" and IVNUM is 1
# coef 4 is what you need to add to the all previous coefs to get the
prediction for when IVCAT is "consonant" and IVNUM is 1
# And all p-values are testing whether the coefficients/estimates are
significantly different from 0.
# The coefficients for IVNUM are different in the two models because
they are the slopes of IVNUM in two different situations:
# - model.1.lm's 3rd coefficient gives you the slope of IVNUM when
IVCAT is "consonant"
# - model.2.lm's 3rd coefficient gives you the slope of IVNUM when
IVCAT is "vowel"
# This is because the interaction term, while not significant, still
says they differ: note that
# - the coefficients of the interaction terms are the same in both
models and, more importantly for your question,
# - the interaction term is the difference between the two slopes in
the two models:
(coef(model.2.lm)[3] - coef(model.1.lm)[3]) # same as
coef(model.1.lm)[4] or coef(model.2.lm)[4]
#####################################
Cheers,
STG
--
Stefan Th. Gries
----------------------------------
Univ. of California, Santa Barbara
http://tinyurl.com/stgries
----------------------------------