Predictions from a fitted model's prior distribution

Given a brms model fitted with the argument save_pars = save_pars(all = TRUE), is there a simple way to make predictions from that model’s sampled prior distribution. I couldn’t find any options to do this in the help files for posterior_epred or posterior_predict.

This is possible only if sample_prior = TRUE was included in the brm call used in model fitting. See Extract prior samples — prior_samples.brmsfit • brms

Above, I mistakenly wrote save_pars = save_pars(all = TRUE) instead of sample_prior = TRUE. Assuming that argument has been specified, do you know of an easy way to make predictions, from a data frame (e.g., using posterior_epred), using the prior rather than the posterior? I realise the utility of doing this may not be obvious, but it’s complicated to explain and I wanted to keep the post brief.

1 Like

Ah, I misread; I thought you just wanted to draw samples of the parameter vector, not make predictions of the response to new data. The easiest way to do this, if you have the bandwidth for a re-fit, is to run a second time with sample_prior = "only", and use posterior_predict on that. If that’s prohibitive, it should be possible to hack around inside a copy of the brmsfit to insert the prior draws where currently there are posterior draws, but I think that would be a bit involved.

1 Like

Thanks, running the model again is what I have done before, but the “problem” is that the draws from this prior distribution are no longer exactly the same as in the first model. Your “hack” idea sounds like it would achieve what I wanted (in the absence of a more straightforward solution). Actually, I have just thought, I could run the model twice once with sample_prior = TRUE and once wth sample_prior = "only" but with the same random seed. Then, presumably, the prior distributions’ draws will be exactly the same?

(The reason I want precisely the same prior distribution draws is because I am testing for differences between the Bayes factors calculated directly from the posterior by brms::hypothesis() and calculating them from draws of average predicted distributions made by marginaleffects::avg_comparisons() with the BF calculated by bayestestR::bayesfactor_parameters(). This is an attempt to find a smooth workflow for obtaining Bayes factors for specific contrasts when there are several interactions in the model, which makes specifying the contrast with coefficients (in brms::hypothesis()) challenging, particularly if using recommended contrasts for “equal marginal priors” as per bayestestR::contr.equalprior).

This will not give you identical prior draws between the two approaches, for two reasons. The more fundamental is that sample_prior = "only" simulates from the prior via HMC, whereas TRUE simulates from the prior via RNGs in generated quantities. Even absent that difference, you’d get different results because the pseudorandom number stream would get advanced in sample_prior = TRUE by all of the random number generation involved in doing the posterior inference.

Thank you for that explanation. So the “hacky” way is probably the only solution for now.