sample,multimedia-method | R Documentation |
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.
## S4 method for signature 'multimedia'
sample(x, size, pretreatment = NULL, profile = NULL, mediators = NULL, ...)
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 |
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 |
profile |
An object of class |
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
|
... |
Additional options to pass to the @sampler method in the estimated mediation model. |
An object of class multimedia
with mediator and outcome slots
sampled according to the description above.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.