Lili
Lili

Reputation: 587

Reporting interactions in a linear model in r

I am trying to report all the interactions in a linear model that reads:

mod1.lme <- lm(volume ~ Group * Treatment + Group + Treatment, data = df)

Group is a factor variable with 3 levels: A, B and C.

The result that I currently get is for (I made up the data):

enter image description here

These two estimates are in reference to Treatment:A, but I would like to see each effect independently. So the output that I would like to get is:

Treatment:A
Treatment:B
Treatment:C

If I eliminate the intercept adding -1 at the end I get: enter image description here

What is the best way to code this?

Thanks

Upvotes: 0

Views: 447

Answers (1)

Oliver
Oliver

Reputation: 8602

The reason you are seeing the output that you are, is that one of the factor levels of Treatment becomes a reference level. When interpreting the model the coefficients become "the difference in effect from the reference level". This is necessary as long as the model includes an intercept, so the only way to get the interpretation with all coefficients shown is to remove the intercept as shown below.

mod1.lme <- lm(volume ~ Group * Treatment - 1, data = df)

Edit:

To change the name of the interaction effect, one would have to edit the name manually

sum.lm <- summary(mod1.lme)
rownames(sum.lm$coef) <- c("groupA","groupB","groupC", "groupA:Treatment", "groupB:Treatment", "groupC:Treatment")

or alternatively use another package for summaries such as sjPlot

library(sjPlot)
tab_model(mod1.lme, pred.labels = c("groupA","groupB","groupC", "groupA:Treatment", "groupB:Treatment", "groupC:Treatment"))

Upvotes: 1

Related Questions