## 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)
#>   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) #>  0.499995 mean(sim(intervention(m, "A", 1), 2e5)$Y)
#>  0.63757

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
#>                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.6161 0.04079 -1.6960 -1.5361  0.000e+00
#> a=1  -0.7665 0.04009 -0.8451 -0.6880  1.755e-81
#> a=2  -0.4574 0.03337 -0.5228 -0.3920  9.351e-43
#> a=3   0.7570 0.02584  0.7063  0.8076 1.234e-188
#>
#> Average Treatment Effect (constrast: 'a=0' vs. 'a=1'):
#>
#>     Estimate Std.Err    2.5%   97.5%  P-value
#> ATE  -0.8496 0.05494 -0.9572 -0.7419 6.16e-54

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.6161 0.04079 -1.6960 -1.5361  0.000e+00
#> a=1  -0.7665 0.04009 -0.8451 -0.6880  1.755e-81
#> a=2  -0.4574 0.03337 -0.5228 -0.3920  9.351e-43
#> a=3   0.7570 0.02584  0.7063  0.8076 1.234e-188
#>
#> Average Treatment Effect (constrast: 'a=1' vs. 'a=3'):
#>
#>     Estimate Std.Err   2.5%  97.5%    P-value
#> ATE   -1.524  0.0445 -1.611 -1.436 7.837e-257
head(iid(a2))
#>                a=0           a=1           a=2           a=3
#> [1,]  1.811492e-04  1.351556e-04  1.332927e-04  1.401916e-04
#> [2,] -1.099388e-04 -8.534005e-05 -8.417548e-05  1.994063e-05
#> [3,] -5.574835e-04 -6.362948e-05 -6.269639e-05 -6.811459e-05
#> [4,] -3.626775e-05 -1.773685e-05 -1.581719e-03 -8.595930e-06
#> [5,] -4.962439e-05 -2.783677e-05 -2.732798e-05 -4.338660e-04
#> [6,]  3.508889e-05  3.259422e-05 -3.411864e-04  2.944555e-05
estimate(a2, function(x) x-x)
#>     Estimate Std.Err   2.5%  97.5%    P-value
#> a=1   -1.524  0.0445 -1.611 -1.436 7.837e-257

## SessionInfo

sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.1 LTS
#>
#> Matrix products: default
#>
#> locale:
#>   LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8
#>   LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8
#>  LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#>  stats     graphics  grDevices utils     datasets  methods   base
#>
#> other attached packages:
#>  targeted_0.4 lava_1.7.0
#>
#> loaded via a namespace (and not attached):
#>   Rcpp_1.0.9           formatR_1.13         futile.logger_1.4.3
#>   bslib_0.4.2          compiler_4.2.2       jquerylib_0.1.4
#>   mets_1.3.1           futile.options_1.0.1 tools_4.2.2
#>  digest_0.6.31        lattice_0.20-45      jsonlite_1.8.4
#>  evaluate_0.19        memoise_2.0.1        lifecycle_1.0.3
#>  rlang_1.0.6          Matrix_1.5-1         cli_3.5.0
#>  yaml_2.3.6           parallel_4.2.2       mvtnorm_1.1-3
#>  pkgdown_2.0.7        xfun_0.36            fastmap_1.1.0
#>  stringr_1.5.0        knitr_1.41           desc_1.4.2
#>  fs_1.5.2             vctrs_0.5.1          sass_0.4.4
#>  systemfonts_1.0.4    globals_0.16.2       grid_4.2.2
#>  rprojroot_2.0.3      data.table_1.14.6    glue_1.6.2
#>  listenv_0.9.0        R6_2.5.1             timereg_2.0.4
#>  textshaping_0.3.6    future.apply_1.10.0  parallelly_1.33.0
#>  survival_3.4-0       rmarkdown_2.19       lambda.r_1.2.4
#>  purrr_1.0.0          magrittr_2.0.3       codetools_0.2-18
#>  htmltools_0.5.4      splines_4.2.2        future_1.30.0
#>  numDeriv_2016.8-1.1  ragg_1.2.4           optimx_2022-4.30
#>  stringi_1.7.8        cachem_1.0.6