Draw samples from the posterior predictive distribution of a fitted geostan model.

posterior_predict(object, S, summary = FALSE, width = 0.95, car_parts, seed)

Arguments

object

A geostan_fit object.

S

Optional; number of samples to take from the posterior distribution. The default, and maximum, is the total number of samples stored in the model.

summary

Should the predictive distribution be summarized by its means and central quantile intervals? If summary = FALSE, an S x N matrix of samples will be returned. If summary = TRUE, then a data.frame with the means and 100*width credible intervals is returned.

width

Only used if summary = TRUE, to set the quantiles for the credible intervals. Defaults to width = 0.95.

car_parts

Data for CAR model specification; only required for stan_car with family = auto_gaussian().

seed

A single integer value to be used in a call to set.seed before taking samples from the posterior distribution.

Value

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 mu, lwr, and upr).

Examples

 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)