-
Notifications
You must be signed in to change notification settings - Fork 0
/
one-stage.Rmd
2118 lines (1912 loc) · 117 KB
/
one-stage.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
---
title: "one-stage"
author: "A.Amstutz"
date: "2023-10-18"
output:
html_document:
keep_md: yes
toc: yes
toc_float: yes
code_folding: hide
pdf_document:
toc: yes
---
# Load packages
```{r load packages, echo=TRUE, message=FALSE, warning=FALSE}
library(tidyverse)
library(readxl)
library(writexl)
library(tableone)
library(here)
library(kableExtra)
library(jtools) # for summ() and plot_summs
library(sjPlot) # for tab_model
library(ggplot2) # survival/TTE analyses and other graphs
library(ggsurvfit) # survival/TTE analyses
library(survival) # survival/TTE analyses
library(gtsummary) # survival/TTE analyses
library(ggfortify) # autoplot
library(lme4) # glmer / clmm
library(sjPlot) # for tab_model
library(glmmTMB) # to specify estimation method explicitly -> i.e. ML
library(coxme) # for mixed-effects cox model
library(ordinal) # for ordinal regression, clm (fixed effects) & clmm (mixed effects)
library(tidycmprsk) # competing risk analysis
library(logistf) # Firth regression in case of rare events
library(meta)
library(forestplot)
library(metafor) #forest()
```
# Load standardized dataset of all trials
```{r echo=TRUE, message=FALSE, warning=FALSE}
## barisolidact
df_barisolidact <- readRDS("df_os_barisolidact.RData")
df_barisolidact <- df_barisolidact %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## actt2
df_actt2 <- readRDS("df_os_actt2.RData")
df_actt2 <- df_actt2 %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## ghazaeian
df_ghazaeian <- readRDS("df_os_ghazaeian.RData")
df_ghazaeian <- df_ghazaeian %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## tofacov
df_tofacov <- readRDS("df_os_tofacov.RData")
df_tofacov <- df_tofacov %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## covinib
df_covinib <- readRDS("df_os_covinib.RData")
df_covinib <- df_covinib %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## COV-BARRIER
df_covbarrier <- readRDS("df_os_cov-barrier.RData")
df_covbarrier <- df_covbarrier %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## Murugesan
df_murugesan <- readRDS("df_os_murugesan.RData")
df_murugesan <- df_murugesan %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## RECOVERY
df_recovery <- readRDS("df_os_recovery.RData")
df_recovery <- df_recovery %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## TACTIC-R
df_tactic_r <- readRDS("df_os_tactic-r.RData")
df_tactic_r <- df_tactic_r %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
## PANCOVID
df_pancovid <- readRDS("df_os_pancovid.RData")
df_pancovid <- df_pancovid %>%
select(id_pat, trial, JAKi, trt, sex, age, ethn, country, icu, sympdur, vacc, clinstatus_baseline, vbaseline,
comed_dexa, comed_rdv, comed_toci, comed_ab, comed_acoa, comed_interferon, comed_other,
comed_cat,
comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp,
comorb_autoimm, comorb_cancer, comorb_kidney, any_comorb, comorb_cat, comorb_any, comorb_count,
crp, sero, vl_baseline, variant,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
clinstatus_28_imp,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
ae_28, ae_28_sev,
vir_clear_5, vir_clear_10, vir_clear_15)
# append
df_tot <- rbind(df_barisolidact, df_actt2, df_ghazaeian, df_tofacov, df_covinib, df_covbarrier, df_recovery, df_tactic_r, df_pancovid)
# df_tot_Muru <- rbind(df_barisolidact, df_actt2, df_ghazaeian, df_tofacov, df_covinib, df_covbarrier, df_murugesan, df_recovery)
# Save
saveRDS(df_tot, file = "df_tot.RData")
write_xlsx(df_tot, path = "df_tot.xlsx")
# saveRDS(df_tot_Muru, file = "df_tot_Muru.RData")
```
# (i) Primary outcome: Mortality at day 28
```{r warning=FALSE}
addmargins(table(df_tot$trial, df_tot$mort_28, useNA = "always"))
addmargins(table(df_tot$mort_28, df_tot$trt, useNA = "always"))
# table(df_tot$age, df_tot$trt, useNA = "always")
table(df_tot$clinstatus_baseline, df_tot$trt, useNA = "always")
table(df_tot$clinstatus_baseline, df_tot$trial, useNA = "always")
table(df_tot$vbaseline, df_tot$trial, useNA = "always")
# reformatting
df_tot$trt_f <- as.factor(df_tot$trt)
df_tot$trial_f <- as.factor(df_tot$trial)
df_tot$clinstatus_baseline_n <- as.numeric(df_tot$clinstatus_baseline)
df_tot <- df_tot %>%
mutate(trial_n = case_when(trial == "Bari-Solidact" ~ 1,
trial == "ACTT2" ~ 2,
trial == "Ghazaeian" ~ 3,
trial == "TOFACOV" ~ 4,
trial == "COVINIB" ~ 5,
trial == "COV-BARRIER" ~ 6,
trial == "RECOVERY" ~ 7,
trial == "TACTIC-R" ~ 8,
trial == "PANCOVID" ~ 9,
))
table(df_tot$trial_n, useNA = "always")
```
GOAL: random treatment effect, stratified trial intercept, stratified prognostic factors, AND centering the treatment variable by the proportion treated in the trial (to improve the estimation of between-study variance) AND maximum likelihood (ML) estimator (due to small trials with rare events). REML is default in glmer, for ML use glmmTMB. See notes.
### (1) common treatment effect, random trial intercept, common prognostic factors
```{r}
# (1) common treatment effect, random trial intercept, common prognostic factors, ML
mort28.ctreat.rtrial.ml <- glmmTMB(mort_28 ~ trt + (1|trial)
+ age + clinstatus_baseline
, data = df_tot, family = binomial)
tab_model(mort28.ctreat.rtrial.ml)
mort28.ctreat.rtrial.ml.vb <- glmmTMB(mort_28 ~ trt + (1|trial)
+ age + vbaseline
, data = df_tot, family = binomial)
# tab_model(mort28.ctreat.rtrial.ml.vb)
```
### (2) random treatment effect, random trial intercept, common prognostic factors and residual variances
```{r}
# (3) random treatment effect, random trial intercept, common prognostic factors and residual variances, ML
mort28.rtreat.rtrial.ml <- glmmTMB(mort_28 ~ trt + (1 + trt|trial_f)
+ age + clinstatus_baseline
, data = df_tot, family = binomial)
# tab_model(mort28.rtreat.rtrial.ml)
mort28.rtreat.rtrial.ml.vb <- glmmTMB(mort_28 ~ trt + (1 + trt|trial_f)
+ age + vbaseline
, data = df_tot, family = binomial)
# tab_model(mort28.rtreat.rtrial.ml.vb)
```
### (3) random treatment effect, stratified trial intercept, common prognostic factors and residual variances
```{r}
# (2) random treatment effect, stratified trial intercept, common prognostic factors and residual variances, and WITHOUT centering the treatment variable, ML
mort28.rtreat.strial.ml <- glmmTMB(mort_28 ~ trt_f + trial_f + (trt - 1 | trial_f)
+ age + clinstatus_baseline
, data = df_tot, family = binomial)
# tab_model(mort28.rtreat.strial.ml)
mort28.rtreat.strial.ml.vb <- glmmTMB(mort_28 ~ trt_f + trial_f + (trt - 1 | trial_f)
+ age + vbaseline
, data = df_tot, family = binomial)
# tab_model(mort28.rtreat.strial.ml.vb)
# The - 1 within (trt - 1 | trial_n) specifies that there is no random intercept for the grouping factor trial_n. We're specifying random slopes for the variable trt within each level of trial_n, i.e., the effect may vary from one trial to another. Together with trial_f, this gives the stratified intercept model. This is a more flexible model compared to a model with a random intercept, which assumes a common baseline for all groups.
# dummy variable for each trial (trial_1, trial_2, trial_3, etc - e.g. where trial_1 = 1 if in trial 1 and 0 otherwise)
# df_tot <- df_tot %>%
# mutate(trial_1 = case_when(trial == "Bari-Solidact" ~ 1, TRUE ~ 0),
# trial_2 = case_when(trial == "ACTT2" ~ 1, TRUE ~ 0),
# trial_3 = case_when(trial == "Ghazaeian" ~ 1, TRUE ~ 0),
# trial_4 = case_when(trial == "TOFACOV" ~ 1, TRUE ~ 0),
# trial_5 = case_when(trial == "COVINIB" ~ 1, TRUE ~ 0),
# trial_6 = case_when(trial == "COV-BARRIER" ~ 1, TRUE ~ 0),
# trial_7 = case_when(trial == "RECOVERY" ~ 1, TRUE ~ 0),
# trial_8 = case_when(trial == "TACTIC-R" ~ 1, TRUE ~ 0))
## Use "Stata syntax":
# mort28.rtreat.strial.2 <- glmer(mort_28 ~ trt_f + trial* + (trt -1 | trial_n)
# + age + clinstatus_baseline_n
# # + comed_dexa + comed_rdv + comed_toci
# , data = df_tot, family = binomial)
# tab_model(mort28.rtreat.strial.2)
```
### (4) random treatment effect, stratified trial intercept, common prognostic factors and residual variances, AND centering the treatment variable
```{r}
# (4) random treatment effect, stratified trial intercept, common prognostic factors and residual variances, ML, but WITH centering the treatment variable
# calculate the proportion treated by trial
proportions <- df_tot %>%
group_by(trial) %>%
summarize(proportion_treated = sum(trt) / n())
df_tot <- left_join(df_tot, proportions[, c("proportion_treated", "trial")], by = join_by(trial == trial))
# table(df_tot$trial, df_tot$proportion_treated)
# create the centered treatment variable
df_tot$trt_centered_n <- df_tot$trt - df_tot$proportion_treated
df_tot$trt_centered_f <- as.factor(df_tot$trt_centered_n)
# table(df_tot$trial, df_tot$trt_centered_f) ## keep it minus?
# build the model. '-1' indicating there is no overall random intercept.
mort28.rtreat.strial.cent.ml <- glmmTMB(mort_28 ~ trt_centered_n + trial_f + (trt_centered_n -1 | trial_f) -1
+ age + clinstatus_baseline
, data = df_tot, family = binomial
)
# tab_model(mort28.rtreat.strial.cent.ml)
mort28.rtreat.strial.cent.ml.vb <- glmmTMB(mort_28 ~ trt_centered_n + trial_f + (trt_centered_n -1 | trial_f) -1
+ age + vbaseline
, data = df_tot, family = binomial
)
# tab_model(mort28.rtreat.strial.cent.ml.vb)
```
### (5) random treatment effect, stratified trial intercept, stratified prognostic factors and residual variances, with centering the treatment variable AND the prognostic variables
```{r}
# "Our default recommendation is to use stratified prognostic effects (i.e. estimate a separate effect of each included prognostic factor for each trial), with trial-specific centering of each prognostic factor to improve ML estimation (for the reasons explained in Section 6.2.8.3). However, if outcome data or prognostic factor categories are sparse, the stratification approach may lead to estimation difficulties, and then allowing prognostic factor effects to be random is a sensible alternative." (p. 145) Centering disentangles (i.e. makes uncorrelated) the estimation of main parameters of interest from other nuisance parameters, which leads to less downward bias in estimates of variance parameters (Figure 6.2) and thus improves coverage of 95% confidence intervals. This can be achieved by centering the covariates by their mean values within trials, such that the interaction estimate is then only based on within-trial information.
# Calculate the mean values of (continuous) prognostic factors within each trial
trial_means <- df_tot %>%
group_by(trial) %>%
summarize(mean_age = mean(age, na.rm = TRUE), mean_clinstatus = mean(clinstatus_baseline_n, na.rm = TRUE))
# Merge back
df_tot <- df_tot %>% left_join(trial_means, by = "trial")
# Center the age and clinstatus_baseline variables
df_tot <- df_tot %>%
mutate(age_centered = age - mean_age,
clinstatus_baseline_centered = clinstatus_baseline_n - mean_clinstatus)
# df_tot %>%
# select(trial_f, trial_n, trt, trt_centered_n, age, mean_age, age_centered, clinstatus_baseline_n, mean_clinstatus, clinstatus_baseline_centered, mort_28) %>%
# View()
### Add the prognostic factors stratified, i.e. create stratified variables for each prognostic factor
## uncentered
df_tot <- df_tot %>%
mutate(age_trial_1 = case_when(trial == "Bari-Solidact" ~ age, TRUE ~ 0),
age_trial_2 = case_when(trial == "ACTT2" ~ age, TRUE ~ 0),
age_trial_3 = case_when(trial == "Ghazaeian" ~ age, TRUE ~ 0),
age_trial_4 = case_when(trial == "TOFACOV" ~ age, TRUE ~ 0),
age_trial_5 = case_when(trial == "COVINIB" ~ age, TRUE ~ 0),
age_trial_6 = case_when(trial == "COV-BARRIER" ~ age, TRUE ~ 0),
age_trial_7 = case_when(trial == "RECOVERY" ~ age, TRUE ~ 0),
age_trial_8 = case_when(trial == "TACTIC-R" ~ age, TRUE ~ 0),
age_trial_9 = case_when(trial == "PANCOVID" ~ age, TRUE ~ 0))
df_tot <- df_tot %>%
mutate(clinstat_trial_1 = case_when(trial == "Bari-Solidact" ~ clinstatus_baseline, TRUE ~ "0"),
clinstat_trial_2 = case_when(trial == "ACTT2" ~ clinstatus_baseline, TRUE ~ "0"),
clinstat_trial_3 = case_when(trial == "Ghazaeian" ~ clinstatus_baseline, TRUE ~ "0"),
clinstat_trial_4 = case_when(trial == "TOFACOV" ~ clinstatus_baseline, TRUE ~ "0"),
clinstat_trial_5 = case_when(trial == "COVINIB" ~ clinstatus_baseline, TRUE ~ "0"),
clinstat_trial_6 = case_when(trial == "COV-BARRIER" ~ clinstatus_baseline, TRUE ~ "0"),
clinstat_trial_7 = case_when(trial == "RECOVERY" ~ clinstatus_baseline, TRUE ~ "0"),
clinstat_trial_8 = case_when(trial == "TACTIC-R" ~ clinstatus_baseline, TRUE ~ "0"),
clinstat_trial_9 = case_when(trial == "PANCOVID" ~ clinstatus_baseline, TRUE ~ "0"))
## centered
df_tot <- df_tot %>%
mutate(age_cent_trial_1 = case_when(trial == "Bari-Solidact" ~ age_centered, TRUE ~ 0),
age_cent_trial_2 = case_when(trial == "ACTT2" ~ age_centered, TRUE ~ 0),
age_cent_trial_3 = case_when(trial == "Ghazaeian" ~ age_centered, TRUE ~ 0),
age_cent_trial_4 = case_when(trial == "TOFACOV" ~ age_centered, TRUE ~ 0),
age_cent_trial_5 = case_when(trial == "COVINIB" ~ age_centered, TRUE ~ 0),
age_cent_trial_6 = case_when(trial == "COV-BARRIER" ~ age_centered, TRUE ~ 0),
age_cent_trial_7 = case_when(trial == "RECOVERY" ~ age_centered, TRUE ~ 0),
age_cent_trial_8 = case_when(trial == "TACTIC-R" ~ age_centered, TRUE ~ 0),
age_cent_trial_9 = case_when(trial == "PANCOVID" ~ age_centered, TRUE ~ 0))
df_tot <- df_tot %>%
mutate(clinstat_cent_trial_1 = case_when(trial == "Bari-Solidact" ~ clinstatus_baseline_centered, TRUE ~ 0),
clinstat_cent_trial_2 = case_when(trial == "ACTT2" ~ clinstatus_baseline_centered, TRUE ~ 0),
clinstat_cent_trial_3 = case_when(trial == "Ghazaeian" ~ clinstatus_baseline_centered, TRUE ~ 0),
clinstat_cent_trial_4 = case_when(trial == "TOFACOV" ~ clinstatus_baseline_centered, TRUE ~ 0),
clinstat_cent_trial_5 = case_when(trial == "COVINIB" ~ clinstatus_baseline_centered, TRUE ~ 0),
clinstat_cent_trial_6 = case_when(trial == "COV-BARRIER" ~ clinstatus_baseline_centered, TRUE ~ 0),
clinstat_cent_trial_7 = case_when(trial == "RECOVERY" ~ clinstatus_baseline_centered, TRUE ~ 0),
clinstat_cent_trial_8 = case_when(trial == "TACTIC-R" ~ clinstatus_baseline_centered, TRUE ~ 0),
clinstat_cent_trial_9 = case_when(trial == "PANCOVID" ~ clinstatus_baseline_centered, TRUE ~ 0))
# (5) random treatment effect, stratified trial intercept, stratified prognostic factors and residual variances, with centering of the treatment variable AND the prognostic factors
mort28.rtreat.strial.cent.ml.spf.cent <- glmmTMB(mort_28 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3 + age_cent_trial_4
+ age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ clinstat_cent_trial_1 + clinstat_cent_trial_2 + clinstat_cent_trial_3
+ clinstat_cent_trial_4 + clinstat_cent_trial_5 + clinstat_cent_trial_6 + clinstat_cent_trial_7 + clinstat_cent_trial_8 + clinstat_cent_trial_9
, data = df_tot, family = binomial)
tab_model(mort28.rtreat.strial.cent.ml.spf.cent)
# mort28.rtreat.strial.cent.ml.spf.cent <- glmmTMB(mort_28 ~ trt_centered_n
# + trial_f
# + (trt_centered_n -1 | trial_f) -1
# + age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3 + age_cent_trial_4
# + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8
# + clinstat_trial_1 + clinstat_trial_2 + clinstat_trial_3
# + clinstat_trial_4 + clinstat_trial_5 + clinstat_trial_6 + clinstat_trial_7 + clinstat_trial_8
# , data = df_tot, family = binomial)
# tab_model(mort28.rtreat.strial.cent.ml.spf.cent)
# Not all trials have all levels, cannot estimate a stratified clinstatus_baseline by trial. Moreover, not sure the centering of the factor variable clinstatus_baseline is ok like this. => Second best option: Add clinstatus_baseline as a random parameter
mort28.rtreat.strial.cent.ml.sage.cent.rclinstat <- glmmTMB(mort_28 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3 + age_cent_trial_4
+ age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = binomial)
# tab_model(mort28.rtreat.strial.cent.ml.sage.cent.rclinstat)
mort28.rtreat.strial.cent.ml.sage.cent.rvb <- glmmTMB(mort_28 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3 + age_cent_trial_4
+ age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (vbaseline -1 | trial_f)
, data = df_tot, family = binomial)
# tab_model(mort28.rtreat.strial.cent.ml.sage.cent.rvb)
```
Discussion:
1. Clinstatus_baseline is a factor -> How to center a factor? By the proportion in each level? More important: Not all trials have all levels, hard to estimate a stratified clinstatus_baseline by trial => Second best option: Add clinstatus_baseline as a random parameter
2. Remember to add all TRIAL centering variables if adding new trials!
3. Investigate the point that a "one-stage random effects model" equals a "two-stage fixed effects model" (only use trials without rare event problems // double-check adjustments in two-stage)
## Collect the effect estimates from all models
```{r}
# Empty data frame to store the results
result_df <- data.frame(
variable = character(),
hazard_odds_ratio = numeric(),
ci_lower = numeric(),
ci_upper = numeric(),
p_value = numeric()
)
# Function to extract treatment results from two different model types (glmer -> REML, glmmTMB -> ML)
extract_trt_results <- function(model, variable_name, n_int, n_cont) {
if (inherits(model, "glmmTMB")) {
coefficients_table <- summary(model)$coefficients$cond
trt_coef <- coefficients_table[grep("^trt", rownames(coefficients_table)), "Estimate"]
hazard_odds_ratio <- exp(trt_coef)
ci_table <- exp(confint(model))
ci <- ci_table[grep("^trt", rownames(ci_table)), c("2.5 %", "97.5 %")]
p_value <- coefficients_table[grep("^trt", rownames(coefficients_table)), "Pr(>|z|)"]
} else if (inherits(model, "glmerMod")) {
coefficients_table <- summary(model)$coefficients
trt_coef <- coefficients_table[grep("^trt", rownames(coefficients_table)), "Estimate"]
hazard_odds_ratio <- exp(trt_coef)
ci_table <- exp(confint(model))
ci <- ci_table[grep("^trt", rownames(ci_table)), c("2.5 %", "97.5 %")]
p_value <- coefficients_table[grep("^trt", rownames(coefficients_table)), "Pr(>|z|)"]
} else {
stop("Unsupported model class")
}
# capture the results
result <- data.frame(
variable = variable_name,
hazard_odds_ratio = hazard_odds_ratio,
ci_lower = ci[1],
ci_upper = ci[2],
p_value = p_value,
n_intervention = n_int,
n_control = n_cont
)
return(result)
}
# Loop through
result_list <- list()
result_list[[1]] <- extract_trt_results(mort28.ctreat.rtrial.ml, "c trt, r intercept, c age/clinstatus", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
# result_list[[2]] <- extract_trt_results(mort28.ctreat.rtrial.ml.vb, "c trt, r intercept, c age/clinstatus, no cent, vb", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
result_list[[3]] <- extract_trt_results(mort28.rtreat.rtrial.ml, "r trt, r intercept, c age/clinstatus", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
# result_list[[4]] <- extract_trt_results(mort28.rtreat.rtrial.ml.vb, "r trt, r intercept, c age/clinstatus, no cent, vb", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
result_list[[5]] <- extract_trt_results(mort28.rtreat.strial.ml, "r trt, s intercept, c age/clinstatus", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
# result_list[[6]] <- extract_trt_results(mort28.rtreat.strial.ml.vb, "r trt, s intercept, c age/clinstatus, no cent, vb", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
result_list[[7]] <- extract_trt_results(mort28.rtreat.strial.cent.ml, "r cent trt, s intercept, c age/clinstatus", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
# result_list[[8]] <- extract_trt_results(mort28.rtreat.strial.cent.ml.vb, "r trt, s intercept, c age/clinstatus, cent trt, vb", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
result_list[[9]] <- extract_trt_results(mort28.rtreat.strial.cent.ml.sage.cent.rclinstat, "r cent trt, s intercept, s and cent age, r clinstatus", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
# result_list[[10]] <- extract_trt_results(mort28.rtreat.strial.cent.ml.sage.cent.rvb, "r trt, s intercept, s and cent age, r clinstatus, cent trt, vb", addmargins(table(df_tot$mort_28, df_tot$trt))[3,2], addmargins(table(df_tot$mort_28, df_tot$trt))[3,1])
# Filter out NULL results and bind the results into a single data frame
result_df <- do.call(rbind, Filter(function(x) !is.null(x), result_list))
# Nicely formatted table
kable(result_df, format = "html", table.attr = 'class="table"') %>%
kable_styling(bootstrap_options = "striped", full_width = FALSE)
```
### Plot the effect estimates and 95% CI for all models
```{r}
# Convert necessary columns to numeric
result_df[, c("hazard_odds_ratio", "ci_lower", "ci_upper", "p_value", "n_intervention", "n_control")] <- lapply(result_df[, c("hazard_odds_ratio", "ci_lower", "ci_upper", "p_value", "n_intervention", "n_control")], as.numeric)
result_df$variable <- factor(result_df$variable,
levels = c("c trt, r intercept, c age/clinstatus",
"r trt, r intercept, c age/clinstatus",
"r trt, s intercept, c age/clinstatus",
"r cent trt, s intercept, c age/clinstatus",
"r cent trt, s intercept, s and cent age, r clinstatus"))
# Plotting the reordered data
# Plotting
ggplot(result_df, aes(x = variable, y = hazard_odds_ratio)) +
geom_point() +
geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper), width = 0.3) +
labs(title = "Mortality at Day 28 - All models",
x = "Model",
y = "Odds Ratio") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.margin = margin(l = 50, r = 10, b = 20, t = 20, unit = "pt")) + # Adjust left margin
scale_y_continuous(limits = c(0.5, 1.0), breaks = c(0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1.0), trans = "log10") +
coord_flip() # Flip axes to show longer variable names
```
### The main recommendations for one-stage IPD meta-analysis models using GLMMs (IPDMA handbook R.Riley)
1. *__Use a random treatment effect.__*
* Justification: Typically the included trials are conducted in different settings, populations and time periods. Therefore, some heterogeneity of treatment effect is expected. Heterogeneity might be reduced by inclusion of prognostic factors or trial-level covariates, but usually unexplained heterogeneity remains and so should be acknowledged. Homogeneity of treatment effect is a strong assumption, and often will be inappropriate due to unexplained between-trial heterogeneity. To address this, the treatment effect parameter can be made random, such that the true treatment effect in each trial is assumed drawn from a particular distribution, typically a normal distribution.
2. *__Stratify by trial the intercept and parameters for other non-treatment variables (such as prognostic factors and residual variances).__* If convergence issues arise, then consider making the intercept (and other non-treatment variables) random.
* Justification: Although a random intercept will usually give similar results to a stratified intercept, in some situations it may compromise randomisation (as it allows baseline risk information to be shared across trials). Many researchers assume nuisance parameters are common (often because this is the default in software packages), but this is not recommended as it may lead to inappropriate conclusions, as now described. (p. 138) The advantage of the stratified intercept approach is that it makes no assumptions about the distribution of intercepts across trials - and mirrors exactly the two-stage approach. The advantage of the random intercepts approach is that it requires fewer parameters to be estimated and so may reduce model convergence issues. But usually give very similar results. (p. 141 & 143)
3. *__Use trial-specific centering of the treatment variable (and any other included variables, such as prognostic factors) when using ML estimation of a one-stage model with a stratified intercept.__*
* Justification: Simulation studies and mathematical reasoning show that this improves ML estimation of between-trial variances and the coverage of confidence intervals for the summary treatment effect. Centering disentangles (i.e. makes uncorrelated) the estimation of main parameters of interest from other nuisance parameters, which leads to less downward bias in estimates of variance parameters (Figure 6.2) and thus improves coverage of 95% confidence intervals. This can be achieved by centering the covariates by their mean values within trials, such that the interaction estimate is then only based on within-trial information. Our default recommendation is to use stratified prognostic effects (i.e. estimate a separate effect of each included prognostic factor for each trial), with trial-specific centering of each prognostic factor to improve ML estimation (for the reasons explained in Section 6.2.8.3). However, if outcome data or prognostic factor categories are sparse, the stratification approach may lead to estimation difficulties, and then allowing prognostic factor effects to be random is a sensible alternative. (p. 145) As previously discussed (Section 6.2.4.1), Jackson et al. and Riley et al. show that for one-stage models with a stratified intercept, ML estimation is improved when using trial-specific centering of treatment and other included variables.181,185 Centering disentangles (i.e. makes uncorrelated) the estimation of main parameters of interest from other nuisance parameters, which leads to less downward bias in estimates of variance parameters (Figure 6.2) and thus improves coverage of 95% confidence intervals. (p. 147)
4. For frequentist estimation of one-stage models for binary, ordinal or count outcomes, use REML estimation of the pseudo-likelihood approach unless most trials in the meta-analysis are small (in terms of participants or outcome events), which then warrants ML estimation of the exact likelihood.
* Justification: Although estimation of the exact likelihood is preferred, ML estimation is known to produce downwardly biased estimates of between-trial variances. Therefore, unless most included trials are small, REML estimation of an approximate pseudo-likelihood specification may improve estimation of between-trial variances and coverage of confidence intervals.
5. A one-stage IPD meta-analysis utilises a more exact statistical likelihood than a two-stage meta-analysis approach, which is advantageous when included trials have few participants or outcome events. (p.127)
6. The word ‘fixed’ is ambiguous; it could refer to either a common or stratified parameter, even though they imply different model specifications and assumptions. Therefore, we recommend that the word ‘fixed’ be avoided in one-stage IPD models, and encourage researchers to use common or stratified instead.
7. See sample R code here: https://www.ipdma.co.uk/one-stage-ipd-ma
## Present the main model: "r cent trt, s intercept, s and cent age, r clinstatus"
1. Treatment parameter: Random treatment effect
2. Trial parameter: Stratified intercept by trial
3. Prognostic factor 'age': Stratified by trial
4. Prognostic factor 'clinical status': As a random parameter by trial. Not all trials have all levels, hard to estimate a stratified clinstatus_baseline by trial => Random effect as sensible alternative (see guidance above)
5. Trial-specific centering of the treatment variable and age (to improve estimation of the between-study variance).
# (i) Mortality at day 28
```{r}
mort28 <- glmmTMB(mort_28 ~ trt_centered_n
+ trial_f # stratified intercept
+ (trt_centered_n -1 | trial_f) -1 # random treatment effect (and centered)
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3 # stratified prognostic factor age (and centered)
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f) # random prognostic factor clinstatus_baseline
, data = df_tot, family = binomial)
tab_model(mort28)
```
# (ii) Mortality at day 60
```{r warning=FALSE}
addmargins(table(df_tot$mort_60, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$mort_60, df_tot$trial, useNA = "always"))
mort60 <- glmmTMB(mort_60 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = binomial)
tab_model(mort60)
```
# (iii) Time to death within max. follow-up time
```{r warning=FALSE}
# table(df_tot$death_reached, df_tot$death_time, useNA = "always")
# table(df_tot$death_reached, df_tot$mort_60, useNA = "always") # 1 death after day 60 in Bari-Solidact
# df_tot %>%
# drop_na(death_time) %>%
# filter(death_reached == 1) %>%
# group_by(trt) %>%
# summarise(median = median(death_time),
# IQR = IQR(death_time),
# Q1 = quantile(death_time, probs = 0.25),
# Q3 = quantile(death_time, probs = 0.75))
# cap at 60 days // always censor first the censoring variable..
df_tot <- df_tot %>%
mutate(death_reached_60 = case_when(death_time >60 ~ 0,
TRUE ~ c(death_reached)))
df_tot <- df_tot %>%
mutate(death_time_60 = case_when(death_time >60 ~ 60,
TRUE ~ c(death_time)))
## time to death, by group. Kaplan-Meier estimate of conditional survival probability.
# km.ttdeath.check <- with(df_tot, Surv(death_time, death_reached))
# head(km.ttdeath.check, 100)
km.ttdeath_trt <- survfit(Surv(death_time, death_reached) ~ trt, data=df_tot)
# summary(km.ttdeath_trt, times = 28)
ttdeath_28d_tbl <- km.ttdeath_trt %>%
tbl_survfit(
times = 28,
label_header = "**28-d survival (95% CI)**"
)
# Nicely formatted table
kable(ttdeath_28d_tbl, format = "markdown", table.attr = 'class="table"') %>%
kable_styling(bootstrap_options = "striped", full_width = FALSE)
autoplot(km.ttdeath_trt)
survfit2(Surv(death_time, death_reached) ~ trt, data=df_tot) %>%
ggsurvfit() +
labs(
x = "Days",
y = "Overall survival probability"
) +
add_confidence_interval() +
add_risktable()
# autoplot by trial with max. 60d fup
km.ttdeath_trial <- survfit(Surv(death_time_60, death_reached_60) ~ trial, data=df_tot)
autoplot(km.ttdeath_trial)
# Assessing proportional hazards // check the KM curve: OK
# Cox proportional hazards model adhering to main model "r cent trt, s intercept, s and cent age, r clinstatus"
ttdeath <- coxme(Surv(death_time, death_reached) ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot)
tab_model(ttdeath)
```
# (iv) New mechanical ventilation or death within 28 days
```{r warning=FALSE}
addmargins(table(df_tot$new_mvd_28, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$new_mvd_28, df_tot$trial, useNA = "always"))
new.mvd28 <- glmmTMB(new_mvd_28 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = binomial)
tab_model(new.mvd28)
```
# (iv.i) New mechanical ventilation among survivors within 28 days
```{r warning=FALSE}
addmargins(table(df_tot$new_mv_28, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$new_mv_28, df_tot$trial, useNA = "always"))
new.mv28 <- glmmTMB(new_mv_28 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = binomial)
tab_model(new.mv28)
```
# (v) Clinical status at day 28
```{r warning=FALSE}
addmargins(table(df_tot$clinstatus_28_imp, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$clinstatus_28_imp, df_tot$trial, useNA = "always"))
# Ordinal regression model adhering to main model "r cent trt, s intercept, s and cent age, r clinstatus"
clin28 <- df_tot %>%
clmm(clinstatus_28_imp ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1
+ age_cent_trial_2
+ age_cent_trial_3
+ age_cent_trial_4
+ age_cent_trial_5
+ age_cent_trial_6
+ age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ clinstatus_baseline_n
# + (clinstatus_baseline_n -1 | trial_f)
, link= c("logit"), data=.)
tab_model(clin28)
```
# (vi) Time to discharge or reaching discharge criteria up to day 28. Death = Competing event
```{r warning=FALSE}
# table(df_tot$discharge_reached, df_tot$discharge_time, useNA = "always")
# table(df_tot$discharge_reached, df_tot$trial, useNA = "always")
# table(df_tot$discharge_time, df_tot$trial, useNA = "always")
#
# df_tot %>%
# drop_na(discharge_time) %>%
# filter(discharge_reached == 1) %>%
# group_by(trt) %>%
# summarise(median = median(discharge_time),
# IQR = IQR(discharge_time),
# Q1 = quantile(discharge_time, probs = 0.25),
# Q3 = quantile(discharge_time, probs = 0.75))
# Kaplan-Meier estimate of conditional discharge probability
km.ttdischarge.check <- with(df_tot, Surv(discharge_time, discharge_reached))
# head(km.ttdischarge.check, 100)
km.ttdischarge_trt <- survfit(Surv(discharge_time, discharge_reached) ~ trt, data=df_tot)
# summary(km.ttdischarge_trt, times = 28)
ttdischarge_28d_tbl <- km.ttdischarge_trt %>%
tbl_survfit(
times = 28,
label_header = "**28-d hospitalization (95% CI)**"
)
# Nicely formatted table
kable(ttdischarge_28d_tbl, format = "markdown", table.attr = 'class="table"') %>%
kable_styling(bootstrap_options = "striped", full_width = FALSE)
# KM graph
survfit2(Surv(discharge_time, discharge_reached) ~ trt, data=df_tot) %>%
ggsurvfit() +
labs(
x = "Days",
y = "Overall hospitalization probability"
) +
add_confidence_interval() +
add_risktable()
# Assessing proportional hazards (using default discharge_time and discharge_reached) -> see KM plots, after the point when the curves really stqrt diverging, it does not cross over again: OK
# ph.check <- coxph(Surv(discharge_time, discharge_reached) ~ trt
# , data = df_tot)
# cz <- cox.zph(ph.check)
# print(cz)
# plot(cz)
## Sub-distribution hazards, i.e., represents the rate per unit of time of the event as well as the influence of competing events. Instantaneous rate of occurrence of the given type of event in subjects who have not yet experienced an event of that type.
df_tot <- df_tot %>% # cuminc needs a factor variable with censored patients coded as 0, the event as 1 and the competing event as 2.
mutate(discharge_reached_comp = case_when (discharge_reached == 0 & (mort_28 == 0 | is.na(mort_28)) ~ 0,
discharge_reached == 1 & (mort_28 == 0 | is.na(mort_28)) ~ 1,
mort_28 == 1 ~ 2))
df_tot$discharge_reached_comp <- as.factor(df_tot$discharge_reached_comp)
# Cumulative incidence for the event=discharge (1) and the competing event=death (2)
cuminc(Surv(discharge_time, discharge_reached_comp) ~ 1, data = df_tot)
cuminc(Surv(discharge_time, discharge_reached_comp) ~ trt, data = df_tot) %>%
ggcuminc(outcome = c("1", "2")) +
ylim(c(0, 1)) +
labs(
x = "Days"
) +
add_confidence_interval() +
add_risktable()
# in int only
df_int <- df_tot %>%
filter(trt == 1)
cuminc(Surv(discharge_time, discharge_reached_comp) ~ trt, data = df_int) %>%
ggcuminc(outcome = c("1", "2")) +
#ylim(c(0, 1)) +
labs(
x = "Days"
) +
add_confidence_interval() +
add_risktable()
# in cont only
df_cont <- df_tot %>%
filter(trt == 0)
cuminc(Surv(discharge_time, discharge_reached_comp) ~ trt, data = df_cont) %>%
ggcuminc(outcome = c("1", "2")) +
#ylim(c(0, 1)) +
labs(
x = "Days"
) +
add_confidence_interval() +
add_risktable()
# Fine-Gray regression model (Competing Risk regression), adhering to main model "r cent trt, s intercept, s and cent age, r clinstatus"
## problem: How to incorporate clustering and random effects?
### crr has a clustering function - however, cannot add random effects. Probably would need multistate models: https://cran.r-project.org/web/packages/survival/vignettes/compete.pdf
ttdischarge.comp <- crr(Surv(discharge_time, discharge_reached_comp) ~ trt_centered_n
+ cluster(trial_f)
# + (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ clinstatus_baseline_n
# + (clinstatus_baseline_n -1 | trial_f)
,data = df_tot)
ttdischarge_comp_reg_tbl <- tbl_regression(ttdischarge.comp, exp = TRUE)
# Nicely formatted table
kable(ttdischarge_comp_reg_tbl, format = "markdown", table.attr = 'class="table"') %>%
kable_styling(bootstrap_options = "striped", full_width = FALSE)
```
Discussion points:
1. crr has a clustering function - however, cannot add random effects. coxme cannot deal with competing risks. Needs a multistate model? https://cran.r-project.org/web/packages/survival/vignettes/compete.pdf
# (vi.i) Time to discharge or reaching discharge criteria up to day 28. Death = Hypothetical
```{r warning=FALSE}
# Censoring and assigned worst outcome (28d) to competing event (death) // hypothetical estimand where no-one died. (Another option could be, but we don't do it, is to exclude the deaths entirely, i.e. discharge among those that survived (but that might bias in favour of those in control that died more, i.e. healthier comparator))
# Cox proportional hazards model adhering to main model "r cent trt, s intercept, s and cent age, r clinstatus"
ttdischarge.hypo <- coxme(Surv(discharge_time_sens, discharge_reached) ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot)
tab_model(ttdischarge.hypo)
```
# (vi.ii) Time to discharge or reaching discharge criteria up to day 28. Death = Censored
```{r warning=FALSE}
## Censoring the deaths => Cause-specific hazards, i.e., represents the rate per unit of time of the event among those not having failed from other events. Instantaneous rate of occurrence of the given type of event in individuals who are currently event‐free. But by simply censoring the competing event, we bias in favour of comparator (if treatment leads to less deaths)
# Cox proportional hazards model adhering to main model "r cent trt, s intercept, s and cent age, r clinstatus"
ttdischarge.cens <- coxme(Surv(discharge_time, discharge_reached) ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot)
tab_model(ttdischarge.cens)
```
# (vi.iii) Time to sustained discharge or reaching discharge criteria up to day 28. Death = Censored
```{r warning=FALSE}
# Sens-analysis: Alternative definition/analysis of outcome: time to sustained discharge within 28 days
# Use cause-specific hazards
# table(df_tot$discharge_reached_sus, df_tot$discharge_time_sus, useNA = "always")
# table(df_tot$discharge_reached_sus, df_tot$trial, useNA = "always")
# table(df_tot$discharge_time_sus, df_tot$trial, useNA = "always")
# Kaplan-Meier estimate of conditional discharge probability
km.ttdischarge.sus.check <- with(df_tot, Surv(discharge_time_sus, discharge_reached_sus))
# head(km.ttdischarge.sus.check, 100)
km.ttdischarge_sus_trt <- survfit(Surv(discharge_time_sus, discharge_reached_sus) ~ trt, data=df_tot)
# summary(km.ttdischarge_trt, times = 28)
ttdischarge_sus_28d_tbl <- km.ttdischarge_sus_trt %>%
tbl_survfit(
times = 28,
label_header = "**28-d sustained hospitalization (95% CI)**"
)
# Nicely formatted table
kable(ttdischarge_sus_28d_tbl, format = "markdown", table.attr = 'class="table"') %>%
kable_styling(bootstrap_options = "striped", full_width = FALSE)
# KM graph
survfit2(Surv(discharge_time_sus, discharge_reached_sus) ~ trt, data=df_tot) %>%
ggsurvfit() +
labs(
x = "Days",
y = "Overall sustained hospitalization probability"
) +
add_confidence_interval() +
add_risktable()
# Cox proportional hazards model adhering to main model "r cent trt, s intercept, s and cent age, r clinstatus"
ttdischarge.sus <- coxme(Surv(discharge_time_sus, discharge_reached_sus) ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1 + age_cent_trial_2 + age_cent_trial_3
+ age_cent_trial_4 + age_cent_trial_5 + age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot)
tab_model(ttdischarge.sus)
```
# (vii) Viral clearance up to day 5
```{r warning=FALSE}
addmargins(table(df_tot$vir_clear_5, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$vir_clear_5, df_tot$trial, useNA = "always"))
vir.clear5 <- glmmTMB(vir_clear_5 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1
+ age_cent_trial_2
+ age_cent_trial_3
+ age_cent_trial_4
+ age_cent_trial_5
+ age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = binomial)
tab_model(vir.clear5)
```
# (viii) Viral clearance up to day 10
```{r warning=FALSE}
addmargins(table(df_tot$vir_clear_10, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$vir_clear_10, df_tot$trial, useNA = "always"))
vir.clear10 <- glmmTMB(vir_clear_10 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1
+ age_cent_trial_2
+ age_cent_trial_3
+ age_cent_trial_4
+ age_cent_trial_5
+ age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = binomial)
tab_model(vir.clear10)
```
# (ix) Viral clearance up to day 15
```{r warning=FALSE}
addmargins(table(df_tot$vir_clear_15, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$vir_clear_15, df_tot$trial, useNA = "always"))
vir.clear15 <- glmmTMB(vir_clear_15 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1
+ age_cent_trial_2
+ age_cent_trial_3
+ age_cent_trial_4
+ age_cent_trial_5
+ age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = binomial)
tab_model(vir.clear15)
```
# (x) Adverse event(s) grade 3 or 4, or a serious adverse event(s), excluding death, by day 28. ANY
```{r warning=FALSE}
addmargins(table(df_tot$ae_28, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$ae_28, df_tot$trial, useNA = "always"))
ae28 <- glmmTMB(ae_28 ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1
+ age_cent_trial_2
+ age_cent_trial_3
+ age_cent_trial_4
+ age_cent_trial_5
+ age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = binomial)
tab_model(ae28)
```
# (x.i) Adverse event(s) grade 3 or 4, or a serious adverse event(s), excluding death, by day 28. SEVERAL
```{r warning=FALSE}
addmargins(table(df_tot$ae_28_sev, df_tot$trt, useNA = "always"))
addmargins(table(df_tot$ae_28_sev, df_tot$trial, useNA = "always"))
ae28sev <- glmmTMB(ae_28_sev ~ trt_centered_n
+ trial_f
+ (trt_centered_n -1 | trial_f) -1
+ age_cent_trial_1
+ age_cent_trial_2
+ age_cent_trial_3
+ age_cent_trial_4
+ age_cent_trial_5
+ age_cent_trial_6 + age_cent_trial_7 + age_cent_trial_8 + age_cent_trial_9
+ (clinstatus_baseline_n -1 | trial_f)
, data = df_tot, family = poisson) # double-check !
tab_model(ae28sev)
```
# Collect all treatment effect estimates across endpoints
```{r message=FALSE, warning=FALSE}
# Empty data frame to store the results
result_df <- data.frame(
variable = character(),
hazard_odds_ratio = numeric(),
ci_lower = numeric(),
ci_upper = numeric(),
standard_error = numeric(),
p_value = numeric(),
n_intervention = numeric(),
n_intervention_tot = numeric(),
n_control = numeric(),
n_control_tot = numeric()
)