Title: | Efficient Estimation of the Causal Effects of Stochastic Interventions |
---|---|
Description: | Efficient estimation of the population-level causal effects of stochastic interventions on a continuous-valued exposure. Both one-step and targeted minimum loss estimators are implemented for the counterfactual mean value of an outcome of interest under an additive modified treatment policy, a stochastic intervention that may depend on the natural value of the exposure. To accommodate settings with outcome-dependent two-phase sampling, procedures incorporating inverse probability of censoring weighting are provided to facilitate the construction of inefficient and efficient one-step and targeted minimum loss estimators. The causal parameter and its estimation were first described by Díaz and van der Laan (2013) <doi:10.1111/j.1541-0420.2011.01685.x>, while the multiply robust estimation procedure and its application to data from two-phase sampling designs is detailed in NS Hejazi, MJ van der Laan, HE Janes, PB Gilbert, and DC Benkeser (2020) <doi:10.1111/biom.13375>. The software package implementation is described in NS Hejazi and DC Benkeser (2020) <doi:10.21105/joss.02447>. Estimation of nuisance parameters may be enhanced through the Super Learner ensemble model in 'sl3', available for download from GitHub using 'remotes::install_github("tlverse/sl3")'. |
Authors: | Nima Hejazi [aut, cre, cph] , David Benkeser [aut] , Iván Díaz [ctb] , Jeremy Coyle [ctb] , Mark van der Laan [ctb, ths] |
Maintainer: | Nima Hejazi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.9 |
Built: | 2024-11-20 05:36:41 UTC |
Source: | https://github.com/nhejazi/txshift |
Bound Precision
bound_precision(vals)
bound_precision(vals)
vals |
|
Bound values in the unit interval to machine precision in order to avoid numerical instability issues in downstream computation.
A numeric
vector of the same length as vals
, where
the returned values are bounded to machine precision. This is intended to
avoid numerical instability issues.
Bound Generalized Propensity Score
bound_propensity(vals, bound = 0.01)
bound_propensity(vals, bound = 0.01)
vals |
|
bound |
|
Bound estimated values of the generalized propensity score (a conditional density) to avoid numerical instability issues arising from practical violations of the assumption of positivity.
A numeric
vector of the same length as vals
, where the
returned values are bounded such that the minimum is no lower than 1/n, for
the sample size n.
Confidence Intervals for Counterfactual Mean Under Stochastic Intervention
## S3 method for class 'txshift' confint(object, parm = seq_len(object$psi), level = 0.95, ..., ci_mult = NULL)
## S3 method for class 'txshift' confint(object, parm = seq_len(object$psi), level = 0.95, ..., ci_mult = NULL)
object |
An object of class |
parm |
A |
level |
A |
... |
Other arguments. Not currently used. |
ci_mult |
Pre-computed multipliers for generating confidence intervals.
The default of |
Compute confidence intervals for estimates produced by
txshift
.
A named numeric
vector containing the parameter estimate from
a txshift
object, alongside lower and upper Wald-style confidence
intervals at a specified coverage level.
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))) txout <- txshift( W = W, A = A, Y = Y, delta = 0.5, estimator = "tmle", g_exp_fit_args = list( fit_type = "hal", n_bins = 5, grid_type = "equal_mass", lambda_seq = exp(-1:-9) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ) ) confint(txout)
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))) txout <- txshift( W = W, A = A, Y = Y, delta = 0.5, estimator = "tmle", g_exp_fit_args = list( fit_type = "hal", n_bins = 5, grid_type = "equal_mass", lambda_seq = exp(-1:-9) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ) ) confint(txout)
Compute the Shift Parameter Estimate and the Efficient Influence Function
eif( Y, Qn, Hn, estimator = c("tmle", "onestep"), fluc_mod_out = NULL, C_samp = rep(1, length(Y)), ipc_weights = rep(1, length(Y)) )
eif( Y, Qn, Hn, estimator = c("tmle", "onestep"), fluc_mod_out = NULL, C_samp = rep(1, length(Y)), ipc_weights = rep(1, length(Y)) )
Y |
A |
Qn |
An object providing the value of the outcome evaluated after
imposing a shift in the treatment. This object is passed in after being
constructed by a call to the internal function |
Hn |
An object providing values of the auxiliary ("clever") covariate,
constructed from the treatment mechanism and required for targeted minimum
loss-based estimation. This object object should be passed in after being
constructed by a call to the internal function |
estimator |
The type of estimator to be fit, either |
fluc_mod_out |
An object giving values of the logistic tilting model
for targeted minimum loss estimation. This type of object should be the
output of the internal routines to perform this step of the TML estimation
procedure, as given by |
C_samp |
Indicator for missingness due to exclusion from second-phase sample. Used for compatibility with the IPCW-TML estimation routine. |
ipc_weights |
A |
Estimate the value of the causal parameter alongside statistical inference for the parameter estimate based on the efficient influence function of the target parameter, which takes the following form:
A list
containing the parameter estimate, estimated variance
based on the efficient influence function (EIF), the estimate of the EIF
incorporating inverse probability of censoring weights, and the estimate of
the EIF without the application of such weights.
Estimate the Censoring Mechanism
est_g_cens( C_cens, A, W, samp_weights = rep(1, length(C_cens)), fit_type = c("sl", "glm"), glm_formula = "C_cens ~ .", sl_learners = NULL, bound = 0.02 )
est_g_cens( C_cens, A, W, samp_weights = rep(1, length(C_cens)), fit_type = c("sl", "glm"), glm_formula = "C_cens ~ .", sl_learners = NULL, bound = 0.02 )
C_cens |
A |
A |
A |
W |
A |
samp_weights |
A |
fit_type |
A |
glm_formula |
A |
sl_learners |
Object containing a set of instantiated learners from the sl3, to be used in fitting an ensemble model. |
bound |
|
Compute the censoring mechanism for the observed data, in order to apply a joint intervention for removing censoring by re-weighting.
A numeric
vector of the propensity score for censoring.
Estimate the Exposure Mechanism via Generalized Propensity Score
est_g_exp( A, W, delta = 0, samp_weights = rep(1, length(A)), fit_type = c("hal", "sl"), sl_learners_density = NULL, haldensify_args = list(grid_type = "equal_range", lambda_seq = exp(seq(-1, -13, length = 300))) )
est_g_exp( A, W, delta = 0, samp_weights = rep(1, length(A)), fit_type = c("hal", "sl"), sl_learners_density = NULL, haldensify_args = list(grid_type = "equal_range", lambda_seq = exp(seq(-1, -13, length = 300))) )
A |
A |
W |
A |
delta |
A |
samp_weights |
A |
fit_type |
A |
sl_learners_density |
Object containing a set of instantiated learners from sl3, to be used in fitting an ensemble model. |
haldensify_args |
A |
Compute the propensity score (exposure mechanism) for the observed data, including the shift. This gives the propensity score for the observed data (at the observed A) the counterfactual shifted exposure levels at (A - delta), (A + delta), and (A + 2 * delta).
A data.table
with four columns, containing estimates of the
generalized propensity score at a downshift (g(A - delta | W)), no shift
(g(A | W)), an upshift (g(A + delta) | W), and an upshift of magnitude two
(g(A + 2 delta) | W).
Estimate Auxiliary Covariate of Full Data Efficient Influence Function
est_Hn(gn_exp, gps_bound)
est_Hn(gn_exp, gps_bound)
gn_exp |
An estimate of the exposure density (a generalized propensity
score) using the output provided by |
gps_bound |
|
Compute an estimate of the auxiliary covariate of the efficient influence function required to update initial estimates through logistic tilting models for targeted minimum loss estimation.
A data.table
with two columns, containing estimates of the
auxiliary covariate at the natural value of the exposure H(A, W) and at the
shifted value of the exposure H(A + delta, W).
Estimate the Outcome Mechanism
est_Q( Y, C_cens = rep(1, length(Y)), A, W, delta = 0, samp_weights = rep(1, length(Y)), fit_type = c("sl", "glm"), glm_formula = "Y ~ .", sl_learners = NULL )
est_Q( Y, C_cens = rep(1, length(Y)), A, W, delta = 0, samp_weights = rep(1, length(Y)), fit_type = c("sl", "glm"), glm_formula = "Y ~ .", sl_learners = NULL )
Y |
A |
C_cens |
A |
A |
A |
W |
A |
delta |
A |
samp_weights |
A |
fit_type |
A |
glm_formula |
A |
sl_learners |
Object containing a set of instantiated learners from the sl3, to be used in fitting an ensemble model. |
Compute the outcome regression for the observed data, including with the shift imposed by the intervention. This returns the outcome regression for the observed data (at A) and under the counterfactual shift shift (at A + delta).
A data.table
with two columns, containing estimates of the
outcome mechanism at the natural value of the exposure Q(A, W) and an
upshift of the exposure Q(A + delta, W).
Estimate Probability of Censoring by Two-Phase Sampling
est_samp(V, C_samp, fit_type = c("sl", "glm"), sl_learners = NULL)
est_samp(V, C_samp, fit_type = c("sl", "glm"), sl_learners = NULL)
V |
A |
C_samp |
A |
fit_type |
A |
sl_learners |
An sl3 |
Compute estimates of the sampling probability for inclusion in the the second-phase via the two-phase sampling mechanism. These estimates are used for the creation of inverse probability weights.
A numeric
vector of the estimated sampling mechanism.
Fit One-Dimensional Fluctuation Model for Updating Initial Estimates
fit_fluctuation( Y, Qn_scaled, Hn, ipc_weights = rep(1, length(Y)), method = c("standard", "weighted"), flucmod_tol = 50 )
fit_fluctuation( Y, Qn_scaled, Hn, ipc_weights = rep(1, length(Y)), method = c("standard", "weighted"), flucmod_tol = 50 )
Y |
A |
Qn_scaled |
An object providing the value of the outcome evaluate
after inducing a shift in the exposure. This object should be passed in
after being constructed by a call to |
Hn |
An object providing values of the auxiliary ("clever") covariate,
constructed from the treatment mechanism and required for targeted minimum
loss estimation. This object object should be passed in after being
constructed by a call to |
ipc_weights |
A |
method |
A |
flucmod_tol |
A |
Procedure for fitting a one-dimensional fluctuation model to update the initial estimates of the outcome regression based on the auxiliary covariate. These updated estimates are subsequently used to construct the TML estimator of the counterfactual mean under a modified treatment policy.
A list
containing the fluctuation model (a glm
object)
produced by logistic regression, a character
vector indicating the
type of fluctuation (whether the auxiliary covariates was used as a weight
or included directly in the model formula), the updated estimates of the
outcome regression under the shifted value of the exposure, and the updated
estimates of the outcome regression under the natural value of exposure.
Iterative IPCW Update Procedure of Augmented Efficient Influence Function
ipcw_eif_update( data_internal, C_samp, V, ipc_mech, ipc_weights, Qn_estim, Hn_estim, estimator = c("tmle", "onestep"), fluctuation = NULL, flucmod_tol = 50, eif_reg_type = c("hal", "glm") )
ipcw_eif_update( data_internal, C_samp, V, ipc_mech, ipc_weights, Qn_estim, Hn_estim, estimator = c("tmle", "onestep"), fluctuation = NULL, flucmod_tol = 50, eif_reg_type = c("hal", "glm") )
data_internal |
A |
C_samp |
A |
V |
A |
ipc_mech |
A |
ipc_weights |
A |
Qn_estim |
A |
Hn_estim |
A |
estimator |
The type of estimator to be fit, either |
fluctuation |
A |
flucmod_tol |
A |
eif_reg_type |
Whether a flexible nonparametric function ought to be
used in the dimension-reduced nuisance regression of the targeting step for
the censored data case. By default, the method used is a nonparametric
regression based on the Highly Adaptive Lasso (from hal9001). Set
this to |
An adaptation of the IPCW-TMLE for iteratively constructing an efficient inverse probability of censoring weighted TML or one-step estimator. The efficient influence function of the parameter and updating the IPC weights in an iterative process, until a convergence criteria is satisfied.
A list
containing the estimated outcome mechanism, the fitted
fluctuation model for TML updates, the updated inverse probability of
censoring weights (IPCW), the updated estimate of the efficient influence
function, and the estimated IPCW component of the EIF.
Working marginal structural model for causal effects of an intervention grid
msm_vimshift( W, A, C_cens = rep(1, length(Y)), Y, C_samp = rep(1, length(Y)), V = NULL, delta_grid = seq(-0.5, 0.5, 0.5), msm_form = list(type = "linear", knot = NA), estimator = c("tmle", "onestep"), weighting = c("identity", "variance"), ci_level = 0.95, ci_type = c("marginal", "simultaneous"), ... )
msm_vimshift( W, A, C_cens = rep(1, length(Y)), Y, C_samp = rep(1, length(Y)), V = NULL, delta_grid = seq(-0.5, 0.5, 0.5), msm_form = list(type = "linear", knot = NA), estimator = c("tmle", "onestep"), weighting = c("identity", "variance"), ci_level = 0.95, ci_type = c("marginal", "simultaneous"), ... )
W |
A |
A |
A |
C_cens |
A |
Y |
A |
C_samp |
A |
V |
The covariates that are used in determining the sampling procedure
that gives rise to censoring. The default is |
delta_grid |
A |
msm_form |
A |
estimator |
The type of estimator to be fit, either |
weighting |
Whether to weight each parameter estimate by the inverse of
its variance (in order to improve stability of the resultant MSM fit) or to
simply weight all parameter estimates equally. The default is the option
|
ci_level |
A |
ci_type |
Whether to construct a simultaneous confidence band covering all parameter estimates at once or marginal confidence intervals covering each parameter estimate separately. The default is to construct marginal confidence intervals for each parameter estimate rather than a simultaneous confidence band. |
... |
Additional arguments to be passed to |
Computes estimates of the counterfactual mean over a grid of shift stochastic interventions and fits a working marginal structural model to summarize the trend through the counterfactual means as a function of the specified shift intervention. The working marginal structural model may be linear in the shift parameter or piecewise linear with a single knot point. Provides support for two weighting schemes, may be used with either of the one-step or TML estimators, and also allows the construction of marginal or simultaneous confidence intervals.
A list
containing estimates of the individual counterfactual
means over a grid in the shift parameters (delta_grid
), alongside
the estimate of a marginal structural model that summarizes a trend through
these counterfactual means.
if (require("sl3")) { n_obs <- 100 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(2 * A - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25) ) # fit a linear spline with knot at 0 n_obs <- 100 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(0.1 * A * (A >= 0) - 3 * A * (A < 0) - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25), msm_form = list(type = "piecewise", knot = 0) ) }
if (require("sl3")) { n_obs <- 100 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(2 * A - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25) ) # fit a linear spline with knot at 0 n_obs <- 100 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(0.1 * A * (A >= 0) - 3 * A * (A < 0) - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25), msm_form = list(type = "piecewise", knot = 0) ) }
One-Step Estimate of Counterfactual Mean of Stochastic Shift Intervention
onestep_txshift( data_internal, C_samp = rep(1, nrow(data_internal)), V = NULL, delta, samp_estim, gn_cens_weights, Qn_estim, Hn_estim, eif_reg_type = c("hal", "glm"), samp_fit_args, ipcw_efficiency = TRUE )
onestep_txshift( data_internal, C_samp = rep(1, nrow(data_internal)), V = NULL, delta, samp_estim, gn_cens_weights, Qn_estim, Hn_estim, eif_reg_type = c("hal", "glm"), samp_fit_args, ipcw_efficiency = TRUE )
data_internal |
A |
C_samp |
A |
V |
The covariates that are used in determining the sampling procedure
that gives rise to censoring. The default is |
delta |
A |
samp_estim |
An object providing the value of the censoring mechanism
evaluated across the full data. This object is passed in after being
constructed by a call to the internal function |
gn_cens_weights |
An object providing the value of inverse probability of censoring weights, the inverse of the censoring mechanism estimate. The weights are used as part of the IPCW-EIF procedure to implement a joint intervention that removes the contribution of the censoring process. |
Qn_estim |
An object providing the value of the outcome evaluated after
imposing a shift in the treatment. This object is passed in after being
constructed by a call to the internal function |
Hn_estim |
An object providing values of the auxiliary ("clever")
covariate, constructed from the treatment mechanism and required for
targeted minimum loss estimation. This object object should be passed in
after being constructed by a call to the internal function |
eif_reg_type |
Whether a flexible nonparametric function ought to be
used in the dimension-reduced nuisance regression of the targeting step for
the censored data case. By default, the method used is a nonparametric
regression based on the Highly Adaptive Lasso (from hal9001). Set
this to |
samp_fit_args |
A |
ipcw_efficiency |
Whether to invoke an augmentation of the IPCW-TMLE
procedure that performs an iterative process to ensure efficiency of the
resulting estimate. The default is |
Invokes the procedure to construct a one-step estimate of the counterfactual mean under a modified treatment policy.
S3 object of class txshift
containing the results of the
procedure to compute a one-step estimate of the treatment shift parameter.
Plot working MSM for causal effects of an intervention grid
## S3 method for class 'txshift_msm' plot(x, ...)
## S3 method for class 'txshift_msm' plot(x, ...)
x |
Object of class |
... |
Additional arguments passed to |
Creates a visualization of the intervention-specific counterfactual means as well as the working marginal structural model summarizing the trend across posited values of the intervention.
if (require("sl3")) { set.seed(3287) n_obs <- 1000 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(2 * A - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25) ) plot(msm) # fit a linear spline with knot at 0 set.seed(8293) n_obs <- 1000 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(0.1 * A * (A >= 0) - 3 * A * (A < 0) - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25), msm_form = list(type = "piecewise", knot = 0) ) plot(msm) }
if (require("sl3")) { set.seed(3287) n_obs <- 1000 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(2 * A - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25) ) plot(msm) # fit a linear spline with knot at 0 set.seed(8293) n_obs <- 1000 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(0.1 * A * (A >= 0) - 3 * A * (A < 0) - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25), msm_form = list(type = "piecewise", knot = 0) ) plot(msm) }
Print Method for Counterfactual Mean of Stochastic Shift Intervention
## S3 method for class 'txshift' print(x, ..., ci_level = 0.95)
## S3 method for class 'txshift' print(x, ..., ci_level = 0.95)
x |
An object of class |
... |
Other options (not currently used). |
ci_level |
A |
The print
method for objects of class txshift
.
None. Called for the side effect of printing an informative summary
of slots of objects of class txshift
.
if (require("sl3")) { 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))) txout <- txshift( W = W, A = A, Y = Y, delta = 0.5, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ) ) print(txout) }
if (require("sl3")) { 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))) txout <- txshift( W = W, A = A, Y = Y, delta = 0.5, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ) ) print(txout) }
Print Method for Marginal Structural Models
## S3 method for class 'txshift_msm' print(x, ...)
## S3 method for class 'txshift_msm' print(x, ...)
x |
An object of class |
... |
Other options (not currently used). |
The print
method for objects of class txshift_msm
.
None. Called for the side effect of printing an informative summary
of slots of objects of class txshift_msm
.
if (require("sl3")) { set.seed(3287) n_obs <- 1000 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(2 * A - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25) ) print(msm) }
if (require("sl3")) { set.seed(3287) n_obs <- 1000 W <- as.numeric(replicate(1, rbinom(n_obs, 1, 0.5))) A <- as.numeric(rnorm(n_obs, mean = 2 * W, sd = 1)) Y <- rbinom(n_obs, 1, plogis(2 * A - W)) msm <- msm_vimshift( W = W, A = A, Y = Y, estimator = "tmle", g_exp_fit_args = list( fit_type = "sl", sl_learners_density = Lrnr_density_hse$new(Lrnr_glm$new()) ), Q_fit_args = list( fit_type = "glm", glm_formula = "Y ~ ." ), delta_grid = seq(-1, 1, 0.25) ) print(msm) }
Transform values from the unit interval back to their original scale
scale_to_original(scaled_vals, max_orig, min_orig)
scale_to_original(scaled_vals, max_orig, min_orig)
scaled_vals |
A |
max_orig |
A |
min_orig |
A |
A back-transformation that returns values computed in the unit
interval to their original scale. This is used in re-scaling updated TML
estimates back to their natural scale. Undoes scale_to_unit
.
A numeric
vector of the same length as scaled_vals
,
where the values are re-scaled to lie in their original/natural interval.
Transform values by scaling to the unit interval
scale_to_unit(vals)
scale_to_unit(vals)
vals |
A |
A transformation that scales an arbitrary set of input values to
the unit interval. See scale_to_original
for a corresponding
backtransformation.
A numeric
vector of the same length as vals
, where the
values are re-scaled to lie in unit interval [0, 1].
Simple Additive Modified Treatment Policy
shift_additive(A, W = NULL, delta)
shift_additive(A, W = NULL, delta)
A |
A |
W |
A |
delta |
A |
A simple modified treatment policy that modifes the observed value
of the exposure by shifting it by a value delta
. Note that this
shifting function assumes support of A|W across all strata of W.
A numeric
vector containing the shifted exposure values.
Targeted Minimum Loss Estimate of Counterfactual Mean of Stochastic Shift Intervention
tmle_txshift( data_internal, C_samp = rep(1, nrow(data_internal)), V = NULL, delta, samp_estim, gn_cens_weights, Qn_estim, Hn_estim, fluctuation = c("standard", "weighted"), max_iter = 10, eif_reg_type = c("hal", "glm"), samp_fit_args, ipcw_efficiency = TRUE )
tmle_txshift( data_internal, C_samp = rep(1, nrow(data_internal)), V = NULL, delta, samp_estim, gn_cens_weights, Qn_estim, Hn_estim, fluctuation = c("standard", "weighted"), max_iter = 10, eif_reg_type = c("hal", "glm"), samp_fit_args, ipcw_efficiency = TRUE )
data_internal |
A |
C_samp |
A |
V |
The covariates that are used in determining the sampling procedure
that gives rise to censoring. The default is |
delta |
A |
samp_estim |
An object providing the value of the sampling mechanism
evaluated across the full data. This object is passed in after being
constructed by a call to the internal function |
gn_cens_weights |
An object providing the value of inverse probability of censoring weights, the inverse of the censoring mechanism estimate. The weights are used as part of the IPCW-TMLE procedure to implement a joint intervention that removes the contribution of the censoring process. |
Qn_estim |
An object providing the value of the outcome evaluated after
imposing a shift in the treatment. This object is passed in after being
constructed by a call to the internal function |
Hn_estim |
An object providing values of the auxiliary ("clever")
covariate, constructed from the treatment mechanism and required for
targeted minimum loss-based estimation. This object object should be passed
in after being constructed by a call to |
fluctuation |
The method to be used in the submodel fluctuation step (targeting step) to compute the TML estimator. The choices are "standard" and "weighted" for where to place the auxiliary covariate in the logistic tilting regression. |
max_iter |
A |
eif_reg_type |
Whether a flexible nonparametric function ought to be
used in the dimension-reduced nuisance regression of the targeting step for
the censored data case. By default, the method used is a nonparametric
regression based on the Highly Adaptive Lasso (from hal9001).
Set this to |
samp_fit_args |
A |
ipcw_efficiency |
Whether to invoke an augmentation of the IPCW-TMLE
procedure that performs an iterative process to ensure efficiency of the
resulting estimate. The default is |
Invokes the procedure to construct a targeted minimum loss estimate (TMLE) of the counterfactual mean under a modified treatment policy.
S3 object of class txshift
containing the results of the
procedure to compute a TML estimate of the treatment shift parameter.
Efficient Estimate of Counterfactual Mean of Stochastic Shift Intervention
txshift( W, A, C_cens = rep(1, length(A)), Y, C_samp = rep(1, length(Y)), V = NULL, delta = 0, estimator = c("tmle", "onestep"), fluctuation = c("standard", "weighted"), max_iter = 10, gps_bound = 0.01, samp_fit_args = list(fit_type = c("glm", "sl", "external"), sl_learners = NULL), g_exp_fit_args = list(fit_type = c("hal", "sl", "external"), lambda_seq = exp(seq(-1, -13, length = 300)), sl_learners_density = NULL), g_cens_fit_args = list(fit_type = c("glm", "sl", "external"), glm_formula = "C_cens ~ .^2", sl_learners = NULL), Q_fit_args = list(fit_type = c("glm", "sl", "external"), glm_formula = "Y ~ .^2", sl_learners = NULL), eif_reg_type = c("hal", "glm"), ipcw_efficiency = TRUE, samp_fit_ext = NULL, gn_exp_fit_ext = NULL, gn_cens_fit_ext = NULL, Qn_fit_ext = NULL )
txshift( W, A, C_cens = rep(1, length(A)), Y, C_samp = rep(1, length(Y)), V = NULL, delta = 0, estimator = c("tmle", "onestep"), fluctuation = c("standard", "weighted"), max_iter = 10, gps_bound = 0.01, samp_fit_args = list(fit_type = c("glm", "sl", "external"), sl_learners = NULL), g_exp_fit_args = list(fit_type = c("hal", "sl", "external"), lambda_seq = exp(seq(-1, -13, length = 300)), sl_learners_density = NULL), g_cens_fit_args = list(fit_type = c("glm", "sl", "external"), glm_formula = "C_cens ~ .^2", sl_learners = NULL), Q_fit_args = list(fit_type = c("glm", "sl", "external"), glm_formula = "Y ~ .^2", sl_learners = NULL), eif_reg_type = c("hal", "glm"), ipcw_efficiency = TRUE, samp_fit_ext = NULL, gn_exp_fit_ext = NULL, gn_cens_fit_ext = NULL, Qn_fit_ext = NULL )
W |
A |
A |
A |
C_cens |
A |
Y |
A |
C_samp |
A |
V |
The covariates that are used in determining the sampling procedure
that gives rise to censoring. The default is |
delta |
A |
estimator |
The type of estimator to be fit, either |
fluctuation |
The method to be used in the submodel fluctuation step (targeting step) to compute the TML estimator. The choices are "standard" and "weighted" for where to place the auxiliary covariate in the logistic tilting regression. |
max_iter |
A |
gps_bound |
|
samp_fit_args |
A |
g_exp_fit_args |
A |
g_cens_fit_args |
A |
Q_fit_args |
A |
eif_reg_type |
Whether a flexible nonparametric function ought to be
used in the dimension-reduced nuisance regression of the targeting step for
the censored data case. By default, the method used is a nonparametric
regression based on the Highly Adaptive Lasso (from hal9001). Set
this to |
ipcw_efficiency |
Whether to use an augmented inverse probability of
censoring weighted EIF estimating equation to ensure efficiency of the
resultant estimate. The default is |
samp_fit_ext |
The results of an external fitting procedure used to
estimate the two-phase sampling mechanism, to be used in constructing the
inverse probability of censoring weighted TML or one-step estimator. The
input provided must match the output of |
gn_exp_fit_ext |
The results of an external fitting procedure used to
estimate the exposure mechanism (generalized propensity score), to be used
in constructing the TML or one-step estimator. The input provided must
match the output of |
gn_cens_fit_ext |
The results of an external fitting procedure used to
estimate the censoring mechanism (propensity score for missingness), to be
used in constructing the TML or one-step estimator. The input provided must
match the output of |
Qn_fit_ext |
The results of an external fitting procedure used to
estimate the outcome mechanism, to be used in constructing the TML or
one-step estimator. The input provided must match the output of
|
Construct a one-step estimate or targeted minimum loss estimate of the counterfactual mean under a modified treatment policy, automatically making adjustments for two-phase sampling when a censoring indicator is included. Ensemble machine learning may be used to construct the initial estimates of nuisance functions using sl3.
S3 object of class txshift
containing the results of the
procedure to compute a TML or one-step estimate of the counterfactual mean
under a modified treatment policy that shifts a continuous-valued exposure
by a scalar amount delta
. These estimates can be augmented to be
consistent and efficient when two-phase sampling is performed.
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" ) ## End(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" ) ## End(Not run)