# Possible to fit two models at once?

Hello all, I have a question on parallelization. I recently adapted Solomon Kurz’s amazing script for Bayesian power analysis in brms for logistic models (see here, but it’s been running very slowly on my aging computer (Ryzen 7 3700X). Even with just a single two-level predictor it’s taking between 35 and 60 minutes to run 1,500 simulations, depending on the sample size I set for the data.

Wondering if it’s possible to speed this up through parallelization? Like, for example, having it fit two models simultaneously…I have an 8 core CPU, so I can probably have two 4-chain models going at once, right? I would expect that to cut the computation time in half if it is possible.

You can fit two models in parallel and use parallelization to speed this up.

Maybe an even easier approach is to have 2 scripts, each doing half of the simulations, and execute each sript in its own R-session?

If your models are simple, you can also get away with using only 2 chains per model and 1000 iterations, which would further speed up things considerably.

2 Likes

Thank you, yes, that’s a much simper solution! I’ll also dumb the chains and steps/iterations down too.

I’ve never adjusted the sampling behavior of RStan before though, so I’d like to ask a clarification question, if I may…I’m a very novice Bayesian and I’m still learning the ropes. I usually leave the sampling stuff on the defaults.

In the tutorial paper for brms, I found the following:

The example model `fit1` is fitted using 4 chains, each with 2000 iterations of which the first 1000 are warmup to calibrate the sampler, leading to a total of 4000 posterior samples.

Am I correct then in assuming that the total number of samples is equal to (iter - warmup) * (n_chains)? For example using the above: (2000 - 1000) * 4 = 4000 posterior samples?

And then, by extension, would I also be correct in assuming that those 4000 samples are divided equally among each parameter estimated in the model? So if I had 2 parameters (e.g., one beta weight and the intercept), they would have an ESS in this instance of about 2000 each?

With 4 chains with 2000 iterations including 1000 warm up samples you will indeed get 4000 samples, but this will be 4000 samples per parameter.

1 Like