1  Get Started

1.1 Installation

To install interflex from CRAN, run the code chunk below:

install.packages("interflex")

We recommend users to install the most up-to-date, stable version of interflex from GitHub using:

devtools::install_github("xuyiqing/interflex")

We fix bugs in the dev branch before merging into the main branch; therefore, it is often more up to date.

devtools::install_github("xuyiqing/interflex@dev")

After installation, check interflex version to make sure the package is up-to-date.

installed.packages()["interflex", "Version"]
#> [1] "1.4.0"

interflex depends on the following packages, which should be installed automatically when interflex is being installed. You can also install them manually.

install_all <- function(packages) {
  installed_pkgs <- installed.packages()[, "Package"]
  for (pkg in packages) {
    if (!pkg %in% installed_pkgs) {
      install.packages(pkg)
    }
  }
}
packages <- c("Rcpp", "RcppArmadillo", "ggplot2", "sandwich", "Lmoments",
              "doParallel", "foreach", "mgcv", "lfe", "gridExtra", "grid",
              "ggplotify", "fixest", "RColorBrewer", "pcse", "gtable",
              "MASS", "mvtnorm", "pROC", "ModelMetrics", "lmtest", "AER",
              "future", "glmnet", "grf", "DoubleML", "mlr3", "mlr3learners", 
              "data.table", "paradox", "ranger", "xgboost")
install_all(packages)
Notexgboost and mlr3 compatibility

The DML estimator’s histogram-based gradient boosting option (model.y = "hgb") requires xgboost. Starting with xgboost ≥ 3.0, you need mlr3 ≥ 1.6.0 and mlr3learners ≥ 0.14.0. If you encounter an error like ALTLIST classes must provide a Set_elt method, update both:

install.packages(c("mlr3", "mlr3learners"))

To use additional dml estimators, interflex suggests the additional mlr3extralearners package, which is not on CRAN but can be installed from GitHub:

devtools::install_github("mlr-org/mlr3extralearners")

1.2 Datasets

The interflex package incorporates several datasets, all accessible via data():

library(interflex)
#> ## Major upgrade since v.1.3.0
#> ## See http://bit.ly/interflex for more info
#> ## Comments and suggestions -> yiqingxu@stanford.edu
data(interflex)
ls()
#>  [1] "app_adiguzel2023" "app_bb2024"       "app_et2023"       "app_hma2015"     
#>  [5] "app_vernby2013"   "s1"               "s2"               "s3"              
#>  [9] "s4"               "s5"               "s6"               "s7"              
#> [13] "s8"               "s9"

1.2.1 Simulation datasets

  • s1: Dichotomous treatment, linear CME. Used in Chapter 3 (fixed effects, multiple arms, predictions, treatment effect differences).
  • s2: Continuous treatment, linear CME. Used in Chapter 3.
  • s3: Dichotomous treatment, nonlinear (quadratic) CME. Used in Chapter 3.
  • s4: Dichotomous treatment, nonlinear CME with two-way fixed effects. Used in Chapter 3 (fixed effects demos).
  • s5: Discrete treatment (3 arms: A, B, C), nonlinear CME. Used in Chapter 3 (multiple treatment arms, predictions, treatment effect differences).
  • s6s9: Discrete outcome (binary \(Y\)) simulation datasets with various DGPs. Used in Chapter 6.

1.2.2 Empirical datasets

  • app_hma2015: Data from Huddy et al. (2015). Binary treatment, continuous moderator. Used in Chapter 2 (binary treatment demos).
  • app_vernby2013: Data from Vernby (2013). Continuous treatment, continuous moderator. Used in Chapter 2 (continuous treatment demos).
  • app_adiguzel2023: Data from Adiguzel et al. (2023). Continuous treatment (change in clinic congestion), continuous moderator (log property value). Used in Chapter 2, Chapter 4, and Chapter 5 (continuous treatment demos).
  • app_bb2024: Data from Beiser-McGrath and Bernauer (2024). Binary treatment, discrete moderator (income categories). Used in Chapter 3 (GATE with discrete moderator).
  • app_et2023: Data from Egerod and Tran (2023). Binary treatment, continuous moderator. Used in Chapter 6.