# NOT RUN {
set.seed(429153)
n_obs <- 100
W <- replicate(2, rbinom(n_obs, 1, 0.5))
A <- rnorm(n_obs, mean = 2 * W, sd = 1)
Y <- rbinom(n_obs, 1, plogis(A + W + rnorm(n_obs, mean = 0, sd = 1)))
C_samp <- rbinom(n_obs, 1, plogis(W + Y)) # two-phase sampling
C_cens <- rbinom(n_obs, 1, plogis(rowSums(W) + 0.5))
# construct a TML estimate, ignoring censoring
tmle <- txshift(
W = W, A = A, Y = Y, delta = 0.5,
estimator = "onestep",
g_exp_fit_args = list(
fit_type = "hal",
n_bins = 3,
lambda_seq = exp(seq(-1, -10, length = 50))
),
Q_fit_args = list(
fit_type = "glm",
glm_formula = "Y ~ ."
)
)
# }
# NOT RUN {
# construct a TML estimate, accounting for censoring
tmle <- txshift(
W = W, A = A, C_cens = C_cens, Y = Y, delta = 0.5,
estimator = "onestep",
g_exp_fit_args = list(
fit_type = "hal",
n_bins = 3,
lambda_seq = exp(seq(-1, -10, length = 50))
),
g_cens_fit_args = list(
fit_type = "glm",
glm_formula = "C_cens ~ ."
),
Q_fit_args = list(
fit_type = "glm",
glm_formula = "Y ~ ."
)
)
# construct a TML estimate under two-phase sampling, ignoring censoring
ipcwtmle <- txshift(
W = W, A = A, Y = Y, delta = 0.5,
C_samp = C_samp, V = c("W", "Y"),
estimator = "onestep", max_iter = 3,
samp_fit_args = list(fit_type = "glm"),
g_exp_fit_args = list(
fit_type = "hal",
n_bins = 3,
lambda_seq = exp(seq(-1, -10, length = 50))
),
Q_fit_args = list(
fit_type = "glm",
glm_formula = "Y ~ ."
),
eif_reg_type = "glm"
)
# construct a TML estimate acconting for two-phase sampling and censoring
ipcwtmle <- txshift(
W = W, A = A, C_cens = C_cens, Y = Y, delta = 0.5,
C_samp = C_samp, V = c("W", "Y"),
estimator = "onestep", max_iter = 3,
samp_fit_args = list(fit_type = "glm"),
g_exp_fit_args = list(
fit_type = "hal",
n_bins = 3,
lambda_seq = exp(seq(-1, -10, length = 50))
),
g_cens_fit_args = list(
fit_type = "glm",
glm_formula = "C_cens ~ ."
),
Q_fit_args = list(
fit_type = "glm",
glm_formula = "Y ~ ."
),
eif_reg_type = "glm"
)
# }
Run the code above in your browser using DataLab