Draw samples from the posterior predictive distribution of a fitted
posterior_predict(object, S, summary = FALSE, width = 0.95, car_parts, seed)
Optional; number of samples to take from the posterior distribution. The default, and maximum, is the total number of samples stored in the model.
Should the predictive distribution be summarized by its means and central quantile intervals? If
summary = FALSE, an
N matrix of samples will be returned. If
summary = TRUE, then a
data.frame with the means and
100*width credible intervals is returned.
Only used if
summary = TRUE, to set the quantiles for the credible intervals. Defaults to
width = 0.95.
Data for CAR model specification; only required for
family = auto_gaussian().
A single integer value to be used in a call to
set.seed before taking samples from the posterior distribution.
A matrix of size S x N containing samples from the posterior predictive distribution, where S is the number of samples drawn and N is the number of observations. If
summary = TRUE, a
data.frame with N rows and 3 columns is returned (with column names
fit <- stan_glm(sents ~ offset(log(expected_sents)), re = ~ name, data = sentencing, family = poisson(), chains = 2, iter = 600) # for speed only yrep <- posterior_predict(fit, S = 65) plot(density(yrep[1,])) for (i in 2:nrow(yrep)) lines(density(yrep[i,]), col = 'gray30') lines(density(sentencing$sents), col = 'darkred', lwd = 2)