bootstrap: Bootstrap Distribution for Estimators

View source: R/inference.R

bootstrapR Documentation

Bootstrap Distribution for Estimators

Description

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.

Usage

bootstrap(model, exper, fs = NULL, B = 1000, progress = TRUE)

Arguments

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.

Value

stats A list of length B containing the results of the fs applied on each of the B bootstrap resamples.

Examples

# 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")

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