Simulation using brms

I am conducting a simulation, and for each iteration of the simulation I am going to run a Stan model using brms. The only thing changing from iteration to iteration is the data, so I’d like to pre-compile the model and use update.brmsfit(newdata = new_data) to do the sampling.

My only question is regarding that initial model fit when the model gets compiled. Is there any reason that I can’t do something like set chains=1, iter=1 to pretty much skip the sampling step? This wouldn’t affect the resulting model fits that occur after calling update(), right?

Thanks in advance.

I typically run a prior only model first and then use the resulting posterior to generate new data (with varying numbers of subjects, trials, etc), to feed into update.brms.

I use multiple chains and iterations to create a relatively large posterior from which to draw simulated data.

Something like:

Sim_Mod <- brm(Sim_fmla,
               Sim_Data,
               family = binomial(),
               prior = Sim_priors,
               inits = "random",
               iter = 2000,
               warmup = 1000,
               chains = 4,
               cores = ncores,
               sample_prior = "only",               
               save_pars = save_pars(all = TRUE),
               control = list(adapt_delta = 0.99,
                              max_treedepth = 12)
)

Then generate simulated data with help from tidybayes:

Sim_Preds <- add_predicted_draws(
        Sim_Data,
        Sim_Mod,
        prediction = "Prediction",
        n = 500
)

Thanks for weighing in, unfortunately that solution doesn’t apply to my use case. I am testing how my model performs under various data-generating processes.

Can you confirm whether or not my suggested solution makes sense, and whether it’s okay to run the initial model with only 1 iteration?

Its fine to run the initial model for only one or two iterations, since you’re just creating the model to update and not making inferences. One thing to be careful of here is that the default priors will be set using data from the initial model creation and then they don’t get updated when the model is run with new data. So it’s good practice to pre-specify all priors in the model otherwise you get data leakage from the first dataset