Incomplete confidence intervals when using plot_model(type='pred') for an interaction

36 views Asked by At

I am trying to visualize a 2-way interaction from the output of a glmer model. Using the following command, the confidence intervals do not cover the range of the x-axis

plot_model(mod, type = "pred", terms = c('p1T','Age [0, 1]'))

plot 2 levels

This doesn't happen if I replace 'Age' with any other regressor, so it has to do with this specific variable, but I couldn't figure out what the problem is (there are no error messages).

Any solutions?

If I plot any of those lines alone, it works:

plot_model(mod, type = "pred", terms = c('p1T','Age [0]'))

plot 1 level

but the more lines I add, the more the CI is compressed

plot_model(mod, type = "pred", terms = c('p1T','Age [-1, 0, 1, 2]'))

plot 4 levels

EDIT: Here is code to reproduce it, it won't show the same plots because I included only a small fraction of the data (and for the same reason the fit is singular, although it wasn't in the original), but the problem is still there.

rm(list=ls())
library(lmerTest)
library(sjPlot)

Data <- structure(list(ID = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                            4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                            4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                            4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
                            5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
                            5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
                            5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), 
                     Age = structure(c(-0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.305615946691335, -0.305615946691335, -0.305615946691335, 
                           -0.305615946691335, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385, 
                           -0.513914262422385, -0.513914262422385, -0.513914262422385, -0.513914262422385
                            ), .Dim = c(101L, 1L)), 
                     RT = c(NaN, 0.4346, 0.4502, 0.5178, 0.5347, 
                             0.6005, 0.6016, 0.4842, 0.6177, 0.5003, 0.4677, 0.5175, NaN, 
                             0.5012, 0.501, 0.5346, 0.5335, 0.4674, 0.4844, 0.5006, 0.5507, 
                             0.617, 0.5002, 0.5167, 0.5673, 0.5502, 0.5339, 0.5508, 0.6186, 
                             0.567, 0.5178, 0.5837, 0.4842, 0.4833, 0.5335, 0.5338, 0.5017, 
                             0.4503, 0.5335, 0.4844, 0.5339, 0.5516, 0.467, 0.5506, 0.4673, 
                             0.5339, 0.4505, 0.5338, 0.4842, 0.5177, 0.4737, NaN, 0.4735, 
                             0.5073, 0.4676, 0.5, 0.5564, 0.4679, 0.4939, 0.5241, 0.5037, 
                             0.6202, 0.5041, 0.5114, 0.5235, 0.5666, 0.5171, 0.4804, 0.5222, 
                             0.4834, 0.4626, 0.5347, 0.4876, 0.533, 0.5018, 0.5452, 0.6013, 
                             0.5813, 0.5181, 0.5178, 0.61, 0.517, 0.501, 0.5514, 0.4821, 0.5664, 
                             0.4933, 0.5668, 0.5719, 0.5069, 0.5755, 0.4266, 0.5054, 0.5989, 
                             0.5534, 0.5001, 0.5204, 0.4509, 0.5387, 0.6158, 0.492), 
                     pT1 = structure(c(NaN, 
                             0.695852325929399, -0.87163048030357, 0.380396741421878, -1.03186972073904, 
                             -1.67931866808958, 0.17768948521671, -0.454311716461359, 1.50958073345499, 
                             -1.65951416328267, 0.528816776667141, 1.52655551414531, 1.19280478562979, 
                             -0.923295092160813, 0.351641038016252, -0.333417293981416, -1.5700673677479, 
                             -0.971659128209172, -0.175061956126577, 0.39366783995057, 0.845484340115352, 
                             -0.463932003825301, -1.50105755156996, 1.24835654737426, -1.37156158837268, 
                             -1.73317382730965, 0.184043203602285, 0.97102963706563, -1.62425786464887, 
                             -0.238798427008845, -1.04473883869857, -1.69091950626311, -0.572471038976459, 
                             0.183799736861474, 0.506370536102814, 0.753074989667339, 0.640920707613122, 
                             -1.13778069286189, -0.840830108921796, 1.27212425370755, 0.872385446311961, 
                             1.35257768917345, 0.470268161525137, -0.832898701090203, -0.056503324590921, 
                             1.3628240347042, -1.61510448581815, 0.710265680646609, 1.29141159803527, 
                             0.925032412257387, -0.902628137966944, NaN, -0.700053753389964, 
                             -1.69792450503422, -1.00332793954651, 0.345631097771898, -0.662595276240653, 
                             -1.38271414885633, -0.324905185978569, -0.751290269998762, -0.0875172740343353, 
                             0.637890156538075, -0.0581603496976353, 0.605284967414117, 1.75462273131946, 
                             1.07541941891234, -1.16375857485727, -1.08551433509677, -1.17539574725846, 
                             -1.0224616114986, 1.38617798932184, 0.632290905644695, -1.18045208464407, 
                             0.622455161968783, 0.806454432410099, 1.19311220621105, -0.877209811243913, 
                             0.663744680651506, -1.29884576263596, 0.114803599245719, -0.888006192467698, 
                             1.29584688786598, -0.704173537996686, -0.261768985236059, -0.888793949322115, 
                             0.623336417191355, 0.048236056806415, 0.826257881430323, -0.384116263511955, 
                             -1.02507920415628, -1.6962786269349, 0.255034836367215, 1.52348864050875, 
                             0.375308590442165, -1.32229068990004, -1.11095633244043, -0.401711864267233, 
                             -0.82088552863839, -0.757716785167329, -1.36560573823799, 0.770681235785515
                             ), .Dim = c(101L, 1L))), 
                row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 
                            7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
                            20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 
                            33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 
                            46L, 47L, 48L, 49L, 50L, 150L, 151L, 152L, 153L, 154L, 155L, 
                            156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 
                            167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 
                            178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 
                            189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 
                            200L), class = "data.frame")

# Fit model
print(summary(mod <- lmer(RT ~ pT1 + pT1:Age + (1|ID), Data)))

# plot
p <- plot_model(mod, type = "pred", terms = c('pT1','Age  [0, 1]'))
print(p)

R version 4.0.3 (2020-10-10)

Platform: x86_64-w64-mingw32/x64 (64-bit)

Running under: Windows 10 x64 (build 19045)

0

There are 0 answers