# Average Treatment Effects

#### Klaus Kähler Holst

#### 2022-10-25

# Introduction

Let \(Y\) be a binary response, \(A\) a categorical treatment, and \(W\) a vector of confounders. Assume that we have observed \(n\) i.i.d. observations \((Y_i, W_i, A_i) \sim P, i=1,\ldots,n\). In the following we are interested in estimating the target parameter \(\psi(P) = (E[Y(a)]\), where \(Y(a)\) is the potential outcome we would have observed if treatment \(a\) had been administered, possibly contrary to the actual treatment that was observed, i.e., \(Y = Y(A)\).

Under the following assumptions

1. Stable Unit Treatment Values Assumption (the treatment of a specific subject is not affecting the potential outcome of other subjects)
2. Positivity, \(P(A\mid W)>\epsilon\) for some \(\epsilon>0.\)
3. No unmeasured confounders, \(Y(a)\perp \!\!\! \perp A|W\)

the target parameter can be identified from the observed data distribution as \[E(E[Y|W,A=a]) = E(E[Y(a)|W]) = E[Y(a)]\] or \[E[Y I(A=a)/P(A=a|W)] = E[Y(a)].\]

This suggests estimation via either outcome regression (OR, g-computation) or inverse probability weighting (IPW). These can eventually also be combined to a doubly-robust augmented inverse probability weighted (AIPW) estimator.

# Simulation

As an illustration we simulate from the following model \[Y \sim Bernoulli(\operatorname{expit}\{A+X+Z\})\] \[A \sim Bernoulli(\operatorname{expit}\{X+Z\})\] \[Z \sim \mathcal{N}(X,1)\]

    m <- lvm(Y ~ A+X+Z, A~X+Z, Z~X)
    m <- distribution(m, ~A+Y, binomial.lvm())
    d <- sim(m, 1e3, seed=1)
    head(d)
    #>   Y A          X          Z
    #> 1 0 0 -0.6264538  0.5085113
    #> 2 1 1  0.1836433  1.2955752
    #> 3 0 0 -0.8356286 -1.7064062
    #> 4 1 1  1.5952808  1.8060124
    #> 5 1 0  0.3295078  0.3989034
    #> 6 0 0 -0.8204684 -2.4831172

# Estimation

The target parameter, \(E[Y(a)]\) can be estimated with the `targeted::ate` function:

    args(ate)
    #> function (formula, data = parent.frame(), weights, binary = TRUE,
    #>     nuisance = NULL, propensity = nuisance, all, missing = FALSE,
    #>     labels = NULL, ...)
    #> NULL

The formula should be specified as `formula = response ~ treatment`, and the outcome regression specified as `nuisance = ~ covariates`, and propensity model `propensity = ~ covariates`. Alternatively, the formula can be specified with the notation `formula = response ~ treatment | OR-covariates | propensity-covariates`. Parametric models are assumed for both the outcome regression and the propensity model which defaults to be logistic regression models (as in the simulation). A linear model can be used for the outcome regression part by setting `binary=FALSE`.

To illustrate this, we can estimate the (non-causal) marginal mean of each treatment value

    ate(Y ~ A, data=d, nuisance=~1, propensity=~1)
    #>     Estimate Std.Err   2.5%  97.5%   P-value
    #> A=0   0.2937 0.02029 0.2539 0.3334 1.741e-47
    #> A=1   0.8367 0.01660 0.8042 0.8692 0.000e+00

or equivalently

    ate(Y ~ A | 1 | 1, data=d)
    #>     Estimate Std.Err   2.5%  97.5%   P-value
    #> A=0   0.2937 0.02029 0.2539 0.3334 1.741e-47
    #> A=1   0.8367 0.01660 0.8042 0.8692 0.000e+00

In this simulation we can compare the estimates to the actual expected potential outcomes which can be approximated by Monte Carlo integration by simulating from the model where we intervene on \(A\) (i.e., break the dependence on \(X, Z\)):

    mean(sim(intervention(m, "A", 0), 2e5)$Y)
    #> [1] 0.50041
    mean(sim(intervention(m, "A", 1), 2e5)$Y)
    #> [1] 0.64086

The IPW estimator can then be estimated

    ate(Y ~ A | 1 | X+Z, data=d)
    #>     Estimate Std.Err   2.5%  97.5%   P-value
    #> A=0   0.4793 0.02678 0.4268 0.5318 1.278e-71
    #> A=1   0.6669 0.03263 0.6029 0.7308 7.528e-93

Similarly, the OR estimator is obtained by

    ate(Y ~ A | A*(X+Z) | 1, data=d)
    #>     Estimate Std.Err   2.5%  97.5%    P-value
    #> A=0   0.5115 0.02106 0.4703 0.5528 2.367e-130
    #> A=1   0.6585 0.02518 0.6092 0.7079 1.008e-150

Both estimates are in this case consistent though we can see that the OR estimate is much more efficient compared to the IPW estimator. However, both of these models rely on correct model specifications.

    ate(Y ~ A | 1 | X, data=d)
    #>     Estimate Std.Err   2.5%  97.5%   P-value
    #> A=0   0.4208 0.02706 0.3678 0.4739 1.543e-54
    #> A=1   0.7072 0.03366 0.6412 0.7731 5.204e-98

    ate(Y ~ A | A*X | 1, data=d)
    #>     Estimate Std.Err   2.5%  97.5%   P-value
    #> A=0   0.4413 0.02395 0.3944 0.4882  7.88e-76
    #> A=1   0.7084 0.02491 0.6596 0.7572 5.84e-178

In contrast, the doubly-robust AIPW estimator is consistent in the intersection model where either the propensity model or the outcome regression model is correctly specified

    a <- ate(Y ~ A | A*X | X+Z, data=d)
    summary(a)
    #>
    #> Augmented Inverse Probability Weighting estimator
    #>   Response Y (Outcome model: logistic regression):
    #>   Y ~ A * X
    #>   Exposure A (Propensity model: logistic regression):
    #>   A ~ X + Z
    #>
    #>                    Estimate Std.Err    2.5%    97.5%    P-value
    #>  A=0               0.493714 0.02451  0.4457  0.54175  3.039e-90
    #>  A=1               0.654050 0.02839  0.5984  0.70970 1.995e-117
    #> Outcome model:
    #>  (Intercept)      -0.320268 0.12263 -0.5606 -0.07991  9.012e-03
    #>  A                 1.578135 0.18083  1.2237  1.93255  2.609e-18
    #>  X                 1.464900 0.15842  1.1544  1.77539  2.305e-20
    #>  A:X              -0.010495 0.25101 -0.5025  0.48147  9.666e-01
    #> Propensity model:
    #>  (Intercept)      -0.006421 0.08337 -0.1698  0.15699  9.386e-01
    #>  X                -0.863004 0.12123 -1.1006 -0.62539  1.091e-12
    #>  Z                -1.005211 0.09080 -1.1832 -0.82725  1.742e-28
    #>
    #> Average Treatment Effect (constrast: 'A=0' vs. 'A=1'):
    #>
    #>    Estimate Std.Err    2.5%    97.5%   P-value
    #> RR   0.7549 0.04536  0.6659  0.84377 3.578e-62
    #> OR   0.5158 0.07501  0.3688  0.66282 6.150e-12
    #> RD  -0.1603 0.03419 -0.2273 -0.09333 2.732e-06

From the `summary` output we also get the estimates of the Average Treatment Effects expressed as a causal relative risk (RR), causal odds ratio (OR), or causal risk difference (RD) including the confidence limits.

From the model object `a` we can extract the estimated coefficients (expected potential outcomes) and corresponding asympotic variance matrix with the `coef` and `vcov` methods. The estimated influence function can extracted with the `iid` method:

    coef(a)
    #>       A=0       A=1
    #> 0.4937138 0.6540498
    vcov(a)
    #>              A=0          A=1
    #> A=0 0.0006007034 0.0001190188
    #> A=1 0.0001190188 0.0008060789
    head(iid(a))
    #>                A=0           A=1
    #> [1,] -0.0011525278 -6.835682e-05
    #> [2,]  0.0002149985  2.750537e-04
    #> [3,] -0.0004591691 -2.792536e-04
    #> [4,]  0.0004331270  2.878354e-04
    #> [5,]  0.0011762997  1.537040e-04
    #> [6,] -0.0004537058 -2.268427e-04

# Multiple treatments

As an example with multiple treatment levels, we simulate from a new model where the outcome is continuous and the treatment follows a proportional odds model

    m <- lvm(y ~ a+x, a~x)
    m <- ordinal(m, K=4, ~a)
    d <- transform(sim(m, 1e4), a=factor(a))

The AIPW estimator is obtained by estimating a logistic regression model for each treatment level (vs all others) in the propensity model (here a correct model is specified for both the OR and IPW part)

    summary(a2 <- ate(y ~ a | a*x | x, data=d, binary=FALSE))
    #>
    #> Augmented Inverse Probability Weighting estimator
    #>   Response y (Outcome model: linear regression):
    #>   y ~ a * x
    #>   Exposure a (Propensity model: logistic regression):
    #>   a ~ x
    #>
    #>     Estimate Std.Err    2.5%   97.5%    P-value
    #> a=0  -1.5286 0.04916 -1.6249 -1.4322 2.897e-212
    #> a=1  -0.7485 0.04081 -0.8285 -0.6685  3.860e-75
    #> a=2  -0.4807 0.03466 -0.5487 -0.4128  9.809e-44
    #> a=3   0.7347 0.02485  0.6860  0.7834 4.215e-192
    #>
    #> Average Treatment Effect (constrast: 'a=0' vs. 'a=1'):
    #>
    #>     Estimate Std.Err    2.5%   97.5%   P-value
    #> ATE  -0.7801 0.06186 -0.9013 -0.6588 1.861e-36

Choosing a different contrast for the association measures:

    summary(a2, contrast=c(2,4))
    #>
    #> Augmented Inverse Probability Weighting estimator
    #>   Response y (Outcome model: linear regression):
    #>   y ~ a * x
    #>   Exposure a (Propensity model: logistic regression):
    #>   a ~ x
    #>
    #>     Estimate Std.Err    2.5%   97.5%    P-value
    #> a=0  -1.5286 0.04916 -1.6249 -1.4322 2.897e-212
    #> a=1  -0.7485 0.04081 -0.8285 -0.6685  3.860e-75
    #> a=2  -0.4807 0.03466 -0.5487 -0.4128  9.809e-44
    #> a=3   0.7347 0.02485  0.6860  0.7834 4.215e-192
    #>
    #> Average Treatment Effect (constrast: 'a=1' vs. 'a=3'):
    #>
    #>     Estimate Std.Err  2.5%  97.5%    P-value
    #> ATE   -1.483 0.04444 -1.57 -1.396 3.377e-244

    head(iid(a2))
    #>                a=0           a=1           a=2           a=3
    #> [1,]  7.897763e-05  6.845513e-05  6.227447e-05  3.219971e-04
    #> [2,] -6.360456e-06  1.021727e-05  9.233976e-06  9.015700e-05
    #> [3,] -2.487285e-05  2.128963e-03 -3.021000e-06  2.960775e-06
    #> [4,]  5.614968e-04 -3.005561e-07 -3.408670e-07  5.813109e-06
    #> [5,] -7.527159e-05 -6.812752e-05 -6.205039e-05 -7.666685e-05
    #> [6,] -5.056668e-05 -2.339970e-05 -2.136395e-05  6.399821e-04
    estimate(a2, function(x) x[2]-x[4])
    #>     Estimate Std.Err  2.5%  97.5%    P-value
    #> a=1   -1.483 0.04444 -1.57 -1.396 3.377e-244

# SessionInfo

    sessionInfo()
    #> R version 4.2.1 (2022-06-23)
    #> Platform: aarch64-apple-darwin21.6.0 (64-bit)
    #> Running under: macOS Monterey 12.6
    #>
    #> Matrix products: default
    #> BLAS:   /Users/Klaus.Holst/.asdf/installs/R/4.2.1/lib/R/lib/libRblas.dylib
    #> LAPACK: /Users/Klaus.Holst/.asdf/installs/R/4.2.1/lib/R/lib/libRlapack.dylib
    #>
    #> locale:
    #> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    #>
    #> attached base packages:
    #> [1] stats     graphics  grDevices utils     datasets  methods   base
    #>
    #> other attached packages:
    #> [1] targeted_0.3 lava_1.7.0
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] Rcpp_1.0.9           bslib_0.4.0          compiler_4.2.1
    #>  [4] formatR_1.12         jquerylib_0.1.4      futile.logger_1.4.3
    #>  [7] mets_1.3.1           futile.options_1.0.1 tools_4.2.1
    #> [10] digest_0.6.30        jsonlite_1.8.3       evaluate_0.17
    #> [13] lattice_0.20-45      rlang_1.0.6          Matrix_1.5-1
    #> [16] cli_3.4.1            yaml_2.3.6           parallel_4.2.1
    #> [19] mvtnorm_1.1-3        xfun_0.34            fastmap_1.1.0
    #> [22] stringr_1.4.1        knitr_1.40           sass_0.4.2
    #> [25] globals_0.16.1       grid_4.2.1           data.table_1.14.4
    #> [28] listenv_0.8.0        R6_2.5.1             timereg_2.0.2
    #> [31] future.apply_1.9.1   parallelly_1.32.1    survival_3.3-1
    #> [34] rmarkdown_2.17       lambda.r_1.2.4       magrittr_2.0.3
    #> [37] codetools_0.2-18     htmltools_0.5.3      splines_4.2.1
    #> [40] future_1.28.0        numDeriv_2016.8-1.1  optimx_2022-4.30
    #> [43] stringi_1.7.8        cachem_1.0.6