posterior_predict() doesn't work on three-level models
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 401
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
Summary:
posterior_predict() with new group levels doesn't work on three-level models because pp_b_ord() assembles the wrong name containing the substring _NEW_. It raises a no matches bug error.
Description:
A model fit with a three-level random effect like (1 | a/b/c) doesn't work with posterior_predict() when there are new group levels. I traced through the code and found the error happens when it's trying to match Z_names with columns from the posterior distribution in the function pp_b_ord().
Aside from fixing this code, is there any way to manually pull out the posterior samples for _NEW_ levels?
Reproducible Steps:
library(lme4)
library(dplyr)
library(rstanarm)
zzz <- stan_lmer(
angle ~ 1 + (1 | replicate/recipe/temp),
data = cake,
prior_PD = TRUE,
iter = 100,
chains = 1)
new_cake <- cake %>%
distinct(temp, recipe) %>%
mutate(replicate = 100)
# Failure on a new grouping level
posterior_linpred(zzz, newdata = new_cake)
old_cake <- cake %>%
distinct(temp, recipe) %>%
mutate(replicate = 1)
# Works on a known grouping level
posterior_linpred(zzz, newdata = old_cake)
RStanARM Version:
2.17.4
R Version:
3.4.x
Operating System:
Windows 10
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the three-level model and new_cake example, then trace the Z_names matching in pp_b_ord(). Compare it with the known-group old_cake case. Done means posterior_linpred() works for new grouping levels in three-level models without the no matches bug.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100