CRAN Task View: Causal Inference
Maintainer: | Imke Mayer, Pan Zhao, Noah Greifer, Nick Huntington-Klein, Julie Josse |
Contact: | imke.mayer at inria.fr |
Version: | 2022-06-16 |
URL: | https://CRAN.R-project.org/view=CausalInference |
Source: | https://github.com/cran-task-views/CausalInference/ |
Contributions: | Suggestions and improvements for this task view are very welcome and can be made through issues or pull requests on GitHub or via e-mail to the maintainer address. For further details see the Contributing guide. |
Citation: | Imke Mayer, Pan Zhao, Noah Greifer, Nick Huntington-Klein, Julie Josse (2022). CRAN Task View: Causal Inference. Version 2022-06-16. URL https://CRAN.R-project.org/view=CausalInference. |
Installation: | The packages from this task view can be installed automatically using the ctv package. For example, ctv::install.views("CausalInference", coreOnly = TRUE) installs all the core packages or ctv::update.views("CausalInference") installs all packages that are not yet installed and up-to-date. See the CRAN Task View Initiative for more details. |
Overview
Causal inference can be seen as a subfield of statistical analysis. It is used in various fields such as econometrics, epidemiology, educational sciences, etc. With causal inference one addresses questions about effects of a treatment, intervention, or policy on some target over a given sample or population. Under certain identifiability and model assumptions, causal inference can be carried out by fitting simple regression models or combining several regression models in a specific way as will be sketched out later. For observational data, additional untestable assumptions have to be made to (non-parametrically) identify causal effects.
There are no basic R functions that are direct implementations of standard causal inference designs, but many methods - more or less complex - are implemented in different packages on CRAN, which we structure into main topics:
Certain causal inference methods originated in specific fields such as econometrics or clinical trials and remain most popular therein. In certain cases, we therefore refer to other task views covering these methods in more depth. More generally, in this task view we focus on causal analyses with observational data.
If you think that we missed some important packages in this list, please contact the maintainers.
Methods for randomized controlled trial (RCT) and other experimental data
- Construction of experimental designs is implemented in blocksdesign (blocks for general factorial treatment designs), BCHM (Bayesian cluster hierarchical model design for multiple subgroup basket trials), Boptbd (Bayesian optimal block designs under linear mixed effects model), seqDesign (sequential design of randomized two-stage treatment efficacy trials with time-to-event endpoints). Many other tools and packages exist for designing experiments and clinical trials, we refer to the ExperimentalDesign and ClinicalTrials CRAN Task Views.
- Tests based on pairwise comparisons are provided in BuyseTest.
- Regression models where the causal estimand is defined as a coefficient of a regression model are implemented in the packages allestimates.
- Analysis methods for RCTs are provided in experiment (various statistical methods), eefAnalytics (Frequentist and Bayesian multilevel models), ipcwswitch (IPW adapted to treatment switch in an RCT), idem (with death and missingness).
- Posterior analysis tools are implemented in beanz (Bayesian HTE models), cjoint (conjoint analysis for survey experiments).
- Design and analysis of two-stage preference trials is implemented in preference.
- In case of non-compliance, rpsftm uses g-estimation to estimate the causal effect of a treatment in a two-armed randomised control trial where non-compliance exists and is measured, under an assumption of an accelerated failure time model and no unmeasured confounders.
- A time series causal inference model for RCT under spillover effect is implemented in SPORTSCausal.
- Design and analysis of clinical non-inferiority or superiority trials with active and placebo control is implemented in ThreeArmedTrials.
Average treatment effect estimation and other univariate treatment effect estimates
- Regression models where the causal estimand is a regression parameter are implemented in
lm()
and glm()
from stats, as well as in a number of more specialized packages such as fixest, estimatr, CausalGAM (using generalized additive models), sampleSelection (two-step and maximum likelihood estimation of Heckman-type sample selection models), BCEE (Bayesian causal effect estimation for binary or continuous treatment and outcomes), borrowr (Bayesian PATE estimation for multiple exchangeable data sources), causaldrf (archived) (average causal dose response functions), hdm (efficient estimators with uniformly valid confidence intervals, it assumes approximately sparse models for high-dimensional settings). Estimation in fixed effects designs is possible through fixest (linear and generalized linear fixed effects models and combined with instrumental variables), plm (for panel data), and alpaca (for high-dimensional k-way fixed effects).
- G-computation and other conditional outcome regression based methods are supported in the packages gfoRmula (also for time-varying treatment and confounding), EffectLiteR (based on structural equation modeling), endoSwitch (maximum likelihood estimation of endogenous switching regression models), and riskRegression (for survival outcomes with or without competing risks). For parametric models, g-computation is the same as estimating average marginal effects, which can be achieved using margins, marginaleffects, modelbased, and stdReg.
- Matching methods are implemented in MatchIt, which provides wrappers for a number of popular methods including propensity score matching and subclassification, (coarsened) exact matching, full matching, and cardinality matching; more specialized matching methods are implemented in some of the packages below, some of which MatchIt depends on. MatchThem provides a wrapper for MatchIt with multiply-imputed data. Matching performs nearest neighbor and genetic matching and implements Abadie and Imbens-style matching imputation estimators. optmatch performs optimal matching using network flows; several other packages rely on the same infrastructure, including DiPs (near-fine matching with directional penalties), matchMulti (optimal matching for clustered data), rcbalance and rcbsubset (optimal matching for refined balance), approxmatch (near-optimal matching for multi-category treatments), and match2C (optimal matching using two criteria). Other packages include cem (coarsened exact matching), designmatch (optimization-based matching using mixed integer programming), stratamatch (matching and stratification in large datasets), FLAME (almost-matching-exactly via learned weighted Hamming distance), PanelMatch (matching with time-series cross-sectional data), and CausalGPS (generalized propensity score matching for continuous treatments).
- Inverse propensity weighting (IPW, also known as inverse probability of treatment weighting, IPTW) methods are implemented in WeightIt, which provides implementations and wrappers for several popular weighting methods for binary, multi-category, continuous, and longitudinal treatments. MatchThem provides a wrapper for WeightIt with multiply-imputed data. PSweight offers propensity score weighting and uncertainty estimation using M-estimation. clusteredinterference and inferference offer weighting methods in the context of interference. Several packages offer specialized methods of estimating balancing weights for various treatment types, which may or may not involve a propensity score: CBPS (generalized method of moments-based propensity score estimation for binary, multi-category, continuous, and longitudinal treatments), twang and twangContinuous (propensity score weighting using gradient boosting machines for binary, multi-category, continuous, and longitudinal treatments), sbw and optweight (optimization-based weights using quadratic programming), and ebal (entropy balancing). mvGPS estimates weights for multivariate treatments using WeightIt’s infrastructure. Matching-adjusted indirect comparison, a relative of propensity score weighting when unit-level data is only available for some groups, is available in maic, maicChecks, and optweight (using the
optweight.svy()
function).
- Doubly robust methods involve both a treatment and outcome model. Augmented IPW (AIPW) is implemented in AIPW, PSweight, DoubleML, and causalweight. Targeted maximum likelihood estimation (TMLE, also known as targeted minimum loss-based estimation) is available in drtmle, tmle, ctmle (for TMLE with variable selection), ltmle (for longitudinal data), and AIPW.
- Difference in differences methods are implemented in DRDID (doubly robust estimators with two choices for nuisance function estimation), bacondecomp (using the Goodman-Bacon decomposition to allow for variation in treatment timing), did (for cases with more than two periods and with variation in treatment timing), fixest (Sun & Abraham estimator), and in qte (archived).
- Quantile treatment effects can be estimated using the qte (archived), Counterfactual and grf packages.
- Odds ratio estimation and power calculation for the Trend in Trend model is implemented in TrendInTrend.
- Synthetic control methods are implemented in Synth (using a group method for comparative case studies),microsynth (for micro- and meso-level data), and gsynth (extension to multiple treated units and variable treatment periods). tidysynth offers an easy-to-use syntax for using synthetic control methods.
- Instrumental variable methods are implemented in ivreg, ivmodel, bpbounds (nonparametric bounds on ATE), grf, fixest, estimatr, and DoubleML (function
DoubleMLIIVM
). ivmte provides a choice-theoretic interpretation to IV models using Marginal Treatment Effects to extrapolate from the compliers to estimate treatment effects for other subpopulations. LARF uses Local Average Response Functions for IV estimation of treatment effects with binary endogenous treatment and instrument. icsw implements inverse compliance score weighting for estimating average treatment effects with an instrumental variable. More details and a longer list of packages for IV methods can be found in Instrumental variables in the Econometrics task view.
- Mediation analysis can be performed with cfma (functional mediation analysis), cit (likelihood-based tests), MultisiteMediation (multisite trials), DirectEffects (controlled direct effect when fixing a potential mediator to a specific value), medflex (natural effect models). causalweight and twangMediation implement weighted estimators for mediation. mediation and cfdecomp implement identification, inference and mediation additionally also provides sensitivity analysis for causal mediation effects. Linear mediation analysis for complex surveys using balanced repeated replication is implemented in MedSurvey. paths uses an imputation approach to estimate path-specific causal effects along with a set of bias formulas for conducting sensitivity analysis. regmedint implements regression-based analysis with a treatment-mediator interaction term. gma performs Granger mediation analysis for time series.
- Under interference, causal effect estimation can be achieved using inferference by inverse-probability weighted (IPW) estimators, netchain on collective outcomes by chain graph models approximating the projection of the full longitudinal data onto the observed data.
- Diagnostics and visualization for Multiplicative Interaction Models are implemented in interflex.
- InvariantCausalPrediction provides confidence intervals for causal effects, using data collected in different experimental or environmental conditions (with hidden variables), extensions to nonlinear models are implemented in nonlinearICP.
- Regression discontinuity design (RDD) methods are implemented in rdrobust (offering robust confidence interval construction and bandwidth selection). A more detailed curated list of packages for RDD methods can be found in Regression discontinuity design in the Econometrics task view.
In addition, causalsens, OVtool, dstat, and EValue provide functions for sensitivity analyses (for unmeasured confounding, selection bias, measurement error), and ui implements functions to derive uncertainty intervals and conduct sensitivity analysis for missing data and unobserved confounding. cobalt and tableone generate balance tables and plots before and after covariate balancing, and confoundr implements covariate-balance diagnostics for time-varying confounding. WhatIf offers methods to assess overlap and extrapolation.
Heterogeneous treatment effect estimation
Some of the above mentioned packages can also be used for heterogeneous treatment effect (HTE) estimation.
- Bayesian approaches for individual causal effect estimation are available in several packages including bartCause (based on Bayesian Additive Regression Trees) and bcf (Bayesian Causal Forest).
- Efficacious treatment or population subset selection exploiting treatment effect heterogeneity is implemented in FindIt and grf. This latter package supports missing covariate values using the Missing Incorporated in Attributes approach. Additionally the package subdetect provides a test for the existence of a subgroup with enhanced treatment effect.
- Other approaches for personalized causal predictions are provided by EffectTreat (exploiting correlation-based expressions), and for randomized data by evalITR (it additionally allows for defining budget constraints) and by SortedEffects (estimation and inference methods for sorted causal effects and classification analysis).
- stepp provides diagnostic plots to explore treatment-covariate interactions for survival or generalized linear models, applicable for continuous, binomial and count data arising from two or more treatment arms of a clinical trial.
Policy learning and dynamic treatment regimes
- Estimation of an optimal dynamic treatment regime (DTR) is implemented in DynTxRegime (Q-Learning, Interactive Q-Learning, weighted learning, and value-search methods based on Augmented Inverse Probability Weighted Estimators and Inverse Probability Weighted Estimators), and iqLearn (archived) (interactive Q-learning); methods based on marginal quantile, marginal mean, and mean absolute difference are implemented in quantoptr as well as doubly-robust methods for quantile-optimal treatment regime). DTRreg proposes different methods such as G-estimation, dynamic weighted OLS and Q-learning, as well as several variance estimation approaches, it can handle survival outcomes and continuous treatment variables. QTOCen provides methods for estimation of mean- and quantile-optimal treatment regimes from censored data. ITRLearn implements maximin-projection learning for recommending a meaningful and reliable individualized treatment regime, and also Q-learning and A-learning for estimating the group-wise contrast function. simml and simsl offer Single-Index Models with Multiple-Links for, respectively, experimental and observational data.
- Estimation of DTR with variable selection is proposed by ITRLearn implements maximin-projection learning for recommending a meaningful and reliable individualized treatment regime, and also Q-learning and A-learning for estimating the group-wise contrast function. ITRSelect implements sequential advantage selection and penalized A-learning for selecting important variables in optimal individualized (dynamic) treatment regime in both single-stage or multi-stage studies. OTRselect implements a penalized regression method that can simultaneously estimate the optimal treatment strategy and identify important variables for either censored or uncensored continuous response. DTRlearn2 offers Q-learning and outcome-weighted learning methods with variable selection via penalization.
- For sequential, multiple assignment, randomized trials (SMART), smartsizer provides a set of tools for determining the necessary sample size in order to identify the optimal DTR; DTRlearn2 also implements estimators for general K-stage DTRs from SMARTs.
Structural equation models, do-calculus causal discovery
- Identifiability is addressed by causaleffect and dosearch providing algorithms to decide whether a causal effect is identifiable (non-parametric identifiability) and by CausalQueries that calculates arbitrary estimands for a given causal model. causaloptim provides tight bounds for a user defined DAG, query and constraints using a symbolic linear optimizer.
- Causal structure learning is possible with functions from pcalg: PC, for observational data without hidden variables, FCI and RFCI, for observational data with hidden variables, and GIES, for a mix of observational and interventional data without hidden variables; pcalg also allows to do causal inference using graphical models (the IDA algorithm, the Generalized Backdoor Criterion - GBC, the Generalized Adjustment Criterion - GAC). Incorporating background knowledge is also possible. Many algorithms and methods for general and specific graphical models exist, we refer to the GraphicalModels and Psychometrics CRAN Task Views for a comprehensive overview.
- Estimation of causal effects is possible in CIEE using estimating equations derived from a DAG and in InvariantCausalPrediction using adjustment sets derived from conditional independence tests that leverage causal invariances across environments.
- Causal networks estimation is implemented in CompareCausalNetworks.
- generalCorr computes generalized correlations, partial correlations and plausible causal paths.
In addition, dagitty provides methods to define different types of graphical models (cpdags, pdag, ect.) and to identify adjustment sets (a web-based graphical environment is also available: DAGitty).
Specific types of data
- Longitudinal data / time series and censored data: Causal effect estimation for time series is implemented in CausalImpact (using a Bayesian approach) and CausalMBSTS (for multivariate responses).
- GWAS and SNPs: CKAT implements kernel based methods to jointly test genetic main effect and gene-treatment interaction effects for a set of SNPs.
- Example data sets to run frequent example problems from causal inference textbooks are accessible through the causaldata package.
- Weighted, two-mode, and longitudinal networks analysis is implemented in tnet
Specific application fields
- Behavior change sciences use specialized analyses and visualization tools implemented in behaviorchange.
- Evaluation of biomarkers and estimation of treatment-biomarker effects can be done using tools from bhm (for biomarker-treatment effects).
- Qualitative Comparative Analysis type methods are implemented in cna.
- Mendelian randomization methods used to examine causal effects related to certain genes are implemented in MendelianRandomization, mr.raps (two-sample Mendelian randomization with summary statistics by using Robust Adjusted Profile Score), MRPC (PC algorithm with the principle of Mendelian Randomization).
- Causal inference approaches in genetic systems exploit quantitative trait loci (QTL) genotypes to infer causal relationships among phenotypes: functions to simultaneously infer causal graphs and genetic architecture (acyclic and cyclic) are implemented in qtlnet.
- tools4uplift uplift modeling aims at predicting the causal effect of an action such as a marketing campaign on a particular individual.
- estudy2 allows examining the impact of certain events on the stock valuation of companies through an event study methodology (with parametric and nonparametric tests).
- Coincidence analysis through configurational comparative methods is provided by cna.
CRAN packages
Core: | cobalt, dagitty, fixest, Matching, MatchIt, mediation, pcalg, PSweight, riskRegression, tmle, WeightIt. |
Regular: | AIPW, allestimates, alpaca, approxmatch, bacondecomp, bartCause, BCEE, bcf, BCHM, beanz, behaviorchange, bhm, blocksdesign, Boptbd, borrowr, bpbounds, BuyseTest, causaldata, causaleffect, CausalGAM, CausalGPS, CausalImpact, CausalMBSTS, causaloptim, CausalQueries, causalsens, causalweight, CBPS, cem, cfdecomp, cfma, CIEE, cit, cjoint, CKAT, clusteredinterference, cna, CompareCausalNetworks, confoundr, Counterfactual, ctmle, designmatch, did, DiPs, DirectEffects, dosearch, DoubleML, DRDID, drtmle, dstat, DTRlearn2, DTRreg, DynTxRegime, ebal, eefAnalytics, EffectLiteR, EffectTreat, endoSwitch, estimatr, estudy2, evalITR, EValue, experiment, FindIt, FLAME, generalCorr, gfoRmula, gma, grf, gsynth, hdm, icsw, idem, inferference, interflex, InvariantCausalPrediction, ipcwswitch, ITRLearn, ITRSelect, ivmodel, ivmte, ivreg, LARF, ltmle, maic, maicChecks, marginaleffects, margins, match2C, matchMulti, MatchThem, medflex, MedSurvey, MendelianRandomization, microsynth, modelbased, mr.raps, MRPC, MultisiteMediation, mvGPS, netchain, nonlinearICP, optmatch, optweight, OTRselect, OVtool, PanelMatch, paths, plm, preference, qtlnet, QTOCen, quantoptr, rcbalance, rcbsubset, rdrobust, regmedint, rpsftm, sampleSelection, sbw, seqDesign, simml, simsl, smartsizer, SortedEffects, SPORTSCausal, stdReg, stepp, stratamatch, subdetect, Synth, tableone, ThreeArmedTrials, tidysynth, tnet, tools4uplift, TrendInTrend, twang, twangContinuous, twangMediation, ui, WhatIf. |
Archived: | causaldrf, iqLearn, qte. |
Related links
Other resources