parallelize: Parallelize Estimation across Responses

View source: R/estimators.R

parallelizeR Documentation

Parallelize Estimation across Responses

Description

For many mediation and outcome models, we simply want to apply a univariate model across all response variable. Parallelize enables this conversion. For example, applying parallelize to ranger() returns a function that estimates separate random forest models for each response on the left hand side of a formula.

Usage

parallelize(f, progress = TRUE)

Arguments

f

A function for estimating a single response model given a formula and input dataset. This is the model that we would like to parallelize across responses.

progress

A logical indicating whether to show a progress bar.

Value

f_multi A function that takes a formula and dataset and applies f to each response on the left hand side of the original formula.

Examples

mat <- data.frame(matrix(rnorm(100), 25, 4))
colnames(mat) <- c("y1", "y2", "x1", "x2")
plm <- parallelize(lm)
plm(y1 + y2 ~ x1 + x2, mat)

prf <- parallelize(ranger::ranger)
prf(mpg + hp ~ wt + disp + cyl, data = mtcars)

multimedia documentation built on Sept. 30, 2024, 9:28 a.m.