Skip to contents

Simplified version of `ateGT` with no selection indicator. Imputes counterfactual outcome for each observation i under each treament a as $$Y^a = \frac{A = a}{\pi^a (X)} (Y - \mu^a(X)) + \mu^a(X) $$ Average treatment effects are defined as averages of differences between counterfactual outcomes \(Y^a - Y^{a'}\). and returns marginal means, causal contrasts, and their influence-function based variance estimates. Uses same underlying nuisance function fitter as `ateGT` with no missing data or surrogates.

Usage

aipw(
  y,
  a,
  X,
  treatProb = NULL,
  nuisMod = c("rlm", "rf"),
  estimator = c("AIPW", "IPW", "OM"),
  hajekize = FALSE,
  separateMus = TRUE,
  glmnet_lamchoice = "lambda.min",
  glmnet_alpha = 1,
  glmnet_rho_family = "binomial",
  glmnet_pi_family = "binomial",
  glmnet_mu_family = "gaussian",
  glmnet_parl = FALSE,
  grf_tunerf = "none",
  noi = FALSE
)

Arguments

y

outcome vector (may contain missings ; missings must correspond with s = 0)

a

treatment vector (no missings; can be relaxed with some tinkering)

X

covariate matrix (no missings)

treatProb

propensity score vector (of length n_treatment) or matrix (n_treatment X n_obs), where latter is for covariate adaptive designs; must sum to 1. NULL by default, so pscore is fitted. When provided, no propensity score is fit. With discrete covariates, estimated propensity score is advisable even if treatment was randomized.

nuisMod

one of c("rlm", "rf") : choose how to fit nuisance functions (cross-fit).

estimator

one of c("AIPW", "IPW", "OM"). The default is AIPW.

hajekize

boolean for whether to divide the inverse probability weights term for each treatment level by the sum of weights in that treatment level. This guards against instability from very large weights from extremely small selection or propensity scores.

separateMus

boolean for whether to fit separate outcome models for each treatment group or a single pooled model. The former is recommended and is the default, but a pooled model may be fit when data is scarce / computation is burdensome.

glmnet_lamchoice

choice of lambda (shrinkage parameter) for regularized linear regressions. Only relevant when nuisMod == "rlm"

glmnet_alpha

in [0, 1], choice of alpha in glmnet. 1 (default) corresponds with L1 regularization (LASSO) and 0 corresponds with L2 regularization (ridge), while intermediate values correspond with a mix of the two (elastic net)

glmnet_rho_family

GLM family for selection model. "binomial" by default but can be safely switched to "gaussian" for linear probability models with discrete covariates for faster compute

glmnet_pi_family

GLM family for propensity model. "binomial" by default but can be safely switched to "gaussian" for linear probability models with discrete covariates for faster compute

glmnet_mu_family

GLM family for outcome model. Gaussian by default.

glmnet_parl

Boolean for parallelization in glmnet. Need to enable parallelized cluster beforehand.

grf_tunerf

Tune rf hyperparameters? Passed to grf's regression forest. Use 'all' for hyperparameter tuning.

noi

boolean for printing marginal means and causal contrasts table (it gets returned anyway). off by default.

Value

list containing treatment effects table , nuisance function estimates, and influence function values

Examples

# simulation with no selection bias (generate by passing null function for selection)
df2 = selDGP(selF = NULL)
df2$tau |> mean() # true effect : sinh(1)
#> [1] 1.169659
# lasso
aipw(df2$y, df2$a, df2$X, noi = FALSE, nuisMod = "rlm")$res
#>      parameter       est         se     ci.ll    ci.ul pval
#> 1      E{Y(0)} 0.9710327 0.04317201 0.8864155 1.055650    0
#> 2      E{Y(1)} 2.1088107 0.03670052 2.0368777 2.180744    0
#> 3 E{Y(1)-Y(0)} 1.1377780 0.03381391 1.0715028 1.204053    0
# random forest
aipw(df2$y, df2$a, df2$X, noi = FALSE, nuisMod = "rf")$res
#>      parameter       est         se     ci.ll    ci.ul pval
#> 1      E{Y(0)} 0.9748945 0.04119507 0.8941522 1.055637    0
#> 2      E{Y(1)} 2.1053377 0.03629204 2.0342053 2.176470    0
#> 3 E{Y(1)-Y(0)} 1.1304432 0.02800378 1.0755558 1.185331    0