Parallelize 'modelsummary' functions
Henrik Bengtsson
Source:vignettes/futurize-81-modelsummary.md
futurize-81-modelsummary.Rmd
+
=

The futurize package allows you to easily turn
sequential code into parallel code by piping the sequential code to the
futurize() function. Easy!
TL;DR
library(futurize)
plan(multisession)
library(modelsummary)
fit1 <- lm(mpg ~ cyl, data = mtcars)
fit2 <- lm(mpg ~ cyl + hp, data = mtcars)
models <- list(Model1 = fit1, Model2 = fit2)
modelsummary(models) |> futurize()Introduction
The modelsummary package creates customizable tables and plots to summarize statistical models side-by-side. For example,
library(futurize)
plan(multisession)
library(modelsummary)
## fit multiple linear models
fit1 <- lm(mpg ~ cyl, data = mtcars)
fit2 <- lm(mpg ~ cyl + hp, data = mtcars)
models <- list(Model1 = fit1, Model2 = fit2)
## generate modelsummary table in parallel
tbl <- modelsummary(models, output = "data.frame") |> futurize()
print(tbl)will parallelize model summary statistics extraction, given that we have set up parallel workers, e.g.
plan(multisession)The built-in multisession backend parallelizes on your
local computer and works on all operating systems. There are other parallel
backends to choose from, including alternatives to parallelize
locally as well as distributed across remote machines, e.g.
plan(future.mirai::mirai_multisession)and
plan(future.batchtools::batchtools_slurm)Supported Functions
The following modelsummary functions are supported
by futurize():
-
modelsummary()withseed = TRUEas the default -
msummary()withseed = TRUEas the default -
modelplot()withseed = TRUEas the default