13.5 Posterior predictions

The function brms::posterior_predict returns samples from the posterior predictive distribution of a brms_fit object. For example, the code below yields 4000 sampled predictions for each of the 269 year values in the world temperature data set.

samples_post_pred_temperature <- brms::posterior_predict(fit_temperature)
dim(samples_post_pred_temperature)
## [1] 4000  269

The function brms::posterior_predict can also be used to sample from the posterior predictive distribution of a fitted regression model for new values of the model’s predictors. If we are interested in predictions of average world surface temperature for the years 2025 and 2040, all we need to do is supply a data frame (or tibble) with the predictor values of interest as an argument.

# create a tibble with new predictor values
X_new <- tribble(
  ~ "year", 2025, 2040
)
# get sample predictions from the Bayesian model
post_pred_new <- brms::posterior_predict(fit_temperature, X_new)
# get a (Bayesian) summary for these posterior samples
rbind(
  aida::summarize_sample_vector(post_pred_new[,1], "2025"),
  aida::summarize_sample_vector(post_pred_new[,2], "2040")  
)
## # A tibble: 2 × 4
##   Parameter `|95%`  mean `95%|`
##   <chr>      <dbl> <dbl>  <dbl>
## 1 2025        8.43  9.19   9.99
## 2 2040        8.50  9.30  10.1