Convert a SummarizedExperiment, phyloseq object, or data.frame into a
mediation_data
object. This conversion helps to organize the variables that
lie on different parts of the mediation analysis graph, so that they are not
all kept in a homogeneous experiment or data.frame. It's possible to specify
outcome, mediator, or treatment variables using either string vectors or
tidyselect syntax, e.g., starts_with("mediator_")
will match all columns of
the input data starting with the string mediator.
Arguments
- x
A SummarizedExperiment, phyloseq object, or data.frame whose columns contain all the variables needed for the mediation analysis.
- outcomes
A vector or tidyselect specification of the names of all outcome variables.
- treatments
A vector or tidyselect specification of the names of all treatment variables.
- mediators
A vector or tidyselect specification of the names of all mediators.
- pretreatments
A vector containing names of all pretreatment variables. Defaults to NULL, in which case the pretreatments slot will remain empty.
Value
result An object of class mediation_data
, with separate slots for
each of the node types in a mediation analysis diagram.
Examples
# multiple outcomes, one mediator
mediation_data(
demo_spline(), starts_with("outcome"), "treatment", "mediator"
)
#> [Mediation Data]
#> 5000 samples with measurements for,
#> 1 treatment: treatment
#> 1 mediator: mediator
#> 2 outcomes: outcome_1, outcome_2
# one outcome, multiple mediators
mediation_data(demo_joy(), "PHQ", "treatment", starts_with("ASV"))
#> [Mediation Data]
#> 100 samples with measurements for,
#> 1 treatment: treatment
#> 5 mediators: ASV1, ASV2, ...
#> 1 outcome: PHQ