Skip to contents

Given a fitted multimedia model, contrast sampled mediation and outcome data associated with two treatment profiles.

Usage

contrast_samples(model, profile1, profile2, ...)

Arguments

model

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

profile1

An object of class treatment_profile containing the first treatment profile to consider in the difference.

profile2

An object of class treatment_profile containing the second treatment profile to consider in the difference.

...

Additional arguments to pass to sample().

Value

A list with two elements, mediators and outcomes, containing the differences in the sampled M(T') - M(T) and Y(T', M(T')) - Y(T, M(T)) between the two profiles T and T'.

A list with two elements, mediators and outcomes. These contrast the values of the mediator and outcomes under the two profiles T and T'.

Examples

exper <- demo_joy() |>
    mediation_data("PHQ", "treatment", starts_with("ASV"))
model <- multimedia(exper) |>
    estimate(exper)
t1 <- data.frame(treatment = factor("Treatment"))
t2 <- data.frame(treatment = factor("Control"))
profile1 <- setup_profile(model, t1, t1)
profile2 <- setup_profile(model, t2, t2)
contrast_samples(model, profile1, profile2)
#> $mediators
#>         ASV1       ASV2      ASV3     ASV4      ASV5
#> 1 -0.4153275 0.03269037 -1.002049 0.303136 0.6113224
#> 
#> $outcomes
#>        PHQ
#> 1 2.392375
#> 

samples <- purrr::map(
    seq_len(100),
    ~ contrast_samples(model, profile1, profile2)
)
hist(sapply(samples, \(x) x[[1]]$ASV1))

hist(sapply(samples, \(x) x[[1]]$ASV2))