This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
generated from tlverse/tlverse-workshops
-
Notifications
You must be signed in to change notification settings - Fork 1
/
09-tmle3mopttx.Rmd
1413 lines (932 loc) · 34.8 KB
/
09-tmle3mopttx.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# (PART) Part 4: Advanced Topics {-}
# Optimal Individualized Treatment Regimes
_Ivana Malenica_
Based on the [`tmle3mopttx` `R` package](https://github.com/tlverse/tmle3mopttx)
by _Ivana Malenica, Jeremy Coyle, and Mark van der Laan_.
Updated: `r Sys.Date()`
## Learning Objectives
By the end of this lesson you will be able to:
1. Differentiate dynamic and optimal dynamic treatment interventions from static
interventions.
2. Explain the benefits, and challenges, associated with using optimal
individualized treatment regimes in practice.
3. Contrast the impact of implementing an optimal individualized treatment
regime in the population with the impact of implementing static and dynamic
treatment regimes in the population.
4. Estimate causal effects under optimal individualized treatment regimes with
the `tmle3mopttx` `R` package.
5. Assess the mean under optimal individualized treatment with resource
constraints.
6. Implement optimal individualized treatment rules based on sub-optimal
rules, or "simple" rules, and recognize the practical benefit of these rules.
7. Construct "realistic" optimal individualized treatment regimes that respect
real data and subject-matter knowledge limitations on interventions by
only considering interventions that are supported by the data.
8. Measure variable importance as defined in terms of the optimal individualized
treatment interventions.
---
## Introduction
Identifying which intervention will be effective for which patient
based on lifestyle, genetic and environmental factors is a common goal in
precision medicine. One opts to administer the intervention to individuals
who will benefit from it, instead of assigning treatment on a population level.
* This aim motivates a different type of intervention, as opposed to the static
exposures we might be used to.
* In this chapter, we learn about dynamic (individualized) interventions that
tailor the treatment decision based on the collected covariates.
---
To motivate these types of interventions, we turn to an actual randomized trial.
* The goal is to improve retention in HIV care.
* Several interventions show efficacy -- appointment reminders through text
messages, small cash incentives for on-time clinic visits, and peer health
workers.
* We want to improve effectiveness by assigning each patient the intervention
they are most likely to benefit from.
* We also do not want to allocate resources to individuals who would not benefit
from an intervention.
<br>
```{r, align='center', fig.cap="Illustration of a Dynamic Treatment Regime in a Clinical Setting", echo=FALSE, eval=TRUE, out.width='60%'}
knitr::include_graphics(path = "img/png/DynamicA_Illustration.png")
```
<br>
---
<br>
<div align="center"> In the statistics community, such a treatment strategy is
termed **individualized treatment regimes** (ITR). The (counterfactual) population
mean outcome under an ITR is the **value of the ITR**. </div>
<br>
* Suppose one wishes to maximize the population mean of an outcome, where for
each individual we have access to some set of measured covariates.
* ITR with the maximal value is referred to as an **optimal ITR** or the
**optimal individualized treatment**.
* The value of an optimal ITR is termed the **optimal value**, or the **mean
under the optimal individualized treatment**.
* One opts to administer the intervention to individuals who will profit from
it, instead of assigning treatment on a population level.
<br>
<div align="center"> **But how do we know which intervention works for which patient?** </div>
<br>
<br>
---
* In this chapter, we examine optimal individualized treatment regimes, and
estimate the mean outcome under the ITR.
* The candidate rules are restricted to depend only on user-supplied subset of
the baseline covariates.
* We will use `tmle3mopttx` to estimate optimal ITR and the corresponding value.
<br>
---
<br>
## Data Structure and Notation
* Suppose we observe $n$ independent and identically distributed observations of
the form $O=(W,A,Y) \sim P_0$.
* $P_0 \in \mathcal{M}$, where $\mathcal{M}$ is the
fully nonparametric model.
* Denote $A \in \mathcal{A}$ as categorical treatment.
* Let
$\mathcal{A} \equiv \{a_1, \ldots, a_{n_A} \}$ and $n_A = |\mathcal{A}|$, with
$n_A$ denoting the number of categories.
* Denote $Y$ as the final outcome.
* $W$ a vector-valued collection of baseline covariates.
* Finally, let $V$ be a subset of the baseline covariates $W$ that
the rule might depend on.
<br>
---
<br>
* The likelihood of the data admits a factorization, implied by the time ordering of $O$.
\begin{align*}\label{eqn:likelihood_factorization}
p_0(O) &= p_{Y,0}(Y|A,W) p_{A,0}(A|W) p_{W,0}(W) \\
&= q_{Y,0}(Y|A,W) q_{A,0}(A|W) q_{W,0}(W),
\end{align*}
* Consequently, let
$$P_{Y,0}(Y|A,W)=Q_{Y,0}(Y|A,W),$$ $$P_{A,0}(A|W)=g_0(A|W)$$ and $$P_{W,0}(W)=Q_{W,0}(W).$$
<br>
* We also define $\bar{Q}_{Y,0}(A,W) \equiv E_0[Y|A,W]$.
<br>
---
<br>
## Causal Effect of an OIT
We define relationships between variables with **structural equations**:
\begin{align*}
W &= f_W(U_W) \\ A &= f_A(W, U_A) \\ Y &= f_Y(A, W, U_Y).
\end{align*}
* $U=(U_W,U_A,U_Y)$ denotes the exogenous random variables, drawn from $U \sim P_U$.
* The endogenous variables, written as $O=(W,A,Y)$, correspond to the observed data.
<br>
---
<br>
<div align="center"> **Causal effects are defined as
hypothetical interventions on SEM.** </div>
<br>
* Consider dynamic treatment rules, denoted as $d$, in the set of all possible rules
$\mathcal{D}$.
* In a point treatment setting, $d$ is a deterministic function
that takes as input $V$ and outputs a treatment decision where
<br>
$$V \rightarrow d(V) \in \{a_1, \cdots, a_{n_A} \}.$$
<br>
---
<br>
For a given rule $d$, our modified system then takes the following form:
\begin{align*}
W &= f_W(U_W) \\ A &= d(V) \\ Y_{d(V)} &= f_Y(d(V), W, U_Y).
\end{align*}
<br>
* The counterfactual outcome $Y_{d(V)}$ denotes the outcome for a patient had
their treatment been assigned using the dynamic rule $d(V)$ (possibly contrary
to the fact).
* Distribution of the counterfactual outcomes is $P_{U,X}$, implied by the
distribution of exogenous variables $U$ and structural equations $f$.
* The set of all possible counterfactual distributions are encompassed by the
causal model $\mathcal{M}^F$, where $P_{U,X} \in \mathcal{M}^F$.
<br>
<div align="center"> **"What is the expected outcome had every subject received treatment according to the
(optimal) rule $d$?"** </div>
<br>
---
<br>
We can consider different treatment rules, all in the set $\mathcal{D}$:
1. The **true rule**, $d_0$, and the corresponding causal parameter
$E_{U,X}[Y_{d_0(V)}]$ denoting the expected outcome under the
true treatment rule $d_0(V)$.
2. The **estimated rule**, $d_n$, and the corresponding causal parameter
$E_{U,X}[Y_{d_n(V)}]$ denoting the expected outcome under the
estimated treatment rule $d_n(V)$.
<br>
<div align="center"> In this chapter, we will focus on the value under the estimated rule $d_n$,
a __data-adaptive parameter__. </div>
<br>
<div align="center"> **Note that its true value depends on the sample!** </div>
<br>
---
<br>
The optimal individualized rule is the rule with the maximal value:
$$d_{opt}(V) \equiv \text{argmax}_{d(V) \in \mathcal{D}}
E_{P_{U,X}}[Y_{d(V)}].$$
<br>
Our causal target parameter of interest is the expected outcome under
the estimated optimal individualized rule:
$$\Psi_{d_{n, \text{opt}}(V)}(P_{U,X}) := E_{P_{U,X}}[Y_{d_{n,
\text{opt}}(V)}].$$
<br>
---
<br>
### Identification and Statistical Estimand
<div align="center"> In order for the causal quantities to be estimated from the
observed data, they need to be identified with statistical parameters. </div>
<br>
* This step of the roadmap requires me make a few assumptions:
1. _Strong ignorability_: $A$ independent of $Y^{d_n(v)} \mid W$, for all $a \in \mathcal{A}$.
2. _Positivity (or overlap)_: $P_0(\min_{a \in \mathcal{A}} g_0(a \mid W) > 0) = 1$
<br>
---
<br>
Under the above causal assumptions, we can identify the causal target parameter
with observed data using the G-computation formula.
* The value of an individualized
rule can now be expressed as
$$E_0[Y_{d_n(V)}] = E_{0,W}[\bar{Q}_{Y,0}(A=d_n(V),W)].$$
<br>
<div align="center"> **"Mean outcome if (possibly contrary to fact), treatment was assigned according to the rule $d_n$."** </div>
<br>
---
<br>
* Finally, the statistical counterpart to the causal parameter of interest is
defined as:
$$\psi_0 = E_{0,W}[\bar{Q}_{Y,0}(A=d_{n,\text{opt}}(V),W)].$$
<br>
<div align="center"> **"Mean outcome if (possibly contrary to fact), treatment was assigned according to the optimal rule $d_{n,\text{opt}}$."** </div>
<br>
---
<br>
### High-level idea
<br>
1. Learn the optimal ITR using the Super Learner.
<br>
2. Estimate its value with the cross-validated Targeted Minimum Loss-based
Estimator (CV-TMLE).
<br>
---
<br>
### Why CV-TMLE?
* CV-TMLE is necessary as the non-cross-validated TMLE
is biased upward for the mean outcome under the rule, and therefore overly optimistic.
* More generally however, using CV-TMLE allows us more freedom in estimation and therefore greater
data adaptivity, without sacrificing inference.
<br>
---
<br>
## Binary Treatment
<div align="center"> **How do we estimate the optimal individualized treatment regime?** </div>
<br>
* In the case of binary treatment, a key quantity for optimal ITR is the **blip** function.
* Optimal ITR assigns treatment to individuals falling in strata in which the
stratum specific average treatment effect, the blip function, is positive.
* Consequently, it does not assign treatment to individuals for which this
quantity is negative.
<br>
We define the blip function as:
$$\bar{Q}_0(V) \equiv E_0[Y_1-Y_0|V] \equiv E_0[\bar{Q}_{Y,0}(1,W) - \bar{Q}_{Y,0}(0,W) | V], $$
or the average treatment effect within a stratum of $V$.
<br>
Optimal individualized rule can now be derived as:
$$d_{opt}(V) = I(\bar{Q}_{0}(V) > 0).$$
<br>
---
<br>
We follow the below steps in order to obtain value of the ITR:
<br>
1. Estimate $\bar{Q}_{Y,0}(A,W)$ and $g_0(A|W)$ using `sl3`. We denote such estimates
as $\bar{Q}_{Y,n}(A,W)$ and $g_n(A|W)$.
<br>
2. Apply the doubly robust Augmented-Inverse Probability Weighted (A-IPW) transform to
our outcome, where we define:
$$D_{\bar{Q}_Y,g,a}(O) \equiv \frac{I(A=a)}{g(A|W)} (Y-\bar{Q}_Y(A,W)) + \bar{Q}_Y(A=a,W)$$
<br>
---
<br>
Few notes on the A-IPW transform:
* Under the randomization and positivity assumptions, we have that
$E[D_{\bar{Q}_Y,g,a}(O) | V] = E[Y_a |V].$
* Due to the double robust nature
of the A-IPW transform, consistency of $E[Y_a |V]$ will depend on correct estimation
of either $\bar{Q}_{Y,0}(A,W)$ or $g_0(A|W)$.
* In a randomized trial, we are
guaranteed a consistent estimate of $E[Y_a |V]$ even if we get $\bar{Q}_{Y,0}(A,W)$ wrong!
<br>
Using this transform, we can define the following contrast:
$$D_{\bar{Q}_Y,g}(O) = D_{\bar{Q}_Y,g,a=1}(O) - D_{\bar{Q}_Y,g,a=0}(O).$$
<br>
We estimate the blip function, $\bar{Q}_{0,a}(V)$, by regressing $D_{\bar{Q}_Y,g}(O)$ on $V$.
<br>
Our estimated rule is $d(V) = \text{argmax}_{a \in \mathcal{A}} \bar{Q}_{0,a}(V)$.
---
<br>
Finally, get the mean under the OIT:
3. We obtain inference for the mean outcome under the estimated optimal rule using CV-TMLE.
<br>
---
<br>
All combined:
1. Estimate $\bar{Q}_{Y,0}(A,W)$ and $g_0(A|W)$ using `sl3`. We denote such estimates
as $\bar{Q}_{Y,n}(A,W)$ and $g_n(A|W)$.
<br>
2. Apply the doubly robust Augmented-Inverse Probability Weighted (A-IPW) transform to
our outcome. Our estimated rule is $d(V) = \text{argmax}_{a \in \mathcal{A}} \bar{Q}_{0,a}(V)$.
<br>
3. We obtain inference for the mean outcome under the estimated optimal rule using CV-TMLE.
<br>
---
<br>
### Causal Effect of OIT with Binary A
To start, let us load the packages we will use and set a seed for simulation:
```{r setup-mopttx, message=FALSE, warning=FALSE}
library(data.table)
library(sl3)
library(tmle3)
library(tmle3mopttx)
library(devtools)
library(here)
set.seed(111)
```
<br>
---
<br>
#### Simulate Data
Our data generating distribution is of the following form:
$$W \sim \mathcal{N}(\bf{0},I_{3 \times 3})$$
$$P(A=1|W) = \frac{1}{1+\exp^{(-0.8*W_1)}}$$
\begin{align}
P(Y=1|A,W) &= 0.5\text{logit}^{-1}[-5I(A=1)(W_1-0.5) \\
&+ 5I(A=0)(W_1-0.5)] +0.5\text{logit}^{-1}(W_2W_3)
\end{align}
<br>
---
<br>
```{r load_data_bin, echo=FALSE}
load(here("data", "tmle3mopttx_bin.RData"))
```
```{r load sim_bin_data, eval=FALSE, echo=FALSE}
data("data_bin")
data <- data_bin
```
```{r load sim_bin_data_head}
head(data)
```
* The above composes our observed data structure $O = (W, A, Y)$.
* Note that the mean under the OIT is $\psi_0=0.578$ for this data generating
distribution.
<br>
---
<br>
Next, we specify the role that each variable in the data set plays as the nodes in a DAG.
```{r data_nodes2-mopttx}
# organize data and nodes for tmle3
node_list <- list(
W = c("W1", "W2", "W3"),
A = "A",
Y = "Y"
)
node_list
```
* We now have an observed data structure (`data`), and a specification of the role
that each variable in the data set plays as the nodes in a DAG.
<br>
---
<br>
#### Constructing Stacked Regressions with `sl3`
We generate three different ensemble learners that must be fit.
1. learners for the outcome regression,
2. propensity score, and
3. blip function.
```{r mopttx_sl3_lrnrs2}
# Define sl3 library and metalearners:
lrn_mean <- Lrnr_mean$new()
lrn_glm <- Lrnr_glm_fast$new()
lrn_lasso <- Lrnr_glmnet$new()
lrnr_hal <- Lrnr_hal9001$new(reduce_basis=1/sqrt(nrow(data)) )
## Define the Q learner:
Q_learner <- Lrnr_sl$new(
learners = list(lrn_lasso, lrn_mean, lrn_glm),
metalearner = Lrnr_nnls$new()
)
## Define the g learner:
g_learner <- Lrnr_sl$new(
learners = list(lrn_lasso, lrn_glm),
metalearner = Lrnr_nnls$new()
)
## Define the B learner:
b_learner <- Lrnr_sl$new(
learners = list(lrn_mean, lrn_glm, lrn_lasso),
metalearner = Lrnr_nnls$new()
)
```
We make the above explicit with respect to standard
notation by bundling the ensemble learners into a list object below:
```{r mopttx_make_lrnr_list}
# specify outcome and treatment regressions and create learner list
learner_list <- list(Y = Q_learner, A = g_learner, B = b_learner)
learner_list
```
<br>
---
<br>
#### Targeted Estimation
To start, we will initialize a specification for the TMLE of our parameter of
interest simply by calling `tmle3_mopttx_blip_revere`.
* We specify the argument `V = c("W1", "W2", "W3")` in order to communicate that
we're interested in learning a rule dependent on `V` covariates.
* We also need to specify the type of blip we will use in this estimation problem, and
the list of learners used.
* In addition, we need to specify whether we want to maximize or minimize the
mean outcome under the rule (`maximize=TRUE`).
```{r mopttx_spec_init_complex, eval=FALSE}
# initialize a tmle specification
tmle_spec <- tmle3_mopttx_blip_revere(
V = c("W1", "W2", "W3"), type = "blip1",
learners = learner_list,
maximize = TRUE, complex = TRUE,
realistic = FALSE, resource = 1,
interpret=TRUE
)
```
```{r mopttx_fit_tmle_auto_blip_revere_complex, eval=FALSE}
# fit the TML estimator
fit <- tmle3(tmle_spec, data, node_list, learner_list)
```
```{r mopttx_fit_tmle_auto_blip_revere_complex_res, eval=TRUE}
# see the result
fit
```
<br>
<div align="center"> We can see that the confidence interval covers the truth! </div>
<br>
---
<br>
We can also get the interpretable surrogate rule in terms of HAL:
```{r mopttx_fit_tmle_auto_blip_revere_complex_HAL, eval=TRUE}
# Interpretable rule
head(tmle_spec$blip_fit_interpret$coef)
```
```{r mopttx_fit_tmle_auto_blip_revere_complex_HAL2, eval=TRUE}
# Interpretable rule
head(tmle_spec$blip_fit_interpret$term)
```
<br>
---
<br>
#### Resource constraint
We can also restrict the number of individuals that get the treatment, even if giving
treatment is beneficial (according to the estimated blip).
* In order to impose a resource constraint, we have to specify the percent
of individuals that will
benefit the most from getting treatment.
* For example, if `resource=1`, all
individuals with blip higher than zero will get treatment.
* If `resource=0`, none will get treatment.
```{r mopttx_spec_init_complex_resource, eval=FALSE}
# initialize a tmle specification
tmle_spec_resource <- tmle3_mopttx_blip_revere(
V = c("W1", "W2", "W3"), type = "blip1",
learners = learner_list,
maximize = TRUE, complex = TRUE,
realistic = FALSE, resource = 0.80
)
```
```{r mopttx_fit_tmle_auto_blip_revere_complex_resource, eval=FALSE}
# fit the TML estimator
fit_resource <- tmle3(tmle_spec_resource, data, node_list, learner_list)
```
```{r mopttx_fit_tmle_auto_blip_revere_complex_resource_res, eval=TRUE}
# see the result
fit_resource
```
<br>
---
<br>
We can compare the number of individuals that got treatment with and without the
resource constraint:
```{r mopttx_compare_resource}
# Number of individuals with A=1 (no resource constraint):
table(tmle_spec$return_rule)
# Number of individuals with A=1 (resource constraint):
table(tmle_spec_resource$return_rule)
```
<br>
---
<br>
#### Empty V
```{r mopttx_spec_init_complex_V_empty}
# initialize a tmle specification
tmle_spec_V_empty <- tmle3_mopttx_blip_revere(
type = "blip1",
learners = learner_list,
maximize = TRUE, complex = TRUE,
realistic = FALSE, resource = 1
)
```
```{r mopttx_fit_tmle_auto_blip_revere_complex_V_empty, eval=FALSE}
# fit the TML estimator
fit_V_empty <- tmle3(tmle_spec_V_empty, data, node_list, learner_list)
```
```{r mopttx_fit_tmle_auto_blip_revere_complex_V_empty_res, eval=TRUE}
# see the result:
fit_V_empty
```
<br>
---
<br>
## Categorical Treatment
<div align="center"> **QUESTION:** What if the treatment is categorical, with more than two categories?
Can we still use the blip function? </div>
<br>
* We define **pseudo-blips**: vector valued entities where the output for a given
$V$ is a vector of length equal to the number of treatment categories, $n_A$.
* As such, we define it as:
$$\bar{Q}_0^{pblip}(V) = \{\bar{Q}_{0,a}^{pblip}(V): a \in \mathcal{A} \}.$$
<br>
---
<br>
We implement three different pseudo-blips in `tmle3mopttx`.
1. **Blip1** corresponds to choosing a reference category of treatment, and
defining the blip for all other categories relative to the specified reference:
$$\bar{Q}_{0,a}^{pblip-ref}(V) \equiv E_0(Y_a-Y_0|V)$$
<br>
2. **Blip2** corresponds to defining the blip relative to the average of
all categories:
$$\bar{Q}_{0,a}^{pblip-avg}(V) \equiv E_0(Y_a- \frac{1}{n_A} \sum_{a \in \mathcal{A}} Y_a|V)$$
<br>
3. **Blip3** reflects an extension of Blip2, where the average is now a weighted average:
$$\bar{Q}_{0,a}^{pblip-wavg}(V) \equiv E_0(Y_a- \frac{1}{n_A} \sum_{a \in \mathcal{A}} Y_{a} P(A=a|V)
|V)$$
<br>
---
<br>
### Causal Effect of OIT with Categorical A
We now need to pay attention to the **type of blip** we define in the estimation stage,
as well as **how we construct our learners.**
#### Simulated Data
First, we load the simulated data. Here, our data generating distribution was
of the following form:
<br>
$$W \sim \mathcal{N}(\bf{0},I_{4 \times 4})$$
$$P(A|W) = \frac{1}{1+\exp^{(-(0.05*I(A=1)*W_1+0.8*I(A=2)*W_1+0.8*I(A=3)*W_1))}}$$
$$P(Y|A,W)=0.5\text{logit}^{-1}[15I(A=1)(W_1-0.5) - 3I(A=2)(2W_1+0.5) \\
+ 3I(A=3)(3W_1-0.5)] +\text{logit}^{-1}(W_2W_1)$$
<br>
---
<br>
We can just load the data available as part of the package as follows:
```{r load_results, eval=TRUE, echo=FALSE}
load(here("data", "tmle3mopttx_cat.RData"))
```
```{r load sim_cat_data, eval=FALSE, echo=FALSE}
data("data_cat_realistic")
```
```{r load sim_cat_data_head, eval=TRUE}
head(data)
```
* The above constructs our observed data structure $O = (W, A, Y)$.
* The true mean under the OIT is $\psi=0.658$, which is the quantity we aim
to estimate.
<br>
---
<br>
```{r data_nodes-mopttx}
# organize data and nodes for tmle3
data <- data_cat_realistic
node_list <- list(
W = c("W1", "W2", "W3", "W4"),
A = "A",
Y = "Y"
)
node_list
```
We can see the number of observed categories of treatment below:
```{r data_cats-mopttx}
# organize data and nodes for tmle3
table(data$A)
```
<br>
---
<br>
#### Constructing Stacked Regressions with `sl3`
**QUESTION:** With categorical treatment, what is the dimension of the blip now?
What is the dimension for the current example? How would we go about estimating it?
<br>
```{r sl3_lrnrs-mopttx, eval=TRUE}
# Initialize few of the learners:
lrn_xgboost_50 <- Lrnr_xgboost$new(nrounds = 50)
lrn_mean <- Lrnr_mean$new()
lrn_glm <- Lrnr_glm_fast$new()
## Define the Q learner, which is just a regular learner:
Q_learner <- Lrnr_sl$new(
learners = list(lrn_xgboost_50, lrn_mean, lrn_glm),
metalearner = Lrnr_nnls$new()
)
## Define the g learner, which is a multinomial learner:
# specify the appropriate loss of the multinomial learner:
mn_metalearner <- make_learner(Lrnr_solnp,
eval_function = loss_loglik_multinomial,
learner_function = metalearner_linear_multinomial
)
g_learner <- make_learner(Lrnr_sl, list(lrn_xgboost_50, lrn_mean), mn_metalearner)
## Define the Blip learner, which is a multivariate learner:
learners <- list(lrn_xgboost_50, lrn_mean, lrn_glm)
b_learner <- create_mv_learners(learners = learners)
```
<br>
---
<br>
* We need to estimate $g_0(A|W)$ for a categorical $A$:
we use the **multinomial** Super Learner option available within the `sl3` package.
* We need to estimate the blip using a **multivariate** Super Learner
available within the `sl3` package.
<br>
In order to see which learners can
be used to estimate $g_0(A|W)$ in `sl3`, we run the following:
```{r cat_learners}
# See which learners support multi-class classification:
sl3_list_learners(c("categorical"))
```
```{r make_lrnr_list-mopttx}
# specify outcome and treatment regressions and create learner list
learner_list <- list(Y = Q_learner, A = g_learner, B = b_learner)
learner_list
```
<br>
---
<br>
#### Targeted Estimation
```{r spec_init, eval=FALSE}
# initialize a tmle specification
tmle_spec_cat <- tmle3_mopttx_blip_revere(
V = c("W1", "W2", "W3", "W4"), type = "blip2",
learners = learner_list, maximize = TRUE, complex = TRUE,
realistic = FALSE
)
```
```{r fit_tmle_auto, eval=FALSE}
# fit the TML estimator
fit_cat <- tmle3(tmle_spec_cat, data, node_list, learner_list)
```
```{r fit_tmle_auto_res, eval=TRUE}
# see the result:
fit_cat
# How many individuals got assigned each treatment?
table(tmle_spec_cat$return_rule)
```
We can see that the confidence interval covers the truth.
<br>
<div align="center"> **NOTICE the distribution of the assigned treatment! We will need this shortly.** </div>
<br>
---
<br>
## Extensions
We consider multiple extensions to the procedure described for
estimating the value of the ITR.
<br>
* One might be interested in a grid of possible suboptimal rules, corresponding to
potentially limited knowledge of potential effect modifiers (**Simpler Rules**).
<br>
* Certain regimes might be preferred, but due to positivity restraints are not realistic to implement (**Realistic Interventions**).
<br>
---
<br>
### Simpler Rules
We define $S$-optimal rules as the optimal rule that considers all possible subsets
of $V$ covariates, with card($S$) $\leq$ card($V$) and $\emptyset \in S$.
* This allows us to consider sub-optimal rules that are easier to estimate:
we allow for statistical inference for the counterfactual mean outcome under the sub-optimal rule.