R: Interaction Plot with a continuous and a categorical variable for a GLMM (lme4)

后端 未结 3 648
名媛妹妹
名媛妹妹 2020-12-30 16:05

I would like to make an interaction plot to visually display the difference or similarity in slopes of interaction of a categorical variable (4 levels) and a standardized co

3条回答
  •  星月不相逢
    2020-12-30 17:03

    The jtools package (CRAN link) can make the plotting of this sort of model pretty straightforward. I'm the developer of that package.

    We will fit the model like Ben did in his answer:

    library(lme4)
    fit <- glmer(resp.var ~ cont.var:cat.var + (1 | rand.eff),
                 data = sample.data, family = poisson)
    

    And with jtools we just use the interact_plot function like this:

    library(jtools)
    interact_plot(fit, pred = cont.var, modx = cat.var)
    

    The result:

    By default it plots on the response scale, but you can have it plotted on the linear scale with the outcome.scale = "link" argument (default is "response").

提交回复
热议问题