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

Error in dimnames(reMatrix) <- *vtmp* : 'dimnames' applied to non-array #118

Open
brandondey opened this issue Feb 12, 2021 · 3 comments
Open

Comments

@brandondey
Copy link

predictInterval throws this error when there's more than one random effect term. The problem seems to be line 177 in merPredict.R. An example:

I have 23 levels in a grouping factor, names of which are in alllvl:

alllvl = letters[1:23]

My reMatrix looks like:

reMatrix = list(size = structure(c(0.0010590513633398, 0.00130942496234446,
0.00129894979503106, 0.00118412346502953, 0.00116751337164642,
0.00130986225366811, 0.0012815709812561, 0.00122341615092764,
0.0013055710142556, 0.00119962011691454, 0.00117346872472058,
0.00130978072280987, 0.00129631915092133, 0.00130929613187338,
0.00126293324291472, 0.00118125023094927, 0.00129247399987755,
0.00127080564553264, 0.00115105006299901, 0.00113803319542948,
0.00125943975352465, 0.00128281177379072, 0.00130993387574278
), .Dim = c(1L, 1L, 23L)), (Intercept) = structure(c(0.00616517388531857,
0.0728379145733699, 0.0277587954760533, 0.0170618925751313, 0.0228251867556144,
0.0935383181277517, 0.0323877731661849, 0.0156046527666698, 0.0479869499664141,
0.00985455715978766, 0.0117280054681569, 0.0951347183845107,
0.0482523323875463, 0.0648854105503106, 0.0299101857039257, 0.0126892495431074,
0.020004630031733, 0.0183821561488726, 0.00930078032646545, 0.0141397642837315,
0.0145113112521174, 0.0287140193778731, 0.0827959661462078), .Dim = c(1L,
1L, 23L)))
This fails:
dimnames(reMatrix)[[3]] <- alllvl

This works (after modifying the dimnames of the size random effect explicitely)
dimnames(reMatrix$size)[[3]] <- alllvl

@brandondey
Copy link
Author

reMatrix is a list of arrays containing the covariance matrices over each of the 23 levels of the grouping variable.

It's not just having more than one term because this works fine:

`set.seed(271828)
data(sleepstudy)

sleepstudy$another_var = rnorm(nrow(sleepstudy), 0, 1)
fm1 <- lmer(Reaction ~ Days + (Days + another_var |Subject), data=sleepstudy)

PI <- predictInterval(merMod = fm1, newdata = sleepstudy,
level = 0.95, n.sims = 1000,
stat = "median", type="linear.prediction",
include.resid.var = TRUE)`

My model is a glmer.nb, which I know isn't supported.

@brandondey
Copy link
Author

Ah! It's because my intercepts and slopes are uncorrelated. Should have just read the docs more carefully!

This fails with the same error after uncorrelating:

set.seed(271828)
data(sleepstudy)

sleepstudy$another_var = rnorm(nrow(sleepstudy), 0, 1)
fm1 <- lmer(Reaction ~ Days + (Days + another_var || Subject), data=sleepstudy)

PI <- predictInterval(merMod = fm1, newdata = sleepstudy,
level = 0.95, n.sims = 1000,
stat = "median", type="linear.prediction",
include.resid.var = TRUE)

@jknowles
Copy link
Owner

Hi and thanks for this bug report - I think it is related to the issue raised in #101 as well. I think the code is making too strong of assumptions about the shape of the reMatrix and how it is structured, based on assuming the presence of an intercept and other factors.

I don't know when I'll be able to spend time to fix this. At this point I've learned enough from the community to know that there is a simpler and more flexible way to rewrite predictInterval to be more modular, easy to update, and accommodating to a wider array of RE specifications than the initial package scope. It's hard to find the time right now.

But this bug report is a big help.

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

2 participants