Title: | Causal Inference for Multiple Treatments with a Binary Outcome |
---|---|
Description: | Different methods to conduct causal inference for multiple treatments with a binary outcome, including regression adjustment, vector matching, Bayesian additive regression trees, targeted maximum likelihood and inverse probability of treatment weighting using different generalized propensity score models such as multinomial logistic regression, generalized boosted models and super learner. For more details, see the paper by Hu et al. <doi:10.1177/0962280220921909>. |
Authors: | Liangyuan Hu [aut], Chenyang Gu [aut], Michael Lopez [aut], Jiayi Ji [aut, cre] |
Maintainer: | Jiayi Ji <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2.0 |
Built: | 2025-03-13 04:48:41 UTC |
Source: | https://github.com/cran/CIMTx |
The function ce_estimate
implements the 6
different methods for causal inference with
multiple treatments using observational data.
ce_estimate( y, x, w, method, formula = NULL, discard = FALSE, estimand, trim_perc = NULL, sl_library, reference_trt, boot = FALSE, nboots, verbose_boot = TRUE, ndpost = 1000, caliper = 0.25, n_cluster = 5, ... )
ce_estimate( y, x, w, method, formula = NULL, discard = FALSE, estimand, trim_perc = NULL, sl_library, reference_trt, boot = FALSE, nboots, verbose_boot = TRUE, ndpost = 1000, caliper = 0.25, n_cluster = 5, ... )
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
method |
A character string. Users can selected from the
following methods including |
formula |
A |
discard |
A logical indicating whether to use the discarding rules
for the BART based methods. The default is |
estimand |
A character string representing the type of causal estimand.
Only |
trim_perc |
A 2-vector numeric value indicating the percentile
at which the inverse probability of treatment weights should be trimmed.
The default is |
sl_library |
A character vector of prediction algorithms.
A list of functions included in the SuperLearner package
can be found with |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
boot |
A logical indicating whether or not to use nonparametric
bootstrap to calculate the 95% confidence intervals of the causal
effect estimates. The default is |
nboots |
A numeric value representing the number of bootstrap samples. |
verbose_boot |
A logical value indicating whether to
print the progress of nonparametric bootstrap.
The default is |
ndpost |
A numeric value indicating the number of posterior draws
for the Bayesian methods ( |
caliper |
A numeric value denoting the caliper which should be used
when matching ( |
n_cluster |
A numeric value denoting the number of clusters to form
using K means clustering on the logit of GPS when |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function. For VM, the output contains the number
of matched individuals. For BART and discard = TRUE
,
the output contains number of discarded individuals. For IPTW related
method and boot = FALSE
, the weight distributions can be
visualized using plot
function. For BART and RA, the output
contains a list of the posterior samples of causal estimands.
Hu, L., Gu, C., Lopez, M., Ji, J., & Wisnivesky, J. (2020). Estimation of causal effects of multiple treatments in observational studies with a binary outcome. Statistical Methods in Medical Research, 29(11), 3218–3234.
Hu, L., Gu, C. Estimation of causal effects of multiple treatments in healthcare database studies with rare outcomes. Health Service Outcomes Research Method 21, 287–308 (2021).
Sparapani R, Spanbauer C, McCulloch R Nonparametric Machine Learning and Efficient Computation with Bayesian Additive Regression Trees: The BART R Package. Journal of Statistical Software, 97(1), 1-66.
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
Matthew Cefalu, Greg Ridgeway, Dan McCaffrey, Andrew Morral, Beth Ann Griffin and Lane Burgette (2021). twang: Toolkit for Weighting and Analysis of Nonequivalent Groups. R package version 2.5. URL:https://CRAN.R-project.org/package=twang
Noah Greifer (2021). WeightIt: Weighting for Covariate Balance in Observational Studies. R package version 0.12.0. URL:https://CRAN.R-project.org/package=WeightIt
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
Andrew Gelman and Yu-Sung Su (2020). arm: Data Analysis Using Regression and Multilevel/Hierarchical Models. R package version 1.11-2. URL:https://CRAN.R-project.org/package=arm
Wood, S.N. (2011) Fast stable restricted maximum likelihood and marginal likelihood estimation of semiparametric generalized linear models. Journal of the Royal Statistical Society (B) 73(1):3-36
Eric Polley, Erin LeDell, Chris Kennedy and Mark van der Laan (2021). SuperLearner: Super Learner Prediction. R package version 2.0-28. URL:https://CRAN.R-project.org/package=SuperLearner
Susan Gruber, Mark J. van der Laan (2012). tmle: An R Package for Targeted Maximum Likelihood Estimation. Journal of Statistical Software, 51(13), 1-35.
Jasjeet S. Sekhon (2011). Multivariate and Propensity Score Matching Software with Automated Balance Optimization: The Matching Package for R. Journal of Statistical Software, 42(7), 1-52
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.
Claus O. Wilke (2020). cowplot: Streamlined Plot Theme and Plot Annotations for 'ggplot2'. R package version 1.1.1. URL:https://CRAN.R-project.org/package=cowplot
Elio Campitelli (2021). metR: Tools for Easier Analysis of Meteorological Fields. R package version 0.11.0. URL:https://github.com/eliocamp/metR
Hadley Wickham (2021). tidyr: Tidy Messy Data. R package version 1.1.4. https://CRAN.R-project.org/package=tidyr
Microsoft Corporation and Steve Weston (2020). doParallel: Foreach Parallel Adaptor for the 'parallel' Package. R package version 1.0.16. URL:https://CRAN.R-project.org/package=doParallel
Microsoft and Steve Weston (2020). foreach: Provides Foreach Looping Construct. R package version 1.5.1. URL:https://CRAN.R-project.org/package=foreach
lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) ce_estimate( y = data$y, x = data$covariates, w = data$w, ndpost = 100, method = "RA", estimand = "ATE" )
lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) ce_estimate( y = data$y, x = data$covariates, w = data$w, ndpost = 100, method = "RA", estimand = "ATE" )
The function ce_estimate_bart_ate
implements
BART to estimate ATE effect with
multiple treatments using observational data.
ce_estimate_bart_ate(y, x, w, discard = FALSE, ndpost = 1000, ...)
ce_estimate_bart_ate(y, x, w, discard = FALSE, ndpost = 1000, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
discard |
A logical indicating whether to use the discarding rules.
The default is |
ndpost |
A numeric value indicating the number of posterior draws. |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function. The output also
contains a list of the posterior samples of causal estimands. When
discard = TRUE
, the output contains number of discarded
individuals.
Sparapani R, Spanbauer C, McCulloch R Nonparametric Machine Learning and Efficient Computation with Bayesian Additive Regression Trees: The BART R Package. Journal of Statistical Software, 97(1), 1-66.
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
The function ce_estimate_bart_att
implements
BART to estimate ATT effect with
multiple treatments using observational data.
ce_estimate_bart_att( y, x, w, discard = FALSE, ndpost = 1000, reference_trt, ... )
ce_estimate_bart_att( y, x, w, discard = FALSE, ndpost = 1000, reference_trt, ... )
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
discard |
A logical indicating whether to use the discarding rules.
The default is |
ndpost |
A numeric value indicating the number of posterior draws. |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function. The output also
contains a list of the posterior samples of causal estimands. When
discard = TRUE
, the output contains number of discarded
individuals.
Sparapani R, Spanbauer C, McCulloch R Nonparametric Machine Learning and Efficient Computation with Bayesian Additive Regression Trees: The BART R Package. Journal of Statistical Software, 97(1), 1-66.
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
The function ce_estimate_iptw_ate
implements
IPTW to estimate ATE effect with
multiple treatments using observational data.
ce_estimate_iptw_ate(y, w, x, method, ...)
ce_estimate_iptw_ate(y, w, x, method, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
w |
A numeric vector representing the treatment groups. |
x |
A dataframe, including all the covariates but not treatments. |
method |
A character string. Users can selected from the
following methods including |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function. The weight distributions can be
visualized using plot
function.
Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
Matthew Cefalu, Greg Ridgeway, Dan McCaffrey, Andrew Morral, Beth Ann Griffin and Lane Burgette (2021). twang: Toolkit for Weighting and Analysis of Nonequivalent Groups. R package version 2.5. URL:https://CRAN.R-project.org/package=twang
Noah Greifer (2021). WeightIt: Weighting for Covariate Balance in Observational Studies. R package version 0.12.0. URL:https://CRAN.R-project.org/package=WeightIt
The function ce_estimate_iptw_ate_boot
implements
IPTW with bootstrapping to estimate ATE effect with
multiple treatments using observational data.
ce_estimate_iptw_ate_boot(y, x, w, method, nboots, verbose_boot, ...)
ce_estimate_iptw_ate_boot(y, x, w, method, nboots, verbose_boot, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
method |
A character string. Users can selected from the following
methods including |
nboots |
A numeric value representing the number of bootstrap samples. |
verbose_boot |
A logical value indicating whether to print the progress of nonparametric bootstrap. |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
The function ce_estimate_iptw_att
implements
IPTW to estimate ATT effect with
multiple treatments using observational data.
ce_estimate_iptw_att(y, x, w, method, reference_trt, ...)
ce_estimate_iptw_att(y, x, w, method, reference_trt, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
method |
A character string. Users can selected from the
following methods including |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function. The weight distributions can be
visualized using plot
function.
Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
Matthew Cefalu, Greg Ridgeway, Dan McCaffrey, Andrew Morral, Beth Ann Griffin and Lane Burgette (2021). twang: Toolkit for Weighting and Analysis of Nonequivalent Groups. R package version 2.5. URL:https://CRAN.R-project.org/package=twang
Noah Greifer (2021). WeightIt: Weighting for Covariate Balance in Observational Studies. R package version 0.12.0. URL:https://CRAN.R-project.org/package=WeightIt
The function ce_estimate_iptw_att_boot
implements
IPTW with bootstrapping to estimate ATT effect with
multiple treatments using observational data.
ce_estimate_iptw_att_boot( y, x, w, reference_trt, method, nboots, verbose_boot, ... )
ce_estimate_iptw_att_boot( y, x, w, reference_trt, method, nboots, verbose_boot, ... )
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
method |
A character string. Users can selected from the
following methods including |
nboots |
A numeric value representing the number of bootstrap samples. |
verbose_boot |
A logical value indicating whether to print
the progress of nonparametric bootstrap. The default is |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
The function ce_estimate_ra_ate
implements
RA to estimate ATE effect with
multiple treatments using observational data.
ce_estimate_ra_ate(y, x, w, ndpost)
ce_estimate_ra_ate(y, x, w, ndpost)
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
ndpost |
A numeric value indicating the number of posterior draws. |
A summary of the effect estimates can be obtained
with summary
function. The output also
contains a list of the posterior samples of causal estimands.
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
Andrew Gelman and Yu-Sung Su (2020). arm: Data Analysis Using Regression and Multilevel/Hierarchical Models. R package version 1.11-2. https://CRAN.R-project.org/package=arm
The function ce_estimate_ra_att
implements
RA to estimate ATT effect with
multiple treatments using observational data.
ce_estimate_ra_att(y, x, w, ndpost, reference_trt)
ce_estimate_ra_att(y, x, w, ndpost, reference_trt)
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
ndpost |
A numeric value indicating the number of posterior draws. |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
A summary of the effect estimates can be obtained
with summary
function. The output also
contains a list of the posterior samples of causal estimands.
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
Andrew Gelman and Yu-Sung Su (2020). arm: Data Analysis Using Regression and Multilevel/Hierarchical Models. R package version 1.11-2. https://CRAN.R-project.org/package=arm
The function ce_estimate_rams_ate
implements
RAMS to estimate ATE effect with
multiple treatments using observational data.
ce_estimate_rams_ate(y, w, x, method, ...)
ce_estimate_rams_ate(y, w, x, method, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
w |
A numeric vector representing the treatment groups. |
x |
A dataframe, including all the covariates but not treatments. |
method |
A character string. Users can selected from the
following methods including |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function.
Matthew Cefalu, Greg Ridgeway, Dan McCaffrey, Andrew Morral, Beth Ann Griffin and Lane Burgette (2021). twang: Toolkit for Weighting and Analysis of Nonequivalent Groups. R package version 2.5. URL:https://CRAN.R-project.org/package=twang
Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
Noah Greifer (2021). WeightIt: Weighting for Covariate Balance in Observational Studies. R package version 0.12.0. URL:https://CRAN.R-project.org/package=WeightIt
Wood, S.N. (2011) Fast stable restricted maximum likelihood and marginal likelihood estimation of semiparametric generalized linear models. Journal of the Royal Statistical Society (B) 73(1):3-36
The function ce_estimate_rams_ate_boot
implements
RAMS with bootstrapping to estimate ATE effect with
multiple treatments using observational data.
ce_estimate_rams_ate_boot(y, w, x, method, nboots, verbose_boot, ...)
ce_estimate_rams_ate_boot(y, w, x, method, nboots, verbose_boot, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
w |
A numeric vector representing the treatment groups. |
x |
A dataframe, including all the covariates but not treatments. |
method |
A character string. Users can selected from the
following methods including |
nboots |
A numeric value representing the number of bootstrap samples. |
verbose_boot |
A logical value indicating whether to print the progress of nonparametric bootstrap. |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
The function ce_estimate_rams_att
implements
RAMS to estimate ATT effect with
multiple treatments using observational data.
ce_estimate_rams_att(y, w, x, method, reference_trt, ...)
ce_estimate_rams_att(y, w, x, method, reference_trt, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
w |
A numeric vector representing the treatment groups. |
x |
A dataframe, including all the covariates but not treatments. |
method |
A character string. Users can selected from the
following methods including |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function.
Matthew Cefalu, Greg Ridgeway, Dan McCaffrey, Andrew Morral, Beth Ann Griffin and Lane Burgette (2021). twang: Toolkit for Weighting and Analysis of Nonequivalent Groups. R package version 2.5. URL:https://CRAN.R-project.org/package=twang
Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
Noah Greifer (2021). WeightIt: Weighting for Covariate Balance in Observational Studies. R package version 0.12.0. URL:https://CRAN.R-project.org/package=WeightIt
Wood, S.N. (2011) Fast stable restricted maximum likelihood and marginal likelihood estimation of semiparametric generalized linear models. Journal of the Royal Statistical Society (B) 73(1):3-36
The function ce_estimate_rams_att_boot
implements
RAMS with bootstrapping to estimate ATT effect with
multiple treatments using observational data.
ce_estimate_rams_att_boot( y, w, x, reference_trt, method, nboots, verbose_boot, ... )
ce_estimate_rams_att_boot( y, w, x, reference_trt, method, nboots, verbose_boot, ... )
y |
A numeric vector (0, 1) representing a binary outcome. |
w |
A numeric vector representing the treatment groups. |
x |
A dataframe, including all the covariates but not treatments. |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
method |
A character string. Users can selected from the
following methods including |
nboots |
A numeric value representing the number of bootstrap samples. |
verbose_boot |
A logical value indicating whether to print the progress of nonparametric bootstrap. |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
The function ce_estimate_tmle_ate
implements
TMLE to estimate ATE effect with
multiple treatments using observational data.
ce_estimate_tmle_ate(y, w, x, sl_library, ...)
ce_estimate_tmle_ate(y, w, x, sl_library, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
w |
A numeric vector representing the treatment groups. |
x |
A dataframe, including all the covariates but not treatments. |
sl_library |
A character vector of prediction algorithms.
A list of functions included in the SuperLearner package
can be found with |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function.
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
Eric Polley, Erin LeDell, Chris Kennedy and Mark van der Laan (2021). SuperLearner: Super Learner Prediction. R package version 2.0-28. URL:https://CRAN.R-project.org/package=SuperLearner
Susan Gruber, Mark J. van der Laan (2012). tmle: An R Package for Targeted Maximum Likelihood Estimation. Journal of Statistical Software, 51(13), 1-35.
Causal inference with multiple treatments using TMLE for ATE effects (bootstrapping for CI)
ce_estimate_tmle_ate_boot(y, x, w, nboots, verbose_boot, ...)
ce_estimate_tmle_ate_boot(y, x, w, nboots, verbose_boot, ...)
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
nboots |
A numeric value representing the number of bootstrap samples. |
verbose_boot |
A logical value indicating whether to print the progress of nonparametric bootstrap. |
... |
Other parameters that can be passed through to functions. |
A summary of the effect estimates can be obtained
with summary
function.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
The function ce_estimate_vm_att
implements
VM to estimate ATT effect with
multiple treatments using observational data.
ce_estimate_vm_att(y, x, w, reference_trt, caliper, n_cluster)
ce_estimate_vm_att(y, x, w, reference_trt, caliper, n_cluster)
y |
A numeric vector (0, 1) representing a binary outcome. |
x |
A dataframe, including all the covariates but not treatments. |
w |
A numeric vector representing the treatment groups. |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
caliper |
A numeric value denoting the caliper on the logit of
GPS within each cluster formed by K-means clustering.
The caliper is in standardized units.
For example, |
n_cluster |
A numeric value denoting the number of clusters to form using K means clustering on the logit of GPS. |
A summary of the effect estimates can be obtained
with summary
function. The output also contains the number
of matched individuals.
Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
Jasjeet S. Sekhon (2011). Multivariate and Propensity Score Matching Software with A utomated Balance Optimization: The Matching Package for R. Journal of Statistical Software, 42(7), 1-52
Covariate overlap figure
covariate_overlap(treatment, prob)
covariate_overlap(treatment, prob)
treatment |
A numeric vector representing the treatment groups. |
prob |
Probability of being assigned to the treatment group. |
A ggplot figure.
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.
Claus O. Wilke (2020). cowplot: Streamlined Plot Theme and Plot Annotations for 'ggplot2'. R package version 1.1.1. URL:https://CRAN.R-project.org/package=cowplot
The function data_sim
simulate data for binary outcome with
multiple treatments. Users can adjust the following 7 design factors:
(1) sample size, (2) ratio of units across treatment groups,
(3) whether the treatment assignment model and the outcome generating model
are linear or nonlinear, (4) whether the covariates that best predict
the treatment also predict the outcome well,
(5) whether the response surfaces are parallel across treatment groups,
(6) outcome prevalence, and (7) degree of covariate overlap.
data_sim( sample_size, n_trt = 3, x = "rnorm(0, 1)", lp_y = rep("x1", 3), nlp_y = NULL, align = TRUE, tau = c(0, 0, 0), delta = c(0, 0), psi = 1, lp_w, nlp_w )
data_sim( sample_size, n_trt = 3, x = "rnorm(0, 1)", lp_y = rep("x1", 3), nlp_y = NULL, align = TRUE, tau = c(0, 0, 0), delta = c(0, 0), psi = 1, lp_w, nlp_w )
sample_size |
A numeric value indicating the total number of units. |
n_trt |
A numeric value indicating the number of treatments. The default is set to 3. |
x |
A vector of characters representing covariates,
with each covariate being generated from the standard probability.
The default is set to "rnorm(0, 1)".
|
lp_y |
A vector of characters of length |
nlp_y |
A vector of characters of length |
align |
A logical indicating whether the predictors in the
treatment assignment model are the same as the predictors for
the outcome generating model.
The default is |
tau |
A numeric vector of length |
delta |
A numeric vector of length |
psi |
A numeric value for the parameter governing the sparsity of covariate overlap. Higher values mean weaker covariate overlap; lower values mean stronger covariate overlap. The default is set to 1, which corresponds to a moderate covariate overlap. |
lp_w |
is a vector of characters of length |
nlp_w |
is a vector of characters of length |
A list with 7 elements for simulated data. It contains
covariates: |
x matrix |
w: |
treatment indicators |
y: |
observed binary outcomes |
y_prev: |
outcome prevalence rates |
ratio_of_units: |
the proportions of units in each treatment group |
overlap_fig: |
the visualization of covariate overlap via boxplots of the distributions of true GPS |
y_true: |
simulated true outcome in each treatment group |
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
library(CIMTx) lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2,0.4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1,0.4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 )
library(CIMTx) lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2,0.4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1,0.4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 )
Plot for non-IPTW estimation methods with bootstrapping for ATE effect
## S3 method for class 'CIMTx_ATE_posterior' plot(x, ...)
## S3 method for class 'CIMTx_ATE_posterior' plot(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
an error message
## Not run: result <- list(method = "RA") class(result) <- "CIMTx_ATE_posterior" plot(result) ## End(Not run)
## Not run: result <- list(method = "RA") class(result) <- "CIMTx_ATE_posterior" plot(result) ## End(Not run)
Plot for non-IPTW estimation methods for ATT effect
## S3 method for class 'CIMTx_ATT_posterior' plot(x, ...)
## S3 method for class 'CIMTx_ATT_posterior' plot(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
an error message
## Not run: result <- list(method = "RA") class(result) <- "CIMTx_ATT_posterior" plot(result) ## End(Not run)
## Not run: result <- list(method = "RA") class(result) <- "CIMTx_ATT_posterior" plot(result) ## End(Not run)
This function make the boxplot plot for the weights estimated by different IPTW methods. The inputs of the function are from the output of ce_estimate.R function when the methods are "IPTW-Multinomial", "IPTW-GBM", "IPTW-SL".
## S3 method for class 'CIMTx_IPTW' plot(...)
## S3 method for class 'CIMTx_IPTW' plot(...)
... |
Objects from IPTW related methods |
A ggplot figure
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.
Claus O. Wilke (2020). cowplot: Streamlined Plot Theme and Plot Annotations for 'ggplot2'. R package version 1.1.1. URL:https://CRAN.R-project.org/package=cowplot
iptw_object_example <- list(weight = rnorm(1000, 1, 1), method = "IPTW-SL") class(iptw_object_example) <- "CIMTx_IPTW" plot(iptw_object_example)
iptw_object_example <- list(weight = rnorm(1000, 1, 1), method = "IPTW-SL") class(iptw_object_example) <- "CIMTx_IPTW" plot(iptw_object_example)
Plot for non-IPTW estimation methods for ATE effect
## S3 method for class 'CIMTx_nonIPTW_once' plot(x, ...)
## S3 method for class 'CIMTx_nonIPTW_once' plot(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
an error message
## Not run: result <- list(method = "TMLE") class(result) <- "CIMTx_nonIPTW_once" plot(result) ## End(Not run)
## Not run: result <- list(method = "TMLE") class(result) <- "CIMTx_nonIPTW_once" plot(result) ## End(Not run)
This function make the countor plot after the grid specification of sensitivity analysis. The input of the function is from the output of the sa.R function.
## S3 method for class 'CIMTx_sa_grid' plot(x, ate = NULL, att = NULL, ...)
## S3 method for class 'CIMTx_sa_grid' plot(x, ate = NULL, att = NULL, ...)
x |
Object from sa function |
ate |
a character indicating the ATE effect to plot, eg, "1,3" or "2,3" |
att |
a character indicating the ATT effect to plot, eg, "1,3" or "1,2" |
... |
further arguments passed to or from other methods. |
A ggplot figure
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
Elio Campitelli (2021). metR: Tools for Easier Analysis of Meteorological Fields. R package version 0.11.0. URL:https://github.com/eliocamp/metR
sa_object_example <- list( ATE13 = seq(0, 1, length.out = 25), grid_index = c(4, 5), c_functions = data.frame( c4 = rep(seq(-0.6, 0, 0.15), each = 5), c5 = rep(seq(0, 0.6, 0.15), 5) ) ) class(sa_object_example) <- "CIMTx_sa_grid" plot(sa_object_example, ate = "1,3")
sa_object_example <- list( ATE13 = seq(0, 1, length.out = 25), grid_index = c(4, 5), c_functions = data.frame( c4 = rep(seq(-0.6, 0, 0.15), each = 5), c5 = rep(seq(0, 0.6, 0.15), 5) ) ) class(sa_object_example) <- "CIMTx_sa_grid" plot(sa_object_example, ate = "1,3")
Posterior distribution summary
posterior_summary(rd_est, rr_est, or_est)
posterior_summary(rd_est, rr_est, or_est)
rd_est |
Posterior distribution for rd estimates. |
rr_est |
Posterior distribution for rr estimates. |
or_est |
Posterior distribution for rr estimates. |
A list of causal estimands including risk difference (rd), odds ratios (or) and relative risk (rr) between different treatment groups.
The print
method for class "CIMTx_ATE_posterior"
## S3 method for class 'CIMTx_ATE_posterior' print(x, ...)
## S3 method for class 'CIMTx_ATE_posterior' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
The output from print
result <- list(method = "RA") class(result) <- "CIMTx_ATE_posterior" print(result)
result <- list(method = "RA") class(result) <- "CIMTx_ATE_posterior" print(result)
The print
method for class "CIMTx_ATE_sa"
## S3 method for class 'CIMTx_ATE_sa' print(x, ...)
## S3 method for class 'CIMTx_ATE_sa' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
The output from print
result <- list(estimand = "ATE") class(result) <- "CIMTx_ATE_sa" print(result)
result <- list(estimand = "ATE") class(result) <- "CIMTx_ATE_sa" print(result)
The print
method for class "CIMTx_ATT_posterior"
## S3 method for class 'CIMTx_ATT_posterior' print(x, ...)
## S3 method for class 'CIMTx_ATT_posterior' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
The output from print
result <- list(method = "RA") class(result) <- "CIMTx_ATT_posterior" print(result)
result <- list(method = "RA") class(result) <- "CIMTx_ATT_posterior" print(result)
The print
method for class "CIMTx_ATT_sa"
## S3 method for class 'CIMTx_ATT_sa' print(x, ...)
## S3 method for class 'CIMTx_ATT_sa' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
The output from print
result <- list(estimand = "ATT") class(result) <- "CIMTx_ATT_sa" print(result)
result <- list(estimand = "ATT") class(result) <- "CIMTx_ATT_sa" print(result)
The print
method for class "CIMTx_IPTW"
## S3 method for class 'CIMTx_IPTW' print(x, ...)
## S3 method for class 'CIMTx_IPTW' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
The output from print
result <- list(method = "IPTW-Multinomial", estimand = "ATE") class(result) <- "CIMTx_IPTW" print(result)
result <- list(method = "IPTW-Multinomial", estimand = "ATE") class(result) <- "CIMTx_IPTW" print(result)
The print
method for class "CIMTx_nonIPTW_once"
## S3 method for class 'CIMTx_nonIPTW_once' print(x, ...)
## S3 method for class 'CIMTx_nonIPTW_once' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
The output from print
result <- list(method = "TMLE", estimand = "ATE") class(result) <- "CIMTx_nonIPTW_once" print(result)
result <- list(method = "TMLE", estimand = "ATE") class(result) <- "CIMTx_nonIPTW_once" print(result)
The print
method for class "CIMTx_sa_grid"
## S3 method for class 'CIMTx_sa_grid' print(x, ...)
## S3 method for class 'CIMTx_sa_grid' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
The output from print
result <- list(estimand = "ATE") class(result) <- "CIMTx_sa_grid" print(result)
result <- list(estimand = "ATE") class(result) <- "CIMTx_sa_grid" print(result)
The function sa
implements the flexible sensitivity analysis
approach for unmeasured confounding with multiple treatments
and a binary outcome.
sa( x, y, w, formula = NULL, prior_c_function, m1, m2 = NULL, n_cores = 1, estimand, reference_trt, ... )
sa( x, y, w, formula = NULL, prior_c_function, m1, m2 = NULL, n_cores = 1, estimand, reference_trt, ... )
x |
A dataframe, including all the covariates but not treatments. |
y |
A numeric vector (0, 1) representing a binary outcome. |
w |
A numeric vector representing the treatment groups. |
formula |
A |
prior_c_function |
1) A vector of characters indicating the
prior distributions for the confounding functions.
Each character contains the random number generation code
from the standard probability
|
m1 |
A numeric value indicating the number of draws of the GPS from the posterior predictive distribution |
m2 |
A numeric value indicating the number of draws from the prior distributions of the confounding functions |
n_cores |
A numeric value indicating number of cores to use for parallel computing. |
estimand |
A character string representing the type of
causal estimand. Only |
reference_trt |
A numeric value indicating reference treatment group for ATT effect. |
... |
Other parameters that can be passed to BART functions |
A list of causal estimands including risk difference (RD) between different treatment groups.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
Hadley Wickham (2021). tidyr: Tidy Messy Data. R package version 1.1.4. URL:https://CRAN.R-project.org/package=tidyr
Sparapani R, Spanbauer C, McCulloch R Nonparametric Machine Learning and Efficient Computation with Bayesian Additive Regression Trees: The BART R Package. Journal of Statistical Software, 97(1), 1-66.
Microsoft Corporation and Steve Weston (2020). doParallel: Foreach Parallel Adaptor for the 'parallel' Package. R package version 1.0.16. URL:https://CRAN.R-project.org/package=doParallel
Microsoft and Steve Weston (2020). foreach: Provides Foreach Looping Construct.. R package version 1.5.1 URL:https://CRAN.R-project.org/package=foreach
lp_w_all <- c( ".4*x1 + .1*x2 - 1.1*x4 + 1.1*x5", # w = 1 ".2 * x1 + .2 * x2 - 1.2 * x4 - 1.3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - 1.1*x4 - 1.2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(1111) data <- data_sim( sample_size = 100, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(0.5, -0.5, 0.5), delta = c(0.5, 0.5), psi = 2 ) c_grid <- c( "runif(-0.6, 0)", # c(1,2) "runif(0, 0.6)", # c(2,1) "runif(-0.6, 0)", # c(2,3) "seq(-0.6, 0, by = 0.3)", # c(1,3) "seq(0, 0.6, by = 0.3)", # c(3,1) "runif(0, 0.6)" # c(3,2) ) sensitivity_analysis_parallel_result <- sa( m1 = 1, x = data$covariates, y = data$y, w = data$w, prior_c_function = c_grid, n_cores = 1, estimand = "ATE", )
lp_w_all <- c( ".4*x1 + .1*x2 - 1.1*x4 + 1.1*x5", # w = 1 ".2 * x1 + .2 * x2 - 1.2 * x4 - 1.3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - 1.1*x4 - 1.2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(1111) data <- data_sim( sample_size = 100, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(0.5, -0.5, 0.5), delta = c(0.5, 0.5), psi = 2 ) c_grid <- c( "runif(-0.6, 0)", # c(1,2) "runif(0, 0.6)", # c(2,1) "runif(-0.6, 0)", # c(2,3) "seq(-0.6, 0, by = 0.3)", # c(1,3) "seq(0, 0.6, by = 0.3)", # c(3,1) "runif(0, 0.6)" # c(3,2) ) sensitivity_analysis_parallel_result <- sa( m1 = 1, x = data$covariates, y = data$y, w = data$w, prior_c_function = c_grid, n_cores = 1, estimand = "ATE", )
Summarize a CIMTx_ATE_posterior object
## S3 method for class 'CIMTx_ATE_posterior' summary(object, ...)
## S3 method for class 'CIMTx_ATE_posterior' summary(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
a list with w*(w-1)/2 elements for ATE effect. Each element of the list contains the estimation, standard error, lower and upper 95% CI for RD/RR/OR.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
library(CIMTx) lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) ce_estimate_ra_ate_result <- ce_estimate( y = data$y, x = data$covariates, w = data$w, ndpost = 10, method = "RA", estimand = "ATE" ) summary(ce_estimate_ra_ate_result)
library(CIMTx) lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) ce_estimate_ra_ate_result <- ce_estimate( y = data$y, x = data$covariates, w = data$w, ndpost = 10, method = "RA", estimand = "ATE" ) summary(ce_estimate_ra_ate_result)
Summarize a CIMTx_ATE_sa object
## S3 method for class 'CIMTx_ATE_sa' summary(object, ...)
## S3 method for class 'CIMTx_ATE_sa' summary(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
a data frame containing the estimation, standard error, lower and upper 95% CI for the causal estimand in terms of RD.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
lp_w_all <- c( ".4*x1 + .1*x2 - 1.1*x4 + 1.1*x5", # w = 1 ".2 * x1 + .2 * x2 - 1.2 * x4 - 1.3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - 1.1*x4 - 1.2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(1111) data <- data_sim( sample_size = 100, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(0.5, -0.5, 0.5), delta = c(0.5, 0.5), psi = 2 ) c_grid <- c( "runif(-0.6, 0)", # c(1,2) "runif(0, 0.6)", # c(2,1) "runif(-0.6, 0)", # c(2,3) "seq(-0.6, 0, by = 0.3)", # c(1,3) "seq(0, 0.6, by = 0.3)", # c(3,1) "runif(0, 0.6)" # c(3,2) ) sensitivity_analysis_parallel_ATE_result <- sa( m1 = 1, x = data$covariates, y = data$y, w = data$w, prior_c_function = c_grid, nCores = 1, estimand = "ATE", ) summary(sensitivity_analysis_parallel_ATE_result)
lp_w_all <- c( ".4*x1 + .1*x2 - 1.1*x4 + 1.1*x5", # w = 1 ".2 * x1 + .2 * x2 - 1.2 * x4 - 1.3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - 1.1*x4 - 1.2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(1111) data <- data_sim( sample_size = 100, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(0.5, -0.5, 0.5), delta = c(0.5, 0.5), psi = 2 ) c_grid <- c( "runif(-0.6, 0)", # c(1,2) "runif(0, 0.6)", # c(2,1) "runif(-0.6, 0)", # c(2,3) "seq(-0.6, 0, by = 0.3)", # c(1,3) "seq(0, 0.6, by = 0.3)", # c(3,1) "runif(0, 0.6)" # c(3,2) ) sensitivity_analysis_parallel_ATE_result <- sa( m1 = 1, x = data$covariates, y = data$y, w = data$w, prior_c_function = c_grid, nCores = 1, estimand = "ATE", ) summary(sensitivity_analysis_parallel_ATE_result)
Summarize a CIMTx_ATT_posterior object
## S3 method for class 'CIMTx_ATT_posterior' summary(object, ...)
## S3 method for class 'CIMTx_ATT_posterior' summary(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
a list with w-1 elements for ATT effect. Each element of the list contains the estimation, standard error, lower and upper 95% CI for RD/RR/OR.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) ce_estimate_ra_att_result <- ce_estimate( y = data$y, x = data$covariates, w = data$w, reference_trt = 1, ndpost = 10, method = "RA", estimand = "ATT" ) summary(ce_estimate_ra_att_result)
lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) ce_estimate_ra_att_result <- ce_estimate( y = data$y, x = data$covariates, w = data$w, reference_trt = 1, ndpost = 10, method = "RA", estimand = "ATT" ) summary(ce_estimate_ra_att_result)
Summarize a CIMTx_ATT_sa object
## S3 method for class 'CIMTx_ATT_sa' summary(object, ...)
## S3 method for class 'CIMTx_ATT_sa' summary(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
a data frame containing the estimation, standard error, lower and upper 95% CI for the causal estimand in terms of RD.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
lp_w_all <- c( ".4*x1 + .1*x2 - 1.1*x4 + 1.1*x5", # w = 1 ".2 * x1 + .2 * x2 - 1.2 * x4 - 1.3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - 1.1*x4 - 1.2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(1111) data <- data_sim( sample_size = 100, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(0.5, -0.5, 0.5), delta = c(0.5, 0.5), psi = 2 ) c_grid <- c( "runif(-0.6, 0)", # c(1,2) "runif(0, 0.6)", # c(2,1) "runif(-0.6, 0)", # c(2,3) "seq(-0.6, 0, by = 0.3)", # c(1,3) "seq(0, 0.6, by = 0.3)", # c(3,1) "runif(0, 0.6)" # c(3,2) ) sensitivity_analysis_parallel_ATT_result <- sa( m1 = 1, x = data$covariates, y = data$y, w = data$w, prior_c_function = c_grid, nCores = 1, estimand = "ATE", ) summary(sensitivity_analysis_parallel_ATT_result)
lp_w_all <- c( ".4*x1 + .1*x2 - 1.1*x4 + 1.1*x5", # w = 1 ".2 * x1 + .2 * x2 - 1.2 * x4 - 1.3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - 1.1*x4 - 1.2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(1111) data <- data_sim( sample_size = 100, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(0.5, -0.5, 0.5), delta = c(0.5, 0.5), psi = 2 ) c_grid <- c( "runif(-0.6, 0)", # c(1,2) "runif(0, 0.6)", # c(2,1) "runif(-0.6, 0)", # c(2,3) "seq(-0.6, 0, by = 0.3)", # c(1,3) "seq(0, 0.6, by = 0.3)", # c(3,1) "runif(0, 0.6)" # c(3,2) ) sensitivity_analysis_parallel_ATT_result <- sa( m1 = 1, x = data$covariates, y = data$y, w = data$w, prior_c_function = c_grid, nCores = 1, estimand = "ATE", ) summary(sensitivity_analysis_parallel_ATT_result)
Summarize a CIMTx_IPTW object
## S3 method for class 'CIMTx_IPTW' summary(object, ...)
## S3 method for class 'CIMTx_IPTW' summary(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
a data frame with ATT/ATE effect estimates in terms of RD, RR and OR.
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) iptw_multi_res <- ce_estimate( y = data$y, x = data$covariates, w = data$w, method = "IPTW-Multinomial", estimand = "ATE" ) summary(iptw_multi_res)
lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) iptw_multi_res <- ce_estimate( y = data$y, x = data$covariates, w = data$w, method = "IPTW-Multinomial", estimand = "ATE" ) summary(iptw_multi_res)
Summarize a CIMTx_nonIPTW_once object
## S3 method for class 'CIMTx_nonIPTW_once' summary(object, ...)
## S3 method for class 'CIMTx_nonIPTW_once' summary(object, ...)
object |
a |
... |
further arguments passed to or from other methods. |
a data frame with ATT/ATE effect estimates in terms of RD, RR and OR.
Hadley Wickham, Romain François, Lionel Henry and Kirill Müller (2021). dplyr: A Grammar of Data Manipulation. R package version 1.0.7. URL: https://CRAN.R-project.org/package=dplyr
Hadley Wickham (2019). stringr: Simple, Consistent Wrappers for Common String Operations. R package version 1.4.0. URL:https://CRAN.R-project.org/package=stringr
lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) iptw_tmle_res <- ce_estimate( y = data$y, x = data$covariates, w = data$w, method = "TMLE", estimand = "ATE", sl_library = c("SL.glm", "SL.glmnet") ) summary(iptw_tmle_res)
lp_w_all <- c( ".4*x1 + .1*x2 - .1*x4 + .1*x5", # w = 1 ".2 * x1 + .2 * x2 - .2 * x4 - .3 * x5" ) # w = 2 nlp_w_all <- c( "-.5*x1*x4 - .1*x2*x5", # w = 1 "-.3*x1*x4 + .2*x2*x5" ) # w = 2 lp_y_all <- rep(".2*x1 + .3*x2 - .1*x3 - .1*x4 - .2*x5", 3) nlp_y_all <- rep(".7*x1*x1 - .1*x2*x3", 3) X_all <- c( "rnorm(0, 0.5)", # x1 "rbeta(2, .4)", # x2 "runif(0, 0.5)", # x3 "rweibull(1,2)", # x4 "rbinom(1, .4)" # x5 ) set.seed(111111) data <- data_sim( sample_size = 300, n_trt = 3, x = X_all, lp_y = lp_y_all, nlp_y = nlp_y_all, align = FALSE, lp_w = lp_w_all, nlp_w = nlp_w_all, tau = c(-1.5, 0, 1.5), delta = c(0.5, 0.5), psi = 1 ) iptw_tmle_res <- ce_estimate( y = data$y, x = data$covariates, w = data$w, method = "TMLE", estimand = "ATE", sl_library = c("SL.glm", "SL.glmnet") ) summary(iptw_tmle_res)
This function calculates the true confounding functions with 3 treatments and a binary predictor for simulated data.
true_c_fun_cal(x, w)
true_c_fun_cal(x, w)
x |
A matrix with one column for the binary predictor with values 0 and 1 |
w |
A treatment indicator |
A matrix with 2 rows and 6 columns
set.seed(111) data_SA <- data_sim( sample_size = 100, n_trt = 3, x = c( "rbinom(1, .5)", # x1:measured confounder "rbinom(1, .4)" ), # x2:unmeasured confounder lp_y = rep(".2*x1+2.3*x2", 3), # parallel response surfaces nlp_y = NULL, align = FALSE, # w model is not the same as the y model lp_w = c( "0.2 * x1 + 2.4 * x2", # w = 1 "-0.3 * x1 - 2.8 * x2" ), nlp_w = NULL, tau = c(-2, 0, 2), delta = c(0, 0), psi = 1 ) x1 <- data_SA$covariates[, 1, drop = FALSE] w <- data_SA$w Y1 <- data_SA$Y_true[, 1] Y2 <- data_SA$Y_true[, 2] Y3 <- data_SA$Y_true[, 3] true_c_fun <- true_c_fun_cal(x = x1, w = w)
set.seed(111) data_SA <- data_sim( sample_size = 100, n_trt = 3, x = c( "rbinom(1, .5)", # x1:measured confounder "rbinom(1, .4)" ), # x2:unmeasured confounder lp_y = rep(".2*x1+2.3*x2", 3), # parallel response surfaces nlp_y = NULL, align = FALSE, # w model is not the same as the y model lp_w = c( "0.2 * x1 + 2.4 * x2", # w = 1 "-0.3 * x1 - 2.8 * x2" ), nlp_w = NULL, tau = c(-2, 0, 2), delta = c(0, 0), psi = 1 ) x1 <- data_SA$covariates[, 1, drop = FALSE] w <- data_SA$w Y1 <- data_SA$Y_true[, 1] Y2 <- data_SA$Y_true[, 2] Y3 <- data_SA$Y_true[, 3] true_c_fun <- true_c_fun_cal(x = x1, w = w)
The function trims the weights for IPTW methods.
trunc_fun(x, trim_perc = 0.05)
trunc_fun(x, trim_perc = 0.05)
x |
A numeric vector |
trim_perc |
A numeric vector with length 2 indicating trimming percentile. |
A numeric vector