How to obtain prediction based on a grouping variable from stan_glm() in rstanarm


#1

I was wondering how to obtain the posterior prediction based on a grouping variable from stan_glm()?

For example, if I have a binary (0, 1) coded grouping variable called "vs" in my data, how can I obtain the prediction for vs == 0 and vs == 1?

Here is my R code:

fit <- stan_glm(mpg ~ ., data = mtcars)

posterior_predict(fit, newdata = ??)

#2
nd <- mtcars
nd$vs <- 0
PPD_0 <- posterior_predict(fit, newdata = nd)
nd$vs <- 1
PPD_1 <- posterior_predict(fit, newdata = nd)