For causal identification, mediation analysis relies on several untestable assumptions. One important one is that there is no confounding between the counterfactual mediator and outcome variables. Even though we can never know whether this exists, we can measure the sensitivity of our conclusions to the existence/strength of such a confounder. In this function, we approach this by inducing (unallowable) correlation between the mediator and outcome model residuals, simulate forward, and see how the estimated pathwise indirect effects change.
Usage
sensitivity_pathwise(
model,
exper,
confound_ix = NULL,
rho_seq = NULL,
n_bootstrap = 100,
progress = TRUE,
...
)
Arguments
- model
A
multimedia
object containing the fitted models for sensitivity analysis. Note that since our approach relies on correlating simulated residual error, it is only applicable to models of classlm_model()
,glmnet_model()
andrf_model()
.- exper
The original
mediation_data
class object used to fitmodel
. These observations will be resampled to support bootstrap confidence interval construction of the sensitivity curve.- confound_ix
A data.frame specifying which mediator/outcome should be allowed to be correlated. Should have two columns: 'mediator' and 'outcome' specifying which pairs of mediators and outcomes should be correlated. Defaults to NULL, which creates a data.frame with no rows (and so enforcing independence between mediators and outcomes)
- rho_seq
We will evaluate correlations Cor(e', e) between mediation and outcome model errors ranging along this grid. Defaults to NULL, which internally sets the sequence to rho = (-0.9, -0.7 ..., 0.7, 0.9).
- n_bootstrap
The number of bootstrap resamples used to build confidence bands around the sensitivity curves. Defaults to 100.
- progress
A logical indicating whether to show a progress bar.
- ...
Additional arguments passed to indirect_pathwise.
Value
A date.frame
giving the outputs of indirect_overall
across many
values of the correlation rho.
Examples
xy_data <- demo_spline()
exper <- mediation_data(
xy_data, starts_with("outcome"), "treatment", "mediator"
)
model <- multimedia(
exper,
outcome_estimator = glmnet_model(lambda = 1e-2)
) |>
estimate(exper)
rho_seq <- c(-0.2, 0, 0.2)
subset_indices <- expand.grid(
mediator = n_mediators(model), outcome = n_outcomes(model)
)
sensitivity_pathwise(model, exper, subset_indices, rho_seq, n_bootstrap = 2)
#> Indirect effects for direct setting 1
#> Indirect effects for direct setting 2
#> Indirect effects for direct setting 1
#> Indirect effects for direct setting 2
#> Indirect effects for direct setting 1
#> Indirect effects for direct setting 2
#> Indirect effects for direct setting 1
#> Indirect effects for direct setting 2
#> Indirect effects for direct setting 1
#> Indirect effects for direct setting 2
#> Indirect effects for direct setting 1
#> Indirect effects for direct setting 2
#> # A tibble: 12 × 7
#> # Groups: outcome, direct_setting, contrast, mediator [4]
#> rho outcome direct_setting contrast mediator indirect_effect
#> <dbl> <chr> <fct> <chr> <chr> <dbl>
#> 1 -0.2 outcome_1 0 0 - 1 mediator 0.0202
#> 2 0 outcome_1 0 0 - 1 mediator 0.0282
#> 3 0.2 outcome_1 0 0 - 1 mediator 0.0185
#> 4 -0.2 outcome_1 1 0 - 1 mediator 0.0202
#> 5 0 outcome_1 1 0 - 1 mediator 0.0282
#> 6 0.2 outcome_1 1 0 - 1 mediator 0.0185
#> 7 -0.2 outcome_2 0 0 - 1 mediator -0.376
#> 8 0 outcome_2 0 0 - 1 mediator -0.405
#> 9 0.2 outcome_2 0 0 - 1 mediator -0.389
#> 10 -0.2 outcome_2 1 0 - 1 mediator -0.376
#> 11 0 outcome_2 1 0 - 1 mediator -0.405
#> 12 0.2 outcome_2 1 0 - 1 mediator -0.389
#> # ℹ 1 more variable: indirect_effect_standard_error <dbl>