Skip to contents

For general mediation analysis, we need to provide counterfactuals for both the outcome and mediator components of each sample. That is, we need to understand Y(t, M(t')) where t and t' may not be the same. treatment_profile classes place some more structural requirements on treatment profiles, so that later effect estimation can make simplifying assumptions. This function creates a treatment profile from a collection of possible mediator and outcome treatments.

Usage

setup_profile(x, t_mediator = NULL, t_outcome = NULL)

Arguments

x

An object of class multimedia specifying the complete mediation analysis DAG. The treatment, mediator, and outcome names are necessary to build a profile of counterfactual treatments across each of these variables.

t_mediator

A data.frame whose columns store treatment names and whose values are the treatment assignments to each sample (row). Defaults to NULL, in which case this type of data.frame is constructed from the treatment assignments in the mediation_data's @treatment slot. Each column must be either a numeric or factor variable.

t_outcome

A data.frame analogous to t_mediator, but applying to the outcome node.

Value

An object of class treatment_profile giving treatment assignments for both mediation and outcome terms.

See also

check_profile

Examples

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

t1 <- data.frame(treatment = factor(rep(c(0, 1), each = 5)))
profile <- setup_profile(fit, t_mediator = t1, t_outcome = t1)
profile
#> An object of class "treatment_profile"
#> Slot "t_mediator":
#> $mediator
#>    treatment
#> 1          0
#> 2          0
#> 3          0
#> 4          0
#> 5          0
#> 6          1
#> 7          1
#> 8          1
#> 9          1
#> 10         1
#> 
#> 
#> Slot "t_outcome":
#> $outcome_1
#>    treatment
#> 1          0
#> 2          0
#> 3          0
#> 4          0
#> 5          0
#> 6          1
#> 7          1
#> 8          1
#> 9          1
#> 10         1
#> 
#> $outcome_2
#>    treatment
#> 1          0
#> 2          0
#> 3          0
#> 4          0
#> 5          0
#> 6          1
#> 7          1
#> 8          1
#> 9          1
#> 10         1
#> 
#> 

t2 <- data.frame(treatment = factor(rep(0, 10)))
profile <- setup_profile(fit, t_mediator = t1, t_outcome = t2)
profile
#> An object of class "treatment_profile"
#> Slot "t_mediator":
#> $mediator
#>    treatment
#> 1          0
#> 2          0
#> 3          0
#> 4          0
#> 5          0
#> 6          1
#> 7          1
#> 8          1
#> 9          1
#> 10         1
#> 
#> 
#> Slot "t_outcome":
#> $outcome_1
#>    treatment
#> 1          0
#> 2          0
#> 3          0
#> 4          0
#> 5          0
#> 6          0
#> 7          0
#> 8          0
#> 9          0
#> 10         0
#> 
#> $outcome_2
#>    treatment
#> 1          0
#> 2          0
#> 3          0
#> 4          0
#> 5          0
#> 6          0
#> 7          0
#> 8          0
#> 9          0
#> 10         0
#> 
#>