# NOT RUN {
# Example using rstanarm package:
# posterior_predict method for 'stanreg' objects
# }
# NOT RUN {
if (require("rstanarm")) {
fit <- stan_glm(mpg ~ wt + am, data = mtcars)
yrep <- posterior_predict(fit)
all.equal(ncol(yrep), nobs(fit))
nd <- data.frame(wt = mean(mtcars$wt), am = c(0, 1))
ytilde <- posterior_predict(fit, newdata = nd)
all.equal(ncol(ytilde), nrow(nd))
}
# }
# NOT RUN {
# Also see help("posterior_predict", package = "rstanarm")
# }
Run the code above in your browser using DataLab