medoutcon | R Documentation |
Efficient estimation of natural and interventional (in)direct effects
medoutcon(
W,
A,
Z,
M,
Y,
R = rep(1, length(Y)),
obs_weights = rep(1, length(Y)),
svy_weights = NULL,
two_phase_weights = rep(1, length(Y)),
effect = c("direct", "indirect", "pm"),
contrast = NULL,
g_learners = sl3::Lrnr_glm_fast$new(),
h_learners = sl3::Lrnr_glm_fast$new(),
b_learners = sl3::Lrnr_glm_fast$new(),
q_learners = sl3::Lrnr_glm_fast$new(),
r_learners = sl3::Lrnr_glm_fast$new(),
u_learners = sl3::Lrnr_hal9001$new(),
v_learners = sl3::Lrnr_hal9001$new(),
d_learners = sl3::Lrnr_glm_fast$new(),
estimator = c("tmle", "onestep"),
estimator_args = list(cv_folds = 10L, cv_strat = FALSE, strat_pmin = 0.1, max_iter =
10L, tiltmod_tol = 5),
g_bounds = c(0.005, 0.995)
)
W |
A |
A |
A |
Z |
A |
M |
A |
Y |
A |
R |
A |
obs_weights |
A |
svy_weights |
A |
two_phase_weights |
A |
effect |
A |
contrast |
A |
g_learners |
A |
h_learners |
A |
b_learners |
A |
q_learners |
A |
r_learners |
A |
u_learners |
A |
v_learners |
A |
d_learners |
A |
estimator |
The desired estimator of the direct or indirect effect (or contrast-specific parameter) to be computed. Both an efficient one-step estimator using cross-fitting and a cross-validated targeted minimum loss estimator (TMLE) are available. The default is the TML estimator. |
estimator_args |
A |
g_bounds |
A |
# here, we show one-step and TML estimates of the interventional direct
# effect; the indirect effect can be evaluated by a straightforward change
# to the penultimate argument. the natural direct and indirect effects can
# be evaluated by omitting the argument Z (inappropriate in this example).
# create data: covariates W, exposure A, post-exposure-confounder Z,
# mediator M, outcome Y
n_obs <- 200
w_1 <- rbinom(n_obs, 1, prob = 0.6)
w_2 <- rbinom(n_obs, 1, prob = 0.3)
w <- as.data.frame(cbind(w_1, w_2))
a <- as.numeric(rbinom(n_obs, 1, plogis(rowSums(w) - 2)))
z <- rbinom(n_obs, 1, plogis(rowMeans(-log(2) + w - a) + 0.2))
m_1 <- rbinom(n_obs, 1, plogis(rowSums(log(3) * w + a - z)))
m_2 <- rbinom(n_obs, 1, plogis(rowSums(w - a - z)))
m <- as.data.frame(cbind(m_1, m_2))
y <- rbinom(n_obs, 1, plogis(1 / (rowSums(w) - z + a + rowSums(m))))
# one-step estimate of the interventional direct effect
os_de <- medoutcon(
W = w, A = a, Z = z, M = m, Y = y,
effect = "direct",
estimator = "onestep"
)
# TML estimate of the interventional direct effect
# NOTE: improved variance estimate and de-biasing from targeting procedure
tmle_de <- medoutcon(
W = w, A = a, Z = z, M = m, Y = y,
effect = "direct",
estimator = "tmle"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.