Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predictInterval: coefs[, 1:colIdx, lvl] : subscript out of bounds #101

Open
rdeneer opened this issue Mar 11, 2019 · 8 comments
Open

predictInterval: coefs[, 1:colIdx, lvl] : subscript out of bounds #101

rdeneer opened this issue Mar 11, 2019 · 8 comments

Comments

@rdeneer
Copy link

rdeneer commented Mar 11, 2019

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

@jknowles
Copy link
Owner

jknowles commented May 1, 2019

Closed by #104

@jknowles jknowles closed this as completed May 1, 2019
@HRodenhizer
Copy link

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

@jknowles
Copy link
Owner

jknowles commented May 6, 2019

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.

@jknowles
Copy link
Owner

jknowles commented May 7, 2019

Actually the current dev version should work remotes::install_github("jknowles/merTools") - CRAN version coming within 30 days.

@HRodenhizer
Copy link

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

@jknowles
Copy link
Owner

jknowles commented May 8, 2019

Huh. Thanks! I guess we're not indexing right in cases without intercepts. We will get this fixed soon.

@jknowles jknowles reopened this May 8, 2019
jknowles added a commit that referenced this issue May 11, 2019
@HRodenhizer
Copy link

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

@jknowles jknowles reopened this May 28, 2019
@jknowles
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants