I am wondering if there is a faster way to accomplish something in brms for a project I’m working on. I am developing a patient level microsimulation that includes a number of brms models that use splines on several continuous variables. The micro sim requires me to:
- Sample a cohort of patients (e.g n = 8k)
- Get predicted outcomes based on linked regression equations.
- Repeat this process 1-2k times to incorporate first order (micro simulation) and second order (parameter) uncertainty.
When models don’t have splines this can be very fast since calculating the linear predictor for new data is straightforward. My solution so far has been to use the fitted function with nsamples = 1 but I find this to be very slow. For example, running all 10 fits takes about 6 seconds right now, which which gets out of hand quickly. My guess is that nsamples = 1 is very inefficient since it takes almost as much time to get a fitted object for the full posterior.
Is there something obvious that will allow be to quickly create a the required design matrix for new data to calculate predictions by hand?