bootstrap | R Documentation |
Given a mediation model specification, estimators fs, and original dataset exper, this will re-estimate the mediation model on resampled versions of exper and apply each estimator in fs to construct bootstrap distributions associated wtih those estimators.
bootstrap(model, exper, fs = NULL, B = 1000, progress = TRUE)
model |
An object of class multimedia with specified mediation and outcome models that we want to re-estimate across B bootstrap samples. |
exper |
An object of class multimedia_data containing the mediation and outcome data from which the direct effects are to be estimated. |
fs |
The estimators whose bootstrap samples we are interested in. These are assumed to be a vector of functions (for example, direct_effect or indirect_effect), and they will each be applied to each bootstrap resample. |
B |
The number of bootstrap samples. Defaults to 1000. |
progress |
A logical indicating whether to show a progress bar. |
stats A list of length B containing the results of the fs applied on each of the B bootstrap resamples.
# example with null data. We set B to 5 just to execute quickly -- it's not
# actually a practical choice of B
exper <- demo_joy() |>
mediation_data("PHQ", "treatment", starts_with("ASV"))
multimedia(exper) |>
bootstrap(exper, B = 5)
# example with another dataset
exper <- demo_spline(n_samples = 100, tau = c(2, 1)) |>
mediation_data(starts_with("outcome"), "treatment", "mediator")
samples <- multimedia(exper, rf_model(num.trees = 1e3)) |>
bootstrap(exper, B = 5)
ggplot2::ggplot(samples$direct_effect) +
ggplot2::geom_histogram(
ggplot2::aes(direct_effect, fill = indirect_setting),
bins = 15
) +
ggplot2::facet_wrap(~outcome, scales = "free")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.