Aggregate predictions of brms::posterior_predict

I’m quite new to stan and brms, so I hope this question makes sense. I’m using brms::posterior_predict to get the predictions for new data based on my fitted zero-inflated beta model. For each new data point I’m getting a sample of n=2000 predicted outcomes. Since all data points are coming from a certain spatial location I would like to spatially aggregate and summarise them using the sum of all predictions that are within a certain area (i.e. based on their zip code). Ideally, I would be able to calculate the 5% and 95% as well as the median for the sum of all predictions in an zip code area based on multiple predictions from brms::posterior_predict. Is there a straightforward and/or recommended way to do this? (i.e. using convolution or by summing the summary statistics of each prediction?)

  • Operating System: Windows 7 Professional Service Pack 1
  • brms Version: 2.3.1

Basically, you can do anything to the matrix that posterior_predict produces, but you have to apply the function to each of the rows in order to have a distribution at the end. Something like,

apply(posterior_predict(fit), MARGIN = 1, FUN = foo, extra_arguments_passed_to_foo)

Don’t try to calculate some summary column-wise and then do something with that.

1 Like