R: interaction in model output

Let's say you're trying to fit a model to a dataset that includes categorical variables, group (A or B) and treatment (1, 2, 3 or 4).

In R, your model formula would be DV ~ group * treatment (DV stands for dependent variable) and your model output will look like this:

(intercept)                 [...]
groupB                      [...]
treatment2                  [...]
treatment3                  [...]
treatment4                  [...]
groupB:treatment2           [...]
groupB:treatment3           [...]
groupB:treatment4           [...]


My question is how to interpret this kind of output. Below is what I believe is right for the interpretation of the main effects, and what puzzles me about the interaction parameters.

(intercept)


This the reference value, i.e. for treatment 1 in group A.

groupB


This is the difference between group A and group B for treatment 1 only.

treatment2


This is the difference between treatment 1 and treatment 2, within group A only. It indeed still refers to the intercept value. Same logic for the two following estimates ("treatment3" and "treatment4").

groupB:treatment2


Here is where I get puzzled. Is this testing if the difference between treatment1 and treatment2 is the same in groupB compared to groupA, or is it testing if if the difference between groupA and groupB is the same for treatment1 compared to treatment2.

I thought this question would be very basic, but I went through several R books with no luck and found inconsistent answers on here (see How to interpret 2-way and 3-way interaction in lmer? for support for the first idea and Interpreting the regression output from a mixed model when interactions between categorical variables are included for the other way).

If that matters, I'm working with the glmer function of the lme4 package.

Thanks!

migrated from stackoverflow.comJun 16 '15 at 10:51

This question came from our site for professional and enthusiast programmers.

• Both actually. These cases can't be distinguished. – Roland Jun 16 '15 at 9:56
• Have a look at the effects package – James Jun 16 '15 at 10:01
• If visual inspection is helpful for you, you might want to check the sjp.int function of the sjPlot-package (see examples here). Maybe this blog-posting is also helpful. – Daniel Jun 16 '15 at 11:58

It think Roland in your comment is right. I guess it could be expanded as an answer. If you draw a table summing your coefficients for each case, you end up with something like that :

+------+--------+--------+
|      | treat1 | treat2 |
+------+--------+--------+
| gpb  |   a    |    b   |
| gpa  |   c    |    d   |
+------+--------+--------+


Treatement 3 is volontary omitted. You have :

• $a=intercept+groupB$
• $b=intercept+groupB+treatment2+groupB:treatment2$
• $c=intercept$
• $d=intercept+treatment2$

Your first proposition could be translated as studying $(b-a)-(d-c)$.
Detail : The difference between treatment1 and treatment2 in groupB $(b-a)$, compared to the difference between treatment1 and treatment2 in groupA $(d-c)$.

Similarly, your second proposition could be translated as studying $(b-d)-(a-c)$.

It's then the same expression, and it indeed equals $groupB:treatment2$