Hello, I have tried to use the tmle_NDE and tmle_NIE functions to get the direct/indirect effects besides the total effect I only get with tmle_medshift. Below the code I am using with your example_data.
# produces a simple data set based on ca causal model with mediation
make_mediation_data <- function(n_obs = 1000) {
# baseline covariate -- simple, binary
W <- rbinom(n_obs, 1, prob = 0.50)
# create treatment based on baseline W
A <- as.numeric(rbinom(n_obs, 1, prob = W / 4 + 0.1))
# single mediator to affect the outcome
z1_prob <- 1 - plogis((A^2 + W) / (A + W^3 + 0.5))
Z <- rbinom(n_obs, 1, prob = z1_prob)
# create outcome as a linear function of A, W + white noise
Y <- Z + A - 0.1 * W + rnorm(n_obs, mean = 0, sd = 0.25)
# full data structure
data <- as.data.table(cbind(Y, Z, A, W))
setnames(data, c("Y", "Z", "A", "W"))
return(data)
}
# set seed and simulate example data
set.seed(75681)
example_data <- make_mediation_data(100)
node_list <- list(W = "W", A = "A", Z = "Z", Y = "Y")
# consider an incremental propensity score intervention that triples (i.e.,
# delta = 3) the individual-specific odds of receiving treatment
delta_ipsi <- 3
# Added learners
learners <- list(
Lrnr_glm$new(),
Lrnr_bayesglm$new(),
Lrnr_ranger$new()
)
dense_learners <- Lrnr_sl$new(
learners = learners,
metalearner = Lrnr_nnls$new()
)
cv_learner <- Lrnr_cv$new(dense_learners, full_fit = TRUE)
learner_list <- list(
Y = cv_learner,
A = cv_learner,
Z = cv_learner,
W = cv_learner
)
# Code that works:
tmle_spec <- tmle_medshift(
delta = delta_ipsi,
e_learners = cv_learner,
phi_learners = cv_learner,
max_iter = 5
)
# total effect works:
total_out <- tmle3(
tmle_spec = tmle_spec,
data = example_data,
node_list = node_list,
learner_list = learner_list
)
# Natural direct effect
tmle_spec_NDE <- tmle_NDE(
e_learners = cv_learner,
psi_Z_learners = cv_learner,
max_iter = 5
)
# Returns error `Error: Couldn't find W`
NDE_out <- tmle3(
tmle_spec = tmle_spec_NDE,
data = example_data,
node_list = node_list,
learner_list = learner_list
)
# Same error with Natural indirect effect
tmle_spec_NIE <- tmle_NIE(e_learners = e_learners, psi_Z_learners = phi_learners, max_iter = 5)
NIE_out <- tmle3(
tmle_spec = tmle_spec_NDE,
data = example_data,
node_list = node_list,
learner_list = learner_list
)
The error message is also very uninformative, I have no idea if this has to do with a mismatch with the node_list and the example_data or because the learner_list doesn't contain an list element W.
Thank you for your time.
Hello, I have tried to use the
tmle_NDEandtmle_NIEfunctions to get the direct/indirect effects besides the total effect I only get withtmle_medshift. Below the code I am using with yourexample_data.The error message is also very uninformative, I have no idea if this has to do with a mismatch with the
node_listand theexample_dataor because thelearner_listdoesn't contain an list elementW.Thank you for your time.