Let be a binary response, a categorical treatment, and a vector of confounders. Assume that we have observed i.i.d. observations . In the following we are interested in estimating the target parameter , where is the potential outcome we would have observed if treatment had been administered, possibly contrary to the actual treatment that was observed, i.e., .
Under the following assumptions
the target parameter can be identified from the observed data distribution as or
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.
As an illustration we simulate from the following model
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
The target parameter, can be estimated with the targeted::ate
function:
args(ate)
#> function (formula, data = parent.frame(), weights, offset, family = stats::gaussian(identity),
#> nuisance = NULL, propensity = nuisance, all, 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 (i.e., break the dependence on ):
mean(sim(intervention(m, "A", 0), 2e5)$Y)
#> [1] 0.50034
mean(sim(intervention(m, "A", 1), 2e5)$Y)
#> [1] 0.63689
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.4858 0.02796 0.4310 0.5406 1.243e-67
#> A=1 0.7213 0.02600 0.6703 0.7723 2.248e-169
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.4240 0.02617 0.3727 0.4752 4.794e-59
#> A=1 0.7474 0.02411 0.7001 0.7946 5.297e-211
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: gaussian):
#> Y ~ A * X
#> Exposure A (Propensity model: logistic regression):
#> A ~ X + Z
#>
#> Estimate Std.Err 2.5% 97.5% P-value
#> A=0 0.492322 0.02609 0.4412 0.54346 2.028e-79
#> A=1 0.663735 0.03068 0.6036 0.72386 8.429e-104
#> Outcome model:
#> (Intercept) 0.426675 0.02498 0.3777 0.47563 2.048e-65
#> A 0.322545 0.03399 0.2559 0.38916 2.303e-21
#> X 0.232605 0.01825 0.1968 0.26837 3.266e-37
#> A:X -0.075738 0.02609 -0.1269 -0.02461 3.693e-03
#> 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=1' - 'A=0'):
#>
#> Estimate Std.Err 2.5% 97.5% P-value
#> ATE 0.1714 0.03661 0.09967 0.2432 2.831e-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.4923220 0.6637346
vcov(a)
#> A=0 A=1
#> A=0 0.0006807275 0.0001409887
#> A=1 0.0001409887 0.0009411920
head(iid(a))
#> A=0 A=1
#> 1 -0.0012182867 -0.0002821609
#> 2 0.0002438822 0.0002898771
#> 3 -0.0004583641 -0.0002555994
#> 4 0.0003753253 0.0002567340
#> 5 0.0011971267 0.0001267515
#> 6 -0.0004585485 -0.0001710518
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
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: gaussian):
#> y ~ a * x
#> Exposure a (Propensity model: logistic regression):
#> a ~ x
#>
#> Estimate Std.Err 2.5% 97.5% P-value
#> a=0 -1.5792 0.03928 -1.6562 -1.5022 0.000e+00
#> a=1 -0.7682 0.04115 -0.8489 -0.6876 8.723e-78
#> a=2 -0.4171 0.03548 -0.4866 -0.3475 6.582e-32
#> a=3 0.7470 0.02424 0.6995 0.7945 1.340e-208
#>
#> Average Treatment Effect (constrast: 'a=1' - 'a=0'):
#>
#> Estimate Std.Err 2.5% 97.5% P-value
#> ATE 0.811 0.05461 0.7039 0.918 7.044e-50
Choosing a different contrast for the association measures:
summary(a2, contrast=c(2,4))
#>
#> Augmented Inverse Probability Weighting estimator
#> Response y (Outcome model: gaussian):
#> y ~ a * x
#> Exposure a (Propensity model: logistic regression):
#> a ~ x
#>
#> Estimate Std.Err 2.5% 97.5% P-value
#> a=0 -1.5792 0.03928 -1.6562 -1.5022 0.000e+00
#> a=1 -0.7682 0.04115 -0.8489 -0.6876 8.723e-78
#> a=2 -0.4171 0.03548 -0.4866 -0.3475 6.582e-32
#> a=3 0.7470 0.02424 0.6995 0.7945 1.340e-208
#>
#> Average Treatment Effect (constrast: 'a=1' - 'a=3'):
#>
#> Estimate Std.Err 2.5% 97.5% P-value
#> ATE -1.515 0.04424 -1.602 -1.429 3.985e-257
head(iid(a2))
#> a=0 a=1 a=2 a=3
#> 1 -6.051178e-04 3.348572e-05 3.188711e-05 4.116160e-05
#> 2 -9.227453e-05 2.809195e-04 -6.091591e-05 -7.910553e-05
#> 3 1.554332e-04 1.229831e-04 1.160951e-04 2.360075e-04
#> 4 4.581986e-05 4.615912e-05 -3.669610e-04 5.317770e-05
#> 5 -3.005632e-04 -2.050601e-04 -1.952828e-04 -3.077626e-04
#> 6 1.699202e-04 1.334874e-04 1.259713e-04 1.760130e-04
estimate(a2, function(x) x[2]-x[4])
#> Estimate Std.Err 2.5% 97.5% P-value
#> a=1 -1.515 0.04424 -1.602 -1.429 3.985e-257
sessionInfo()
#> R version 4.4.1 (2024-06-14)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 22.04.5 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0
#>
#> locale:
#> [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
#> [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
#> [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
#> [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] targeted_0.6 lava_1.8.0
#>
#> loaded via a namespace (and not attached):
#> [1] Matrix_1.7-0 future.apply_1.11.2 jsonlite_1.8.9
#> [4] futile.logger_1.4.3 compiler_4.4.1 Rcpp_1.0.13
#> [7] parallel_4.4.1 jquerylib_0.1.4 globals_0.16.3
#> [10] splines_4.4.1 systemfonts_1.1.0 textshaping_0.4.0
#> [13] yaml_2.3.10 fastmap_1.2.0 lattice_0.22-6
#> [16] R6_2.5.1 knitr_1.48 future_1.34.0
#> [19] nloptr_2.1.1 desc_1.4.3 bslib_0.8.0
#> [22] rlang_1.1.4 cachem_1.1.0 xfun_0.48
#> [25] fs_1.6.4 sass_0.4.9 cli_3.6.3
#> [28] pkgdown_2.1.1 formatR_1.14 futile.options_1.0.1
#> [31] digest_0.6.37 grid_4.4.1 mvtnorm_1.3-1
#> [34] lifecycle_1.0.4 timereg_2.0.6 pracma_2.4.4
#> [37] evaluate_1.0.0 data.table_1.16.0 numDeriv_2016.8-1.1
#> [40] lambda.r_1.2.4 listenv_0.9.1 codetools_0.2-20
#> [43] ragg_1.3.3 optimx_2023-10.21 survival_3.6-4
#> [46] parallelly_1.38.0 rmarkdown_2.28 mets_1.3.4
#> [49] tools_4.4.1 htmltools_0.5.8.1