rr-marginaleffects

R marginaleffects package set number of cores


This seems like a rather easy question, so sorry if I have overlooked an obvious answer.

When using avg_slopes() from the marginaleffects package I noticed that calculations seem to be done in parallel on all available cores. So far I have not found any possibility to change the number of cores used. Has anyone any solution of how to do this?


Solution

  • For anyone who happens to stumble across this question. The question was based on using a glmmTMB model as input for avg_slopes() and the observed behaviour is caused by the predict() function of glmmTMB.

    predict() of glmmTMB will infer the number of threads for prediction from the glmmTMB model, i.e. if for model fitting 24 threads were used, 24 will be used for prediction as well.

    This can be changed by updating the model via update(), see also here: https://github.com/glmmTMB/glmmTMB/issues/713.