predictInterval: coefs[, 1:colIdx, lvl] : subscript out of bounds
Below follows a hypothetical but reproducible example to generate this error. In this example the model does not make any sense but in my case this model does but I cannot share the data.
Image we take the sleepstudy data from lme4, and we define a binary Test variable for each subject which is randomly set to TRUE/FALSE:
sleepstudy$Test <- rep(sample(c(TRUE, FALSE), length(unique(sleepstudy$Subject)), replace = TRUE), each = 10)
Now we fit the following (nonsensical) model:
lmer.sleep <- lmer(Reaction ~ Days:Test + (0 + Days | Subject), data = sleepstudy2)
Then if I use the predictInterval function like so:
predictInterval(lmer.sleep, newdata = sleepstudy)
I get the following error:
Error in coefs[, 1:colIdx, lvl] : subscript out of bounds
Closed by #104
I'm having the same issue with this hypothetical model (same structure as what I am doing but reproducible):
model <- lmer(Reaction ~ 0 + Days + Days:Subject +
(1|Days),
data = sleepstudy)
pred <- predictInterval(model, newdata = sleepstudy)
This returns exactly the same error as above:
Error in coefs[, 1:colIdx, lvl] : subscript out of bounds
This is fixed in the development branch - an update will be pushed to CRAN soon. In the meantime, try installing the margins branch from GitHub.
Actually the current dev version should work remotes::install_github("jknowles/merTools") - CRAN version coming within 30 days.
With the current dev version, I am now getting this error:
Error in dimnames(coefs_new) <- `*vtmp*` :
length of 'dimnames' [2] not equal to array extent
Huh. Thanks! I guess we're not indexing right in cases without intercepts. We will get this fixed soon.
That fix solved the issue when a random effect for repeated measures is included in the model, however it's not working when I incorporate a random effect for nested experimental structure in addition to the repeated measures.
For this example, I am supposing that the sleep study occurred in two different hospitals within two different cities:
sleepstudy <- sleepstudy %>%
mutate(city = c(rep(1, 90), rep(2, 90)),
hospital = paste(city, rep(seq(1, 2), 90), sep = ':'))
model <- lmer(Reaction ~ 0 + Days:Subject +
(1|Days) + (1|city/hospital),
data = sleepstudy)
pred <- predictInterval(model, newdata = sleepstudy)
This results in the same error as before:
Error in dimnames(coefs_new) <- `*vtmp*` :
length of 'dimnames' [2] not equal to array extent
Thanks - I don't encounter models like this so this is helpful. I'll push a fix up when I get a chance and ping you here to let you know when the dev version works.
I've never really tested or supported nested specifications before so it may take me some time to make sure I'm addressing the random effect structure correctly.