sample-multimedia-method: Sample New Mediator/Outcome Data

sample,multimedia-methodR Documentation

Sample New Mediator/Outcome Data

Description

This generalizes the built-in sample method to the multimedia class. Given an estimated multimedia object, this function supports sampling along the estimated DAG. It first samples ⁠M* | T, X⁠ and then ⁠Y* | M*, T, X⁠. Each sampling step will call the sample method within the mediation and outcome models that make up the multimedia object on which this is called.

Usage

## S4 method for signature 'multimedia'
sample(x, size, pretreatment = NULL, profile = NULL, mediators = NULL, ...)

Arguments

x

An object of class multimedia containing the estimated mediation and outcome models whose mediation and outcome samples we want to obtain.

size

A placeholder argument to agree with the default sample method in R base. We always return the number of samples as set in either the original input x or a new input profile.

pretreatment

By default, we will return mediation and outcome model predictions using the same pretreatment variables as used when initially estimating the models (like setting newdata = NULL in usual predict). To pass in different pretreatment variables, provide a data.frame here whose columns match the pretreatments as the originally trained mediation and outcome models.

profile

An object of class treatment_profile containing the treatment profile to consider in the difference. Defaults to a profile with all the unique treatment configurations observed in the original data, shared across both the mediators and outcomes.

mediators

By default, we will return outcome predictions using the predicted mediators from the mediation model. Modify this argument if you would like to directly control the mediation inputs for the outcome model. Must be a data.frame whose columns are named to match the mediators(object).

...

Additional options to pass to the @sampler method in the estimated mediation model.

Value

An object of class multimedia with mediator and outcome slots sampled according to the description above.

Examples

exper <- demo_spline(tau = c(2, 1)) |>
    mediation_data(starts_with("outcome"), "treatment", "mediator")
fit <- multimedia(exper) |>
    estimate(exper)
samples <- sample(fit)
mediators(samples)
outcomes(samples)

# sampling with just different "n" has no effect.
samples <- sample(fit, 100)

# Instead sample at a new treatment configuration
t1 <- data.frame(treatment = factor(rep(c(0, 1), each = 50)))
profile <- setup_profile(fit, t_mediator = t1, t_outcome = t1)
samples <- sample(fit, profile = profile)
mediators(samples)
outcomes(samples)

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