Expected Value of Posterior vs. Posterior of Expected Value with epred

I guess Mcelreath can explain that a lot better than I can (Statistical Rethinking 2022 Lecture 02 - Bayesian Inference - YouTube) or chapter 3 in rethinking.

For posterior predict you draw a random sample from the respective rng of the likelihood based on the parameter samples in your posterior.
For posterior epred you calculate the mean of your likelihood for each of those posterior samples.
Eg.

posterior_predict_kumaraswamy <- function(i, prep, ...) {
  mu <- brms::get_dpar(prep, "mu", i = i) # mu for the kumaraswamy is the median
  p <- brms::get_dpar(prep, "p", i = i)
  return(rkumaraswamy(prep$ndraws, mu, p))
}

posterior_epred_kumaraswamy <- function(prep) {
  mu <- brms::get_dpar(prep, "mu") # mu for the kumaraswamy is the median
  p <- brms::get_dpar(prep, "p")
  q <- -(log(2) / log1p(-mu^p))
  return(q * beta((1 + 1 / p), q))
}

So for predict you get draws from the predictive distribution while for epred you get draws of the mean of the ppd.

Hope this helps.

2 Likes