Home > Enterprise >  Plotting random effects with lmer and sjPlot
Plotting random effects with lmer and sjPlot

Time:12-19

I am currently running a mixed effects model using lmer in which random slopes and correlated random intercepts are estimated. After fitting the model I would like to plot the result allowing from random slopes and intercepts as well as one overall fixed line. How I currently implement is this way:


library(lmer)
library(sjPlot)

df <- read_csv("anonymized_test.csv")
m1 <- lmer("DV ~ IV   (1   IV| iso)", df) 

plot_model(m1, ,type="pred",
           terms=c("IV","iso"),
           pred.type="re", ci.lvl = NA)

This is the result: enter image description here

Which is not what is expected as we would expect some negative and positive slopes in addition to the random intercepts according to the extracted random effects of the model enter image description here

The problem is that sjPlot seems to only plot the random intercepts. Looking at an older vignette of sjPlot this seems to have been implemented in a deprecated function (see enter image description here

However, I also get the random slopes using sjPlot. Not sure what went wrong, maybe you are using outdated software?

sjPlot::plot_model(fm1, type="pred", terms=c("Days","Subject"), pred.type="re", ci.lvl=NA)
# Warning message:
# In RColorBrewer::brewer.pal(n, pal) :
#   n too large, allowed maximum for palette Set1 is 9
# Returning the palette you asked for with that many colors

enter image description here

  • Related