Apply a random forest model in parallel across a vector of responses $y$ in either an outcome or mediation model. This is a natural choice when the relationship between inputs and outputs is thought to be nonlinear. Internally, each of the models across the response are estimated using the 'ranger' package.
Value
model An object of class model
with estimator, predictor, and
sampler functions associated wtih a lienar model.
Examples
exper <- demo_joy() |>
mediation_data("PHQ", "treatment", starts_with("ASV"))
multimedia(exper, rf_model(num.trees = 10)) |>
estimate(exper)
#> [Multimedia Analysis]
#> Treatments: treatment
#> Outcomes: PHQ
#> Mediators: ASV1, ASV2, ...
#>
#> [Models]
#> mediation: A fitted lm_model().
#> outcome: A fitted rf_model().
# example with another dataset
exper <- demo_spline(tau = c(2, 1)) |>
mediation_data(starts_with("outcome"), "treatment", "mediator")
multimedia(exper, rf_model(num.trees = 20, max.depth = 2)) |>
estimate(exper)
#> [Multimedia Analysis]
#> Treatments: treatment
#> Outcomes: outcome_1, outcome_2
#> Mediators: mediator
#>
#> [Models]
#> mediation: A fitted lm_model().
#> outcome: A fitted rf_model().