Stan_gamm4 prediction error

Hello,

I’m running a hierarchical model with a penalized spine on my time variable using stan_gamm4, however, when I predict I receive an error which seems to be related to new levels. I have tried including the allow_new_levels = TRUE and re_formula = NA in my predict command to no avail. Any thoughts or assistance would be greatly appreciated.

Error in predict.gam(object, newdata, type = type, se.fit = se.fit, terms = terms, :
2, 35, 46, 57, 68, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 90, 101, 103, 105, 106, 108, 109, 111, 114, 115, 119, 120, 122, 123, 125, 126, 127, 130, 131 not in original fit

My model that I run is this:
stan_gamm4(formula = ln_value_pc ~ s(year, by = hc_hp_num, bs = “ps”), random = ~ (1|hc_hp_num/c_num), data = data_104nha, chains = chains, iter = iterations, seed = seed, cores = cores)

While the posterior predict code is this:
posterior_predict(stan_gamm4_pspline_104nha, newdata = nd, allow_new_levels = TRUE, re_formula = NA)

  • RStudio version 1.1.442
  • R version 3.5.1
  • rstanarm Version: 2.18.2

The posterior_predict function has to call predict.gam to set up the design matrix, so if the presence of new levels is unacceptable to predict.gam, then it is not going to work.