posterior_predict {geostan} | R Documentation |
Draw samples from the posterior predictive distribution of a fitted geostan
model.
posterior_predict(object, S, summary = FALSE, width = 0.95, car_parts, seed)
object |
A |
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 |
width |
Only used if |
car_parts |
Data for CAR model specification; only required for |
seed |
A single integer value to be used in a call to |
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
).
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)