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

get_predicted() with nested random effects #981

Open
a-difabio opened this issue Dec 16, 2024 · 0 comments
Open

get_predicted() with nested random effects #981

a-difabio opened this issue Dec 16, 2024 · 0 comments
Labels
Bug 🐛 Something isn't working

Comments

@a-difabio
Copy link

There are two problems when using the get_predicted() function on a model containing nested random effect terms.

First, the function gives an error if a fixed effect term is also included in the random effects, for instance as a grouping level (see the reg term in this model). This might not make scientific sense in this particular case, but might be useful for other real-world models.

library(lme4)
#> Loading required package: Matrix
library(insight)

model = lmer(total.fruits ~ amd + reg + (1 | reg:popu), data = Arabidopsis)

pred = get_predicted(model)
#> Error in X %*% fixef(object): non-conformable arguments

Second, the terms describing lower groupings (for instance the reg:popu term in this model) are not recognized as individual terms, so the function (silently, if include_random is "default") drops the random effects from the predictions.

model2 = lmer(total.fruits ~ amd + (1 | reg:popu), data = Arabidopsis)

pred2 = get_predicted(model2, include_random = TRUE)
#> Warning: `include_random` was set to `TRUE`, but not all random effects were
#>   found in `data`.
#>   Setting `include_random = FALSE` now.

packageVersion("lme4")
#> [1] '1.1.35.5'
packageVersion("insight")
#> [1] '0.20.4'

Created on 2024-12-16 with reprex v2.1.0

@strengejacke strengejacke added the Bug 🐛 Something isn't working label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants