Léa Prasin
Léa Prasin

Reputation: 11

plotting effect of the interaction between 2 explanatory variables on the response variable from a generalized linear mixed effect model (glmer) in R

I have the following code glmer(Success ~ Trial*Treatment + 1|ID + Origin + Shelter, family = binomial, data = rama)

It gives me a significant effect of the interaction between Trial and Treatment on the response variable success.

I would like to plot this interaction. I tried to use plot(Success ~ Trial*Treatment, data = rama) But it doesn't plot the interaction, rather makes two different plots, one Success vs Trial and another Success vs Treatment. Ideally, I would like to merge these two graphs, a bit as what I would get if it was an LME instead of a GLME and I plotted (if success was a continuous variable) and I'd use the following code boxplot(Success ~ Trial*Treatment, data = rama)

I would be super happy if anyone has an idea.

Thanks a lot!

Upvotes: 0

Views: 639

Answers (1)

Alex M
Alex M

Reputation: 129

This script does the job, but somehow, the effects are shown as not linear in my case (although they must be linear):

library (ggeffects)

Model_1 = glmer(Success ~ 
                Trial*Treatment + 
                Origin + 
                Shelter +
                (1|ID),
                family = binomial, 
                data = rama)

ggemmeans(Model_1, terms = c("Trial","Treatment")) %>% 
  plot()+
  geom_line (size = 2)

(There was also a problem with the random term in your script I guess, which I corrected.)

Upvotes: 0

Related Questions