This is in the context of a linear mixed effects model, though I'm not sure that changes things.

Imagine two dichotomous predictors: Factor A and Factor B.

The model includes the following predictors: A + B + AxB

What precisely is the interaction term testing? I had assumed it tested whether the effect of A differed based on levels of B. But someone recently suggested this might not be the case, and that a type-III ANOVA would be necessary to evaluate the significance of this interaction.

Could anyone help me understand exactly what the AxB interaction is testing, especially with regards to my earlier understanding?


Here is some R Code for the sort of model I describe, and the resulting output.


Subject <- rep(1:30, each = 12)
Item <- rep(1:12, times = 30)
IV1 <- rep(rep(c("A", "B"), each = 6), times = 10)
IV2 <- rep(c("A", "B"),times = 180)
DV <- sample(c(0,1), replace = TRUE, size = 360)

data <- as.data.table(cbind(Subject, Item, IV1, IV2, DV))

data$IV1 <- as.factor(data$IV1)
data$IV2 <- as.factor(data$IV2)
data$DV <- as.factor(data$DV)

contrasts(data$IV1) <- c(1, -1)
contrasts(data$IV2) <- c(1, -1)

m <- glmer(DV ~ IV1*IV2 + (1|Subject) + (1|Item), family = "binomial", data = data)

Resulting output:

Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
 Family: binomial  ( logit )
Formula: DV ~ IV1 * IV2 + (1 | Subject) + (1 | Item)
   Data: data

     AIC      BIC   logLik deviance df.resid 
   507.5    530.8   -247.7    495.5      354 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-1.1435 -1.0000  0.8745  0.8745  1.0690 

Random effects:
 Groups  Name        Variance Std.Dev.
 Subject (Intercept) 1e-12    1e-06   
 Item    (Intercept) 0e+00    0e+00   
Number of obs: 360, groups:  Subject, 30; Item, 12

Fixed effects:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)  0.10075    0.10594   0.951    0.342
IV11         0.16751    0.10594   1.581    0.114
IV21        -0.03338    0.10594  -0.315    0.753
IV11:IV21    0.03338    0.10594   0.315    0.753

Correlation of Fixed Effects:
          (Intr) IV11   IV21  
IV11       0.008              
IV21       0.001 -0.001       
IV11:IV21 -0.001  0.001  0.008

1 Answer 1


The interaction term does what you said, it estimates the interaction between A and B. For continuous variables this means that you have one slope for these two variables, which tells you how the effect changes with varying A and B.

When you have two discrete variables, you get as many terms ("slopes") as there are levels, since these two variables can only change in discrete values, and so you cannot get only 1 term out as you would in the continuous case.

Similarly to testing whether a factor has all terms equal to some value (say 0), you would then use an ANOVA on the linear model to test whether the interaction (or factor variable) is significant overall, because you have to group all the levels together.

Edit: in your case you do get only 1 term/coefficient for the interaction, that represents the interaction for the only other non-reference level, B in your case. So that is the difference of the effect of B, compared to A.

Note: I don't know why you changed the contrasts, but if you keep them original it will be more clear.

Fixed effects:
            Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.09125    0.22119  -0.413    0.680
IV1B         0.41253    0.30400   1.357    0.175
IV2B        -0.23022    0.30383  -0.758    0.449
IV1B:IV2B   -0.27381    0.42998  -0.637    0.524

Anyway, in your case:

(Intercept) is the effect of A of IV1 and A of IV2
IV11 is the effect of B of IV1, compared to A of IV1
IV21 is the effect of B of IV2, compared to A of IV2
IV11:IV21 is the effect of B of IV1 and B of IV2, compared to A of IV1 and A of IV2

So as you see, the one term for the intercept is for the second levels of IV1 and IV2, while the effect of the first levels - the references - is already coded in the intercept.

  • $\begingroup$ Thanks for the response! Do you know if the "lme4" or "lmerTest" packages already do this when displaying coefficients and p values for interactions? $\endgroup$
    – Dave
    Oct 3, 2019 at 19:38
  • $\begingroup$ @Dave lme4 and lmerTest will display p-values for each individual term - for each "slope". If you want to get the overall p-value for the whole interaction (in case of discrete values), then you need to use an ANOVA, but I am not sure about type III SS, that depends on your data. $\endgroup$ Oct 4, 2019 at 6:18
  • $\begingroup$ Thanks for getting back to me again. I was hoping you could clarify something. The lme4 output gives me a single coefficient for the interaction. What exactly does this represent? $\endgroup$
    – Dave
    Oct 4, 2019 at 22:17
  • $\begingroup$ @Dave Can you post the output in your question? $\endgroup$ Oct 5, 2019 at 7:52
  • $\begingroup$ Sure! I edited the question to provide sample R code and output. $\endgroup$
    – Dave
    Oct 7, 2019 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.