Please also provide the following information in addition to your question:
Operating System: macOS Mojave 10.14.6
rstanarm Version: 2.18.2
First, thank you to the developers of rstanarm, it’s such a user-friendly way to learn Bayesian statistics.
I have been unable to use the posterior_vs_predict function for rstanarm Poisson or Negative binomial models. I have read through the R documentation and googled but I still don’t understand why I can’t get it to work. In a recent statistics class, the teacher (on Linux, I believe same version of rstanarm) also encountered this problem. Is there something different I must call within this function for Poisson or Neg binomial models? For Gaussian or Binomial rstanarm models I normally use the below code with no issues:
posterior_vs_prior(rstanarm.model, pars = c(‘parameters specified by name’),
color_by = ‘vs’, group_by = TRUE, facet_args = list(scales = ‘free_y’))
Even keeping it simple, eg. posterior_vs_prior(rstanarm.model), this won’t work with a Poisson or Neg binomial model.
Thanks for your response. You reminded me of the importance of going back to the basics to locate the issue!
Keeping with your minimal example, it’s only when changing both the iterations and warmup from the default that the plot throws an error.
stp ← stan_glm(y ~ x, data = d, family = poisson, iter = 5000, warmup = 2000)
posterior_vs_prior(stp)
Error in FUN(newX[, i], . . . ) : is.atomic(x) is not TRUE
I don’t really understand the error, except x is not an atomic vector. Isn’t a numeric vector (which x is currently classified as) a type of atomic vector?
I believe it may be something to do with the default warmup to iteration ratio for Poisson and Negative binomial models being set at 50%. I assume this is in place as a safe guard.
I decreased the warmup (to 40%) in my models since validation checks still looked good and I thought it’s best to make use of as many samples as possible. Is this unnecessary?
Thank you!
I really like the posterior_vs_prior function as it’s a quick and easy way to check my priors makes sense, so I’m looking forward to a solution.
Thanks, yea I have been doing the former example and it’s fine. It would only provide more flexibility if I can change the warmup and still use this function in the future.
Maybe it’s time I learn rstan/stan.
I should be revising my paper but couldn’t stop thinking about this. This is also more for others who might hit this problem. If you load bayesplot first and then use this slightly hacked together version of the original function, I think you can keep using it even when you specify the warmup = 2000 in the original stan_glm call.
Thanks for reporting this and for attempting to troubleshoot! I haven’t had a chance to look seriously into it yet but hopefully will in the coming days.