# Reweighting Estimators for the ATE

DML
causal
Author

Apoorva Lal

Published

August 10, 2022


#' weighted OLS (can handle negative weights)
OLSw = $$y, X, w) { XtWX = car::wcrossprod(X, w = w) XtWy = car::wcrossprod(X, y, w = w) solve(XtWX) %*% XtWy } #' IPW and AIPW #' @param y outcome vector #' @param w treatment dummy #' @param X1 matrix of covariates for propensity score #' @param X2 matrix of covariates in outcome model #' @param f family for propensity score drHT = \(y, w, X1, X2 = cbind(1, X1), f = binomial(), estimand = "ATE"){ # solve for pscore weights pihat = glm.fit(X1, w, family = f)fitted.values if(estimand == "ATE"){ wt = sqrt(w/pihat + (1-w)/(1-pihat)) } else if(estimand == "ATT"){ rho = mean(w) wt = sqrt( w + # all treat obs weighted as 1 ((1-w) * pihat) / (rho * (1-pihat) ) # control obs weights ) } if(is.null(X2)) X2 = matrix(rep(1, nrow(X1))) # run weighted regression OLSw(y, as.matrix(cbind(w, X2)), wt)[1,1] } ## Average Treatment Effect (ATE) To implement AIPW as a weighted regression, we fit $Y_i = \alpha + \tau W_i + X_i ' \beta + \epsilon_i$ with weights $\lambda_i = \sqrt{ \frac{W_i}{\pi(X_i)} + \frac{1-W_i}{1- \pi(X_i)} }$ data(lalonde.exp); data = setDT(lalonde.exp) yn = 're78'; wn = 'treat'; xn = setdiff(colnames(data), c(yn, wn)) y = data[[yn]]; w = data[[wn]]; X = data[, ..xn] drHT(y, w, X, X2 = NULL)  w 1674  drHT(y, w, X)  w 1642  ## inference using bootstrap bootf = \(d, i, yn, wn, xn){ y = d[[yn]][i]; w = d[[wn]][i]; X = as.matrix(d[i, ..xn]) c( # naive mean(y[w==1]) - mean(y[w==0]), # ipw drHT(y, w, X, X2 = NULL), # aipw drHT(y, w, X) ) } boot( lalonde.exp, bootf, yn = 're78', wn = 'treat', xn = setdiff(colnames(data), c(yn, wn)), R = 1000, parallel = "multicore", ncpus = 6 )  ORDINARY NONPARAMETRIC BOOTSTRAP Call: boot(data = lalonde.exp, statistic = bootf, R = 1000, yn = "re78", wn = "treat", xn = setdiff(colnames(data), c(yn, wn)), parallel = "multicore", ncpus = 6) Bootstrap Statistics : original bias std. error t1* 1794 -6.055 673.4 t2* 1674 -5.217 659.9 t3* 1642 -3.170 688.1 ## Average Treatment effect on the Treated (ATT ) Next, we give all treatment units weights of 1 and control units receive weights $\lambda_i = \sqrt{ \frac{\pi(\vee{X}_i)}{\rho} \frac{1 - W_i}{1 - \pi(\vee{X}_i)} }$ where \(\rho = \Prob{W_i = 1}$$.

data(lalonde.psid); data = setDT(lalonde.psid)
yn = 're78'; wn = 'treat'; xn = setdiff(colnames(data), c(yn, wn))
y = data[[yn]]; w = data[[wn]]; X = data[, ..xn]

drHT(y, w, X, estimand = "ATT")
   w
1958