knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(IVaps)

The IVaps package is an implementation of the method of Approximate Propensity Scores for treatment effect estimation introduced by Narita 2020. On a high level, this method exploits a common quality across most algorithms -- that their outputs are based entirely on observable input variables. These outputs can therefore in theory be used to estimate the causal effects of past decisions that were mediated by such algorithms. Narita 2020 propose to estimate a 2SLS system of the following form: \begin{align} D_i &= \gamma_0 + \gamma_1 Z_i + \gamma_2 p^s(X_i;\delta) + v_i \ Y_i &= \beta_0 + \beta_1 D_i + \beta_2 p^s(X_i;\delta) + \epsilon_i \end{align} where $Z_i$ is a dummy for treatment recommendation (by the algorithm), and is used to instrument for $D_i$, a dummy for realized treatment. $p^s(X_i;\delta)$ is the estimated Approximate Propensity Score for algorithm inputs $X_i$ and bandwidth $\delta$. $Y_i$ is the outcome variable of interest.

IVaps provides functions for the two primary steps of this causal estimation: Approximate Propensity Score (APS) estimation and instrumental variables estimation. These functions should be compatible with all of the major machine-learning libraries in R.

Package Quickstart

Applying the package within your workflow to estimate treatment effects is fairly straightforward, and requires just two function calls -- estimate_aps() and estimate_treatment_effect.

aps <- estimate_aps(data, algorithm_object, ml_type="library of algorithm object", Xc=c("vector", "of", "continuous", "variable", "names"), Xd=c("vector", "of", "discrete", "variable", "names"))
ivreg_model <- estimate_treatment_effect(aps = aps, Y = outcome_vector, Z=treatment_reccomendation, D = treatment_assignment)
summary(ivreg_model)

estimate_aps() has support for parallelized estimation, mixed variables with some discrete values, input variable inference, and seeding.

L <- list("varname1" = c(discrete, values), "varname2" = c(discrete, values))
aps <- estimate_aps(data, algorithm_object, ml_type="library of algorithm object", infer=T, L = L, parallel = T, seed=1)

Value estimation of a counterfactual algorithm is also possible through a one-line call.

output <- estimate_counterfactual_ml(Y=outcome_vector, Z=treatment_recommendation,ML=original_algo_output, ML_new=counterfactual_algo_output)

The IVaps package also offers a covariate balance test diagnostic.

mlm <- covariate_balance_test(aps = aps, X = algo_inputs, Z = treatment_recommendation)


factoryofthesun/r-IVaps documentation built on Dec. 20, 2021, 7:41 a.m.