Coding Causal Inference in R
This notebook contains R code for part 2 of Causal Inference by Miguel Hernán and Jamie Robins (1). While R, SAS, Stata, and Python code are available on the website for Causal Inference, we focus on doing causal inference using the tidyverse ecosystem of R packages, particularly ggplot2, dplyr, and broom.
This notebook is hosted on GitHub; please post any issues or suggestions there.
The data used in this notebook can be downloaded from the Causal Inference website, as well as on the GitHub repository. Alternatively, cleaned versions of the data are available in the
cidata package, which you can install from GitHub:
# if you don't have the remotes package: # install.packages("remotes") remotes::install_github("malcolmbarrett/cidata")
1. Hernán MA, Robins JM. Causal Inference. Boca Raton: Chapman Hall/CRC; 2019.