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)
Summary:
posterior_predict()
with new group levels doesn't work on three-level models becausepp_b_ord()
assembles the wrong name containing the substring_NEW_
. It raises ano matches bug
error.Description:
A model fit with a three-level random effect like
(1 | a/b/c)
doesn't work withposterior_predict()
when there are new group levels. I traced through the code and found the error happens when it's trying to matchZ_names
with columns from the posterior distribution in the functionpp_b_ord()
.Aside from fixing this code, is there any way to manually pull out the posterior samples for
_NEW_
levels?Reproducible Steps:
RStanARM Version:
2.17.4
R Version:
3.4.x
Operating System:
Windows 10