-
Notifications
You must be signed in to change notification settings - Fork 0
/
cov-barrier.Rmd
2282 lines (2106 loc) · 113 KB
/
cov-barrier.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: "COV-BARRIER"
author: "A.Amstutz"
date: "2023-11-05"
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(haven) # Read sas files
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(tidycmprsk) # competing risk analysis
library(ordinal) # clinstatus ordinal regression
library(logistf) # Firth regression in case of rare events
library(finalfit) # missing data exploration
library(mice) # multiple imputation
library(jomo) # multiple imputation
library(mitools) # multiple imputation
```
# Load Data
```{r, include=FALSE}
# SDTM_KHAA_final_new
# df_adverse_events <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ae.sas7bdat")
# df_adverse_events_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppae.sas7bdat")
# df_clinclass <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/cc.sas7bdat")
# df_clinevent <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ce.sas7bdat")
# df_comed <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/cm.sas7bdat")
# df_comed_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppcm.sas7bdat")
# df_demographics <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/dm.sas7bdat")
# df_demographics_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppdm.sas7bdat")
# df_disco <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ds.sas7bdat")
# df_prot_dev <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/dv.sas7bdat")
# df_prot_dev_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppdv.sas7bdat")
# df_dose_details <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ec.sas7bdat")
# df_dose_details_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppec.sas7bdat")
# df_dose_details2 <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ex.sas7bdat")
# df_death_SE <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/fa.sas7bdat")
# df_death_SE_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppfa.sas7bdat")
# df_hosp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ho.sas7bdat")
# df_lab <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/lb.sas7bdat")
# df_lab_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/supplb.sas7bdat")
# df_lab_ext <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/xl.sas7bdat")
# df_lab_ext_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppxl.sas7bdat")
df_microbio <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/mb.sas7bdat")
# df_medicalhist <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/mh.sas7bdat")
# df_medicalhist_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppmh.sas7bdat")
# df_resp_procedure <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/pr.sas7bdat")
# df_resp_procedure_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/supppr.sas7bdat")
# df_rel_CM_AE <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/relrec.sas7bdat")
# # df_do_not_intubate <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/sc.sas7bdat")
# # df_do_not_intubate_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppsc.sas7bdat")
# # df_unknown <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/se.sas7bdat")
# df_death <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ss.sas7bdat")
# df_substance_use <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/su.sas7bdat")
df_substance_use_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppsu.sas7bdat")
# df_subj_visits <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/sv.sas7bdat")
# df_subj_visit_findings <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/xv.sas7bdat")
# # df_unknown <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ta.sas7bdat")
# # df_unknown <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/te.sas7bdat")
# # df_screen_exclusions <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ti.sas7bdat")
# # df_trial_info <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/ts.sas7bdat")
# # df_trial_info2 <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/tv.sas7bdat")
# df_vitalsigns <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/vs.sas7bdat")
# df_vitalsigns_suppO2 <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppvs.sas7bdat")
# df_chest_imaging <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/xp.sas7bdat")
# df_chest_imaging_supp <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/SDTM_KHAA_final_new/suppxp.sas7bdat")
# ADaM_KHAA_final_new
df_ae_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adae.sas7bdat")
df_comed_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adcm.sas7bdat")
df_disco_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adds.sas7bdat")
# df_prot_dev_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/addv.sas7bdat")
# df_dose_details_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adex.sas7bdat")
df_lab_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adlb.sas7bdat")
# df_lab_ext_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adlbcn.sas7bdat")
df_medicalhist_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/admh.sas7bdat")
df_niaid_score_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adniaid.sas7bdat")
df_ind_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adsl.sas7bdat")
# df_ind2_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adsl2.sas7bdat")
df_tte_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adtte.sas7bdat")
# df_tte2_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/adtte2.sas7bdat")
# df_vitalsigns_set <- read_sas("/Users/amstutzal/Library/CloudStorage/OneDrive-usb.ch/Dokumente - JAKi IPDMA data source management/General/COV-BARRIER/ADaM_KHAA_final_new/advs.sas7bdat")
```
# Define ITT population and mark COV-BARRIER and COV-BARRIER expl.
```{r echo=TRUE}
df <- df_ind_set %>% # keep only those randomized
filter(RANDFL == "Y")
df <- df %>% # mark COV-BARRIER (main trial, all severity except MV/ECMO) and COV-BARRIER exploratory (only MV/ECMO)
mutate(subtrial = case_when(BNIAID == "7" ~ "COV-BARRIER_MV",
TRUE ~ c("COV-BARRIER_main")))
addmargins(table(df$ARM, df$subtrial))
```
# Baseline Characteristics
```{r echo=TRUE, message=FALSE, warning=FALSE}
df <- df %>% # no missing in all these
rename(id_pat = SUBJID,
country = COUNTRY,
randdate = RANDDT
)
df <- df %>% # COV-BARRIER exploratory (only MV/ECMO) were recruited in ICU
mutate(icu = case_when(subtrial == "COV-BARRIER_MV" ~ 1,
TRUE ~ 0))
df <- df %>%
mutate(trt = case_when(ARM == "Baricitinib-4mg-QD" ~ 1,
TRUE ~ 0))
# add trial variables
df$trial <- c("COV-BARRIER")
df$JAKi <- c("Baricitinib")
df <- df %>% # no missing in sex
mutate(sex = case_when(SEX == "F" ~ "female",
SEX == "M" ~ "male"))
# Ethnicity
df <- df %>% # no missing in ethnicity
mutate(ethn = case_when(RACE == "UNKNOWN" & ETHNIC == "HISPANIC OR LATINO" ~ "HISPANIC OR LATINO",
TRUE ~ c(RACE)))
# AGE: add 90 to ages ">89" // age data also not available in df_demographics due to anonymization
df$age <- as.numeric(df$AGE)
df <- df %>%
mutate(age = case_when(is.na(age) ~ 90,
TRUE ~ c(age)))
df %>%
drop_na(age) %>%
ggplot(aes(x = age)) +
geom_density(fill = "blue", color = "black") +
labs(title = "Density Plot of Age",
x = "Age",
y = "Density")
# Days with symptoms prior to randomization
df <- df %>%
mutate(sympdur = case_when(SYMHDUR == "-24" ~ "0",
SYMHDUR == "-22" ~ "0",
SYMHDUR == "-16" ~ "0",
SYMHDUR == "-15" ~ "0",
SYMHDUR == "-8" ~ "0",
TRUE ~ c(SYMHDUR)))
df$sympdur <- as.numeric(df$sympdur)
df %>%
drop_na(sympdur) %>%
ggplot(aes(x = sympdur)) +
geom_density(fill = "blue", color = "black") +
labs(title = "Density Plot of Symptom Duration",
x = "Symptom Duration",
y = "Density")
# Severity of COVID-19 with respect to respiratory support at randomisation, according to NIAID score
# transform all clinical scores
score_transform <- function(df, clinstatus_var, score_var) {
df <- df %>%
mutate({{ clinstatus_var }} :=
case_when({{ score_var }} %in% c(1, 2, 3) ~ 1,
{{ score_var }} == 4 ~ 2,
{{ score_var }} == 5 ~ 3,
{{ score_var }} == 6 ~ 4,
{{ score_var }} == 7 ~ 5,
{{ score_var }} == 8 ~ 6)) %>%
mutate({{ clinstatus_var }} := factor({{ clinstatus_var }}, levels = 1:6))
}
df <- score_transform(df, clinstatus_baseline, BNIAIDN)
# addmargins(table(df$clinstatus_baseline, df$trt, useNA = "always")) # 7 missing
# addmargins(table(df$clinstatus_baseline, df$trt, df$subtrial, useNA = "always")) # 7 missing in COV-BARRIER main, no missing in COV-BARRIER 2 // # corresponds to publications
df <- df %>%
mutate(vbaseline = case_when(clinstatus_baseline == "2" | clinstatus_baseline == "3" ~ 0,
clinstatus_baseline == "4" | clinstatus_baseline == "5" ~ 1))
### Co-medication at baseline
# table(df$BLSTRFN, df$trt, df$subtrial, useNA = "always") # corresponds to publications
# table(df$BRMDSVFL, df$trt, df$subtrial, useNA = "always") # corresponds to publications
# check df_comed_set for prior/baseline co-medications for the following:
df$comed_toci <- 0 # excluded according to protocol
df$comed_acoa <- NA
df$comed_interferon <- 0 # excluded according to protocol
df <- df %>%
mutate(comed_dexa = case_when(BLSTRFN == 1 ~ 1,
BLSTRFN == 0 ~ 0))
df <- df %>%
mutate(comed_rdv = case_when(BRMDSVFL == "Y" ~ 1,
TRUE ~ 0))
df <- df %>%
mutate(comed_ab = case_when(PTHANTBI == "Y" ~ 1,
TRUE ~ 0))
df <- df %>%
mutate(comed_other = case_when(PTHOTH == "Y" ~ 1,
TRUE ~ 0))
# group them for the subgroup analysis, according to protocol
df <- df %>%
mutate(comed_cat = case_when(comed_dexa == 0 & (comed_toci == 0 | is.na(comed_toci)) ~ 1, # patients without Dexamethasone nor Tocilizumab
comed_dexa == 1 & (comed_toci == 0 | is.na(comed_toci)) ~ 2, # patients with Dexamethasone but no Tocilizumab
comed_dexa == 1 & comed_toci == 1 ~ 3, # patients with Dexamethasone and Tocilizumab
comed_dexa == 0 & comed_toci == 1 ~ 4)) # patients with Tocilizumab but no Dexamethasone (if exist)
### Comorbidity at baseline, including immunocompromised
df <- df %>%
mutate(comorb_dm = case_when(CMRDFL == "Y" ~ 1,
CMRDFL == "N" ~ 0))
df <- df %>%
mutate(comorb_obese = case_when(CMROFL == "Y" ~ 1,
CMROFL == "N" ~ 0))
df <- df %>%
mutate(comorb_aht = case_when(CMRHFL == "Y" ~ 1,
CMRHFL == "N" ~ 0))
df <- df %>%
mutate(comorb_lung = case_when(CMRCFL == "Y" ~ 1,
CMRCFL == "N" ~ 0))
df <- df %>%
mutate(comorb_kidney = case_when(BRNLGR1 == "Impaired" ~ 1,
TRUE ~ 0))
# take it from medicalhistory dataset
df_medicalhist_set <- df_medicalhist_set %>%
mutate(comorb_cancer = case_when((grepl("Cancer", ALLT) | grepl("cancer", ALLT) | grepl("neoplasm", ALLT) | grepl("Neoplasm", ALLT) | grepl("carcinoma", ALLT) | grepl("Carcinoma", ALLT)) ~ 1))
df_medicalhist_set <- df_medicalhist_set %>%
mutate(comorb_liver = case_when(ALLT == "Chronic liver disease" ~ 1))
df_medicalhist_set <- df_medicalhist_set %>%
mutate(comorb_cvd = case_when(ASOC == "Cardiac disorders" ~ 1))
df_medicalhist_set <- df_medicalhist_set %>%
mutate(immunosupp = case_when((grepl("immune deficiency", ALLT) | grepl("Chemo", ALLT) | grepl("Radio", ALLT)) ~ 1))
df_medicalhist_set <- df_medicalhist_set %>%
mutate(comorb_autoimm = case_when((grepl("rheuma", ALLT) | grepl("Rheuma", ALLT) | grepl("immune", ALLT) | grepl("immune", ASOC) | grepl("immune", ADECOD)) & is.na(immunosupp) ~ 1))
# remove duplicates
df_comorb_cancer <- df_medicalhist_set %>%
filter(comorb_cancer == 1) %>%
distinct(USUBJID,comorb_cancer)
df_comorb_liver <- df_medicalhist_set %>%
filter(comorb_liver == 1) %>%
distinct(USUBJID,comorb_liver)
df_comorb_cvd <- df_medicalhist_set %>%
filter(comorb_cvd == 1) %>%
distinct(USUBJID,comorb_cvd)
df_immunosupp <- df_medicalhist_set %>%
filter(immunosupp == 1) %>%
distinct(USUBJID,immunosupp)
df_comorb_autoimm <- df_medicalhist_set %>%
filter(comorb_autoimm == 1) %>%
distinct(USUBJID,comorb_autoimm)
# merge
df <- left_join(df, df_comorb_cancer[, c("comorb_cancer", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
df <- left_join(df, df_comorb_liver[, c("comorb_liver", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
df <- left_join(df, df_comorb_cvd[, c("comorb_cvd", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
df <- left_join(df, df_immunosupp[, c("immunosupp", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
df <- left_join(df, df_comorb_autoimm[, c("comorb_autoimm", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
# take smoking from substance use set
df_substance_use_supp <- df_substance_use_supp %>%
mutate(comorb_smoker = case_when(QVAL == "CURRENT" ~ 1))
df_comorb_smoker <- df_substance_use_supp %>%
filter(comorb_smoker == 1) %>%
distinct(USUBJID,comorb_smoker)
df <- left_join(df, df_comorb_smoker[, c("comorb_smoker", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
# the remaining missing have only NA in 1 comorb category => no evidence for comorbidity -> recode as 0
# table(df$PTHIMMSP)
df <- df %>%
mutate(comorb_cancer = case_when(is.na(comorb_cancer) ~ 0,
TRUE ~ c(comorb_cancer)),
comorb_liver = case_when(is.na(comorb_liver) ~ 0,
TRUE ~ c(comorb_liver)),
comorb_cvd = case_when(is.na(comorb_cvd) ~ 0,
TRUE ~ c(comorb_cvd)),
immunosupp = case_when(is.na(immunosupp) ~ 0,
TRUE ~ c(immunosupp)),
comorb_autoimm = case_when(is.na(comorb_autoimm) ~ 0,
TRUE ~ c(comorb_autoimm)),
comorb_smoker = case_when(is.na(comorb_smoker) ~ 0,
TRUE ~ c(comorb_smoker)))
df <- df %>%
mutate(any_comorb = case_when(comorb_lung == 1 | comorb_liver == 1 | comorb_cvd == 1 |
comorb_aht == 1 | comorb_dm == 1 | comorb_obese == 1 | comorb_smoker == 1
| immunosupp == 1 | comorb_cancer == 1 | comorb_autoimm == 1 | comorb_kidney == 1
~ 1,
comorb_lung == 0 & comorb_liver == 0 & comorb_cvd == 0 &
comorb_aht == 0 & comorb_dm == 0 & comorb_obese == 0 & comorb_smoker == 0
& immunosupp == 0 & comorb_cancer == 0 & comorb_autoimm == 0 & comorb_kidney == 0
~ 0))
# addmargins(table(df$any_comorb, df$trt, useNA = "always"))
## group them for the subgroup analysis, according to protocol // count all pre-defined comorbidities per patient first
comorb <- df %>%
select(id_pat, comorb_lung, comorb_liver, comorb_cvd, comorb_aht, comorb_dm, comorb_obese, comorb_smoker, immunosupp, comorb_kidney, comorb_autoimm, comorb_cancer)
comorb$comorb_count <- NA
for (i in 1:dim(comorb)[[1]]) {
comorb$comorb_count[i] <- ifelse(
sum(comorb[i, ] %in% c(1)) > 0,
sum(comorb[i, ] %in% c(1)),
NA
)
}
comorb <- comorb %>%
mutate(comorb_count = case_when(comorb_lung == 0 & comorb_liver == 0 & comorb_cvd == 0 &
comorb_aht == 0 & comorb_dm == 0 & comorb_obese == 0 & comorb_smoker == 0
& immunosupp == 0 & comorb_cancer == 0 & comorb_autoimm == 0 & comorb_kidney == 0 ~ 0,
TRUE ~ comorb_count))
df <- left_join(df, comorb[, c("comorb_count", "id_pat")], by = join_by(id_pat == id_pat)) ## merge imputed variable back
df <- df %>%
mutate(comorb_cat = case_when(immunosupp == 1 ~ 4, # immunocompromised
comorb_count == 0 ~ 1, # no comorbidity
comorb_count == 1 ~ 2, # one comorbidity
comorb_count >1 & (immunosupp == 0 | is.na(immunosupp)) ~ 3)) # multiple comorbidities
# addmargins(table(df$comorb_cat, df$trt, useNA = "always"))
df <- df %>%
mutate(comorb_any = case_when(comorb_count == 0 ~ 0, # no comorbidity
comorb_count >0 ~ 1)) # any comorbidity
## CRP
df_crp <- df_lab_set %>%
filter(LBTESTCD == "CRP") %>%
filter(VISIT == "Screening") %>%
filter(AVISITN == 1)
df_crp <- df_crp %>%
distinct(USUBJID, .keep_all = TRUE)
df_crp <- df_crp %>%
rename(crp = LBSTRESN)
df <- left_join(df, df_crp[, c("crp", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
df %>%
drop_na(crp) %>%
ggplot(aes(x = crp)) +
geom_density(fill = "blue", color = "black") +
labs(title = "Density Plot of Symptom Duration",
x = "CRP",
y = "Density")
# Viremia dataset
df_viremia <- df_microbio %>%
filter(MBTESTCD != "MBALL") %>%
filter(MBTSTDTL == "DETECTION") %>%
filter(MBBLFL == "Y")
df_viremia <- df_viremia %>%
distinct(USUBJID, .keep_all = TRUE)
df_viremia <- df_viremia %>% # viral load value <LOQ and/or undectectable
mutate(vl_baseline = case_when(MBORRES == "POSITIVE" ~ 0,
TRUE ~ 1))
df <- left_join(df, df_viremia[, c("vl_baseline", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
# Vaccination // not available
# Variant // not available
# Serology // not available
```
# Endpoints
```{r echo=TRUE}
# (i) Primary outcome: Mortality at day 28
df_ttd <- df_tte_set %>% # death set
filter(PARAM == "Time to Death by Day 28") %>%
filter(RANDFL == "Y") # only randomised population
# discontinuation set
df_disco_any <- df_disco_set %>%
filter(DSDECOD != "COMPLETED" & DSDECOD != "DEATH") %>% # any other reason than these
filter(RANDFL == "Y") %>% # only randomized population
filter(DSSCAT == "STUDY DISPOSITION"| DSSCAT == "TREATMENT DISPOSITION") %>% # full study dispo, not only treatment or drug dispo
distinct(USUBJID, ADT, EPOCH, DSDECOD, DSTERM)
df_disco_any <- df_disco_any %>%
mutate(dupl = ifelse(duplicated(select(., USUBJID, ADT)), 1, 0))
df_disco_any <- df_disco_any %>%
filter(dupl == 0)
df_disco_any <- df_disco_any %>%
mutate(dupl2 = ifelse(duplicated(select(., USUBJID)), 1, 0))
df_disco_any <- df_disco_any %>%
filter(dupl2 == 0)
df_ttd <- left_join(df_ttd, df_disco_any[, c("ADT", "EPOCH", "DSDECOD", "DSTERM", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
# mark those that were censored before day 28 (i.e. stop of follow up, not because of discharge or death, but because of AE/withdrawal/LTFU/etc.)
df_ttd <- df_ttd %>%
mutate(disco_28 = case_when(AVAL <28 & CNSR == 1 ~ 1,
TRUE ~ 0))
df_ttd <- df_ttd %>% # identify deaths
mutate(mort_28 = case_when(EVNTDESC == "Death on or before Day 28" ~ 1,
disco_28 == 0 ~ 0
))
df <- left_join(df, df_ttd[, c("mort_28", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
addmargins(table(df$mort_28, df$trt, df$subtrial, useNA = "always")) # corresponds to publications: "*159 deaths were reported by day 28; an additional three deaths occurred after the treatment period disposition but within 28 days."
# First, keep mort_28 as complete case
# Second, use multiple imputation (see below)
# Third, apply a deterministic imputation (see notes): we use the same rules as ACTT2 => transfer that died are already accounted for, for the remaining -> assign "alive"
df <- df %>%
mutate(mort_28_dimp = case_when(is.na(mort_28) ~ 0,
TRUE ~ c(mort_28)))
# (ii) Mortality at day 60
df_ttd <- df_tte_set %>%
filter(PARAM == "Time to Death by Day 60") %>%
filter(RANDFL == "Y") # only randomised population
df_ttd <- left_join(df_ttd, df_disco_any[, c("ADT", "EPOCH", "DSDECOD", "DSTERM", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge all disco
df_ttd <- df_ttd %>% # mark those that were censored before day 60 (i.e. stop of follow up, not because of discharge or death, but because of AE/withdrawal/LTFU/etc.)
mutate(disco_60 = case_when(AVAL <60 & CNSR == 1 & !is.na(DSTERM) ~ 1,
TRUE ~ 0))
df_ttd <- df_ttd %>% # identify deaths using the censoring variable
mutate(mort_60 = case_when(CNSR == 0 ~ 1,
disco_60 == 0 ~ 0))
df <- left_join(df, df_ttd[, c("mort_60", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
addmargins(table(df$mort_60, df$trt, df$subtrial, useNA = "always"))
# (iii) Time to death within max. follow-up time (systematically until 60 days!)
df_ttd <- df_tte_set %>%
filter(PARAM == "Time to Death") %>%
filter(RANDFL == "Y")
df_ttd <- df_ttd %>% # use censoring variable to identify deaths within 28 days, don't bother about the others
mutate(death_reached = case_when(CNSR == 0 ~ 1,
CNSR == 1 ~ 0))
df_ttd$death_time <- df_ttd$AVAL
df <- left_join(df, df_ttd[, c("death_reached", "death_time", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
# table(df$death_time, df$death_reached, useNA = "always")
# Cap at 60 days, since this was max. systematic follow-up, no deaths recorded afterwards anymore
df <- df %>%
mutate(death_time = case_when(death_time >60 ~ 60,
TRUE ~ c(death_time)))
# (iv) Alternative definition/analysis: New mechanical ventilation OR death within 28 days
# table(df_tte_set$PARAM)
df_mvd <- df_tte_set %>%
filter(PARAM == "Time to progression to invasive ventilation or death (OS >= 7)") %>% # include the deaths, in order not to miss any event (subtract them in the end)
filter(RANDFL == "Y") # only randomised population
df_mvd$tt_mv <- df_mvd$AVAL # time to MV (incl. censoring for those dead or last available visit) -> incl. longer than 28d!
df_mvd <- left_join(df_mvd, df_disco_any[, c("ADT", "EPOCH", "DSDECOD", "DSTERM", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge all disco
df_mvd <- df_mvd %>% # mark those that were discontinued before day 28 (i.e. stop of follow up, not because of discharge or death, but because of AE/withdrawal/LTFU/etc.)
mutate(disco_28_mvd = case_when(AVAL <28 & CNSR == 1 & !is.na(DSTERM) ~ 1,
TRUE ~ 0))
df_mvd <- df_mvd %>% # identify deaths using the censoring variable
mutate(new_mvd_28 = case_when(CNSR == 0 & tt_mv < 29 ~ 1,
disco_28_mvd == 0 ~ 0))
df <- left_join(df, df_mvd[, c("new_mvd_28", "disco_28_mvd", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
# table(df$new_mvd_28, df$mort_28, useNA = "always")
# table(df$clinstatus_baseline, df$new_mvd_28, useNA = "always")
# table(df$new_mvd_28, useNA = "always")
# table(df$mort_28, useNA = "always")
# (iv) New mechanical ventilation among survivors within 28 days
# table(df_tte_set$PARAM)
df_mv <- df_tte_set %>%
filter(PARAM == "Time to invasive ventilation (OS =7)") %>%
filter(RANDFL == "Y") # only randomised population
df_mv$tt_mv <- df_mv$AVAL # time to MV (incl. censoring for those dead or last available visit) -> incl. longer than 28d!
df_mv <- left_join(df_mv, df_disco_any[, c("ADT", "EPOCH", "DSDECOD", "DSTERM", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge all disco
df_mv <- df_mv %>% # mark those that were discontinued before day 28 (i.e. stop of follow up, not because of discharge or death, but because of AE/withdrawal/LTFU/etc.)
mutate(disco_28_mv = case_when(AVAL <28 & CNSR == 1 & !is.na(DSTERM) ~ 1,
TRUE ~ 0))
df_mv <- df_mv %>% # identify deaths using the censoring variable
mutate(new_mv_28 = case_when(CNSR == 0 & tt_mv < 29 ~ 1,
disco_28_mv == 0 ~ 0))
df <- left_join(df, df_mv[, c("new_mv_28", "disco_28_mv", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
# table(df$new_mv_28, df$mort_28, useNA = "always")
# table(df$clinstatus_baseline, df$new_mv_28, useNA = "always")
# table(df$new_mv_28, useNA = "always")
# table(df$mort_28, useNA = "always")
# classify those dead within 28d and those that were MV at baseline as NA ("among survivors")
df <- df %>%
mutate(new_mv_28 = case_when(mort_28 == 1 | clinstatus_baseline == 5 ~ NA,
TRUE ~ c(new_mv_28)))
# table(df$new_mv_28, df$mort_28, useNA = "always")
# table(df$new_mv_28, df$clinstatus_baseline, useNA = "always")
# # see missing data rule: the 7 with no clinstatus at all, not even baseline clinstatus -> assume clinstatus == 5
# df <- df %>%
# mutate(new_mv_28 = case_when(is.na(clinstatus_baseline) ~ 1,
# TRUE ~ c(new_mv_28)))
# (vi) Time to discharge or reaching discharge criteria up to day 28
df_ttdis <- df_tte_set %>%
filter(PARAM == "Time to recovery by Day 28 (OS <=3)") %>%
filter(RANDFL == "Y")
df_ttdis$discharge_time <- df_ttdis$AVAL # time to discharge -> longer than 28d!
# table(df_ttdis$EVNTDESC, df_ttdis$discharge_time) # CAVE: Those that died have all assigned 28 days!
df_ttdis <- df_ttdis %>% # use censoring variable to identify MV
mutate(discharge_reached = case_when(discharge_time < 29 & CNSR == 0 ~ 1,
TRUE ~ 0))
# table(df_ttdis$discharge_reached, df_ttdis$discharge_time, useNA = "always")
df <- left_join(df, df_ttdis[, c("discharge_reached", "discharge_time", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
df <- df %>% # add time to death for those that died
mutate(discharge_time = case_when(mort_28 == 1 ~ death_time,
TRUE ~ discharge_time))
df <- df %>% # Cap at 28 days
mutate(discharge_time = case_when(discharge_time >28 ~ 28,
TRUE ~ c(discharge_time)))
# table(df$discharge_reached, df$discharge_time, useNA = "always")
df <- df %>% # add 28d for those that died // Patients who died prior to day 28 are assumed not having reached discharge, i.e. counted as 28 days
mutate(discharge_time_sens = case_when(mort_28 == 1 ~ 28,
TRUE ~ discharge_time))
# table(df$discharge_reached, df$discharge_time_sens, useNA = "always") -> correct. Corresponds to # table(df_ttdis$discharge_reached, df_ttdis$discharge_time, useNA = "always")
# (v) Clinical status at day 28
## first, curate clinical score long format dataset
df_cs_long <- df_niaid_score_set %>%
filter(PARAM == "NIAID OS Scale") %>%
filter(ABLFL != "Y") %>% # remove baseline clinicalstatus
filter(VISIT != "") # remove missed visits that were LOVCF
df_cs_long <- score_transform(df_cs_long, clinstatus, AVAL) # transform the NIAID score to our score
# second, reformat into wide format
df_cs_wide <- df_cs_long %>% ## the ones with missing baseline clinstatus are missing
pivot_wider(id_cols = c("USUBJID"),
names_from = "VISIT",
values_from = "clinstatus")
# table(df_cs_wide$`Day 28`)
df <- left_join(df, df_cs_wide, by = join_by(USUBJID == USUBJID)) # Merge imputed variable back
df <- df %>%
rename(clinstatus_1 = Screening,
clinstatus_2 = `Day 2`,
clinstatus_3 = `Day 3`,
clinstatus_4 = `Day 4`,
clinstatus_5 = `Day 5`,
clinstatus_6 = `Day 6`,
clinstatus_7 = `Day 7`,
clinstatus_8 = `Day 8`,
clinstatus_9 = `Day 9`,
clinstatus_10 = `Day 10`,
clinstatus_11 = `Day 11`,
clinstatus_12 = `Day 12`,
clinstatus_13 = `Day 13`,
clinstatus_14 = `Day 14`,
clinstatus_15 = `Day 15`,
clinstatus_16 = `Day 16`,
clinstatus_17 = `Day 17`,
clinstatus_18 = `Day 18`,
clinstatus_19 = `Day 19`,
clinstatus_20 = `Day 20`,
clinstatus_21 = `Day 21`,
clinstatus_22 = `Day 22`,
clinstatus_23 = `Day 23`,
clinstatus_24 = `Day 24`,
clinstatus_25 = `Day 25`,
clinstatus_26 = `Day 26`,
clinstatus_27 = `Day 27`,
clinstatus_28 = `Day 28`,
clinstatus_29 = `Follow-up`,
clinstatus_30 = `Final Status`,
clinstatus_60 = `Follow-Up Day 60`)
## Imputation according to protocol: If there was daily data for the ordinal score available but with missing data for single days, then we carried last observed value forward unless for day 28, whereby we first considered data from the window (+/-3 days) but there was nothing in that window => LVCF
# table(df$clinstatus_baseline, useNA = "always")
df <- df %>% # see imputation rules
mutate(clinstatus_baseline_imp = case_when(is.na(clinstatus_baseline) ~ "5",
TRUE ~ clinstatus_baseline))
dfcs <- df %>%
select(USUBJID, clinstatus_baseline_imp, clinstatus_1, clinstatus_2, clinstatus_3, clinstatus_4, clinstatus_5, clinstatus_6, clinstatus_7, clinstatus_8, clinstatus_9, clinstatus_10, clinstatus_11, clinstatus_12, clinstatus_13, clinstatus_14, clinstatus_15, clinstatus_16, clinstatus_17, clinstatus_18, clinstatus_19, clinstatus_20, clinstatus_21, clinstatus_22, clinstatus_23, clinstatus_24, clinstatus_25, clinstatus_26, clinstatus_27, clinstatus_28)
impute_last_forw = function(df){
first = which(names(df)%in%c("clinstatus_baseline_imp"))
last = which(names(df)%in%c("clinstatus_28"))
for (i in 1:dim(df)[[1]]){
for (j in first[1]:last[1]){
p = df[i, j]
df[i,j] <-
ifelse(!is.na(df[i, j]), p, df[i, j-1])
}
}
df
}
dfcs <- impute_last_forw(dfcs)
dfcs <- dfcs %>% # To control, don't overwrite
rename(clinstatus_28_imp = clinstatus_28)
df <- left_join(df, dfcs[, c("clinstatus_28_imp", "USUBJID")], by = join_by(USUBJID == USUBJID)) # Merge imputed variable back
# table(df$clinstatus_28, useNA = "always")
# table(df$clinstatus_28_imp, useNA = "always") # imputed
# df %>% # these ones were discharged, but then readmitted (1 even died, but after day 28)
# filter(clinstatus_28 != 1 & discharge_reached == 1) %>%
# select(discharge_reached, discharge_time, clinstatus_28, clinstatus_baseline, mort_28, mort_60, new_mvd_28, new_mv_28, everything()) %>%
# View()
# (vi) Sens-analysis: Alternative definition/analysis of outcome: time to sustained discharge within 28 days. There are 8 re-admissions documented in COV-BARRIER
df <- df %>%
mutate(discharge_reached_sus = case_when(discharge_reached == 1 & clinstatus_28 != 1 ~ 0,
TRUE ~ c(discharge_reached)))
df <- df %>%
mutate(discharge_time_sus = case_when(discharge_reached == 1 & clinstatus_28 != 1 ~ 28,
TRUE ~ c(discharge_time)))
# table(df$discharge_reached_sus, df$discharge_reached)
# (vii) Viral clearance up to day 5, day 10, and day 15 (Viral load value <LOQ and/or undectectable)
df_viremia <- df_microbio %>%
filter(MBTESTCD != "MBALL") %>%
filter(MBTSTDTL == "DETECTION")
# table(df_viremia$VISITNUM, useNA = "always") # the NAs are not relevant: They are either from before randomization or after day 15
df_viremia <- df_viremia %>%
filter(VISITNUM %in% c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))
df_viremia <- df_viremia %>% # viral load value <LOQ and/or undectectable
mutate(vl = case_when(MBORRES == "POSITIVE" ~ 0,
MBORRES == "NEGATIVE" ~ 1))
# Filtering and extracting the last measurement for each participant
df_vir_clear_5 <- df_viremia %>%
filter(VISITNUM <= 5) %>%
group_by(SUBJID) %>%
slice_max(VISITNUM)
df_vir_clear_5$vir_clear_5 <- df_vir_clear_5$vl
# Check for duplicates in SUBJID and VL
df_vir_clear_5 <- df_vir_clear_5 %>%
mutate(participant_duplicate = duplicated(SUBJID) | duplicated(SUBJID, fromLast = TRUE))
df_vir_clear_5 <- df_vir_clear_5 %>% # remove exact duplicates
distinct(SUBJID, vir_clear_5, .keep_all = TRUE)
specific_duplicates <- any(duplicated(df_vir_clear_5[, c("SUBJID")]))
df_vir_clear_10 <- df_viremia %>%
filter(VISITNUM <= 10) %>%
group_by(SUBJID) %>%
slice_max(VISITNUM)
df_vir_clear_10$vir_clear_10 <- df_vir_clear_10$vl
# Check for duplicates in SUBJID and VL
df_vir_clear_10 <- df_vir_clear_10 %>%
mutate(participant_duplicate = duplicated(SUBJID) | duplicated(SUBJID, fromLast = TRUE))
df_vir_clear_10 <- df_vir_clear_10 %>% # remove exact duplicates
distinct(SUBJID, vir_clear_10, .keep_all = TRUE)
specific_duplicates <- any(duplicated(df_vir_clear_10[, c("SUBJID")]))
df_vir_clear_15 <- df_viremia %>%
filter(VISITNUM <= 15) %>%
group_by(SUBJID) %>%
slice_max(VISITNUM)
df_vir_clear_15$vir_clear_15 <- df_vir_clear_15$vl
# Check for duplicates in SUBJID and VL
df_vir_clear_15 <- df_vir_clear_15 %>%
mutate(participant_duplicate = duplicated(SUBJID) | duplicated(SUBJID, fromLast = TRUE))
df_vir_clear_15 <- df_vir_clear_15 %>% # remove exact duplicates
distinct(SUBJID, vir_clear_15, .keep_all = TRUE)
specific_duplicates <- any(duplicated(df_vir_clear_15[, c("SUBJID")]))
df <- left_join(df, df_vir_clear_5[, c("vir_clear_5", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
df <- left_join(df, df_vir_clear_10[, c("vir_clear_10", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
df <- left_join(df, df_vir_clear_15[, c("vir_clear_15", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge to main df
# (viii) Quality of life at day 28: Not available in COV-BARRIER
# (ix) Participants with an adverse event grade 3 or 4, or a serious adverse event, excluding death, by day 28
# unique(df_ae_set$ASTDY)
df_ae34 <- df_ae_set %>%
filter(AESEV == "SEVERE" | AESEV == "MODERATE" | AESER == "Y") %>%
filter(ASTDY <29)
# Keep just 1 id_pat (-> ANY adverse event grade 3 (severe), 4 (serious))
df_ae34_unique <- df_ae34 %>% distinct(USUBJID, .keep_all = TRUE)
# Assign the outcome
df_ae34_unique$ae_28 <- 1
# table(df_ae34_unique$ae_28)
# merge
df <- left_join(df, df_ae34_unique[, c("ae_28", "USUBJID")], by = join_by(USUBJID == USUBJID)) ## merge variable to main df
# the remaining missing have no AE grade 34 -> recode as 0 and exclude deaths
df <- df %>%
mutate(ae_28 = case_when(is.na(ae_28) & mort_28 == 0 ~ 0,
is.na(ae_28) & mort_28 == 1 ~ NA,
TRUE ~ ae_28))
df <- df %>%
mutate(ae_28 = case_when(mort_28 == 1 ~ NA,
TRUE ~ ae_28))
# table(df$ae_28, df$mort_28, useNA = "always")
# addmargins(table(df$ae_28, df$trt, useNA = "always"))
# (ix) Sens-analysis: Alternative definition/analysis of outcome: incidence rate ratio (Poisson regression) -> AE per person by d28
ae_npp <- df_ae34 %>%
group_by(USUBJID)%>%
summarise(ae_28_sev = n())
df <- left_join(df, ae_npp[, c("ae_28_sev", "USUBJID")], by = join_by(USUBJID == USUBJID)) # merge variable to main df
# the remaining missing have no AE grade 34 -> recode as 0 and exclude deaths
df <- df %>%
mutate(ae_28_sev = case_when(is.na(ae_28_sev) & mort_28 == 0 ~ 0,
is.na(ae_28_sev) & mort_28 == 1 ~ NA,
TRUE ~ ae_28_sev))
df <- df %>%
mutate(ae_28_sev = case_when(mort_28 == 1 ~ NA,
TRUE ~ ae_28_sev))
# table(df$ae_28_sev, df$mort_28, useNA = "always")
# addmargins(table(df$ae_28_sev, df$trt, useNA = "always"))
# (ix) Sens-analysis: Alternative definition/analysis of outcome: time to first (of these) adverse event, within 28 days, considering death as a competing risk (=> censor and set to 28 days)
# re-discuss
# (x) Adverse events of special interest within 28 days: a) thromboembolic events (venous thromboembolism, pulmonary embolism, arterial thrombosis), b) secondary infections (bacterial pneumonia including ventilator-associated pneumonia, meningitis and encephalitis, endocarditis and bacteremia, invasive fungal infection including pulmonary aspergillosis), c) Reactivation of chronic infection including tuberculosis, herpes simplex, cytomegalovirus, herpes zoster and hepatitis B, d) serious cardiovascular and cardiac events (including stroke and myocardial infarction), e) events related to signs of bone marrow suppression (anemia, lymphocytopenia, thrombocytopenia, pancytopenia), f) malignancy, g) gastrointestinal perforation (incl. gastrointestinal bleeding/diverticulitis), h) liver dysfunction/hepatotoxicity (grade 3 and 4)
df_ae_tot <- df_ae_set %>%
filter(ASTDY <29)
df_ae_tot <- left_join(df_ae_tot, df[, c("trt", "USUBJID")], by = join_by(USUBJID == USUBJID))
df_ae_tot <- df_ae_tot %>%
rename(ae = AEDECOD,
ae_class = AESOC,
ae_desc = AEHLT)
df_thrombo <- df_ae_tot %>% # a) thromboembolic events (venous thromboembolism, pulmonary embolism, arterial thrombosis)
filter(grepl("thrombos|embo|occl", ae, ignore.case = TRUE)) %>%
mutate(aesi = "thrombo")
df_sec_inf <- df_ae_tot %>% # b) secondary infections (bacterial pneumonia including ventilator-associated pneumonia, meningitis and encephalitis, endocarditis and bacteremia, invasive fungal infection including pulmonary aspergillosis), but not COVID-19 pneumonia!
filter(ae_class %in% c("Infections and infestations") & !grepl("shock|herpes|COVID-19|sinusitis", ae, ignore.case = TRUE)) %>%
mutate(aesi = "sec_inf")
df_reactivate <- df_ae_tot %>% # c) Reactivation of chronic infection including tuberculosis, herpes simplex, cytomegalovirus, herpes zoster and hepatitis B
filter(grepl("hepatitis|zoster|herpes|cytome|tuber|tb", ae, ignore.case = TRUE) | ae_desc %in% c("Herpes viral infections")) %>%
mutate(aesi = "reactivate")
df_cardiac <- df_ae_tot %>% # d) serious cardiovascular and cardiac events (including stroke and myocardial infarction) (excl. hypertension)
filter(ae_class %in% c("Cardiac disorders") | grepl("stroke|cerebrovascular|infarction|ischaemia|ischemia", ae, ignore.case = TRUE)) %>%
mutate(aesi = "cardiac")
df_penia <- df_ae_tot %>% # e) events related to signs of bone marrow suppression (anemia, lymphocytopenia, thrombocytopenia, pancytopenia)
filter(grepl("penia|anemia|anaemia", ae, ignore.case = TRUE) | grepl("penia|anemia|anaemia", ae_desc, ignore.case = TRUE)) %>%
mutate(aesi = "penia")
df_malig <- df_ae_tot %>% # f) malignancy
filter(ae_class %in% c("Neoplasms benign, malignant and unspecified (incl cysts and polyps)")
# | grepl("cancer|neopl|malig", ae, ignore.case = TRUE) | grepl("cancer|neopl|malig", ae_desc, ignore.case = TRUE)
) %>%
mutate(aesi = "malig")
df_git_bl <- df_ae_tot %>% # g) gastrointestinal perforation (incl. gastrointestinal bleeding/diverticulitis)
filter(ae_class %in% c("Hepatobiliary disorders","Gastrointestinal disorders") & (grepl("hemor|haemor|bleed", ae, ignore.case = TRUE) | grepl("hemor|haemor|bleed", ae_desc, ignore.case = TRUE))) %>%
mutate(aesi = "git_bl")
df_hepatox <- df_ae_tot %>% # h) liver dysfunction/hepatotoxicity (grade 3 and 4)
filter(ae_class %in% c("Hepatobiliary disorders") & grepl("hepatox|liver injury|damage|failure|hypertrans|abnormal|hyperbili", ae, ignore.case = TRUE)) %>%
mutate(aesi = "hepatox")
df_mods <- df_ae_tot %>% # i) Multiple organ dysfunction syndrome and septic shock
filter(grepl("Multiple organ dysfunction syndrome|mods|shock", ae, ignore.case = TRUE)) %>%
mutate(aesi = "mods")
df_aesi <- rbind(df_mods, df_hepatox, df_git_bl, df_malig, df_penia, df_cardiac, df_reactivate, df_sec_inf, df_thrombo)
df_aesi <- df_aesi %>%
rename(id_pat = USUBJID) %>%
select(id_pat, trt, aesi, ae, ae_desc, ae_class)
table(df_aesi$trt, df_aesi$aesi)
# double-check if there are any duplicate AEs within the same person and if it is the same event or distinct ones
df_aesi <- df_aesi %>%
group_by(id_pat) %>%
mutate(duplicate_id = duplicated(ae) & !is.na(ae)) %>%
ungroup()
df_aesi <- df_aesi %>%
filter(duplicate_id == F)
# Save
saveRDS(df_aesi, file = "df_aesi_cov-barrier.RData")
# (xi) Adverse events, any grade and serious adverse event, excluding death, within 28 days, grouped by organ classes
df_ae <- df_ae_tot %>%
rename(id_pat = USUBJID) %>%
select(id_pat, trt, ae, ae_desc, ae_class)
# double-check if there are any duplicate AEs within the same person and if it is the same event or distinct ones
df_ae <- df_ae %>%
group_by(id_pat) %>%
mutate(duplicate_id = duplicated(ae) & !is.na(ae)) %>%
ungroup()
df_ae <- df_ae %>%
filter(duplicate_id == F)
# Save
saveRDS(df_ae, file = "df_ae_cov-barrier.RData")
```
Discussion points OUTCOME data
# Define final datasets
```{r echo=TRUE}
# keep the overall set
df_all <- df
# reduce the df set to our standardized set across all trials
df <- df %>%
select(id_pat, trt, sex, age, trial, JAKi,
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, variant,
vl_baseline,
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
)
# export for one-stage model, i.e., add missing variables
df_os <- df
df_os$vacc <- NA
df_os$sero <- NA
df_os$variant <- NA
# Save
saveRDS(df_os, file = "df_os_cov-barrier.RData")
```
# Missing data plot: One-stage dataset
```{r echo=TRUE}
# Bar plot, missing data, each data point, standardized one-stage dataset
original_order <- colnames(df_os)
missing_plot <- df_os %>%
summarise_all(~ mean(is.na(.))) %>%
gather() %>%
mutate(key = factor(key, levels = original_order)) %>%
ggplot(aes(x = key, y = value)) +
geom_bar(stat = "identity") +
labs(x = "Columns", y = "Proportion of Missing Values", title = "Missing Data - standardized one-stage dataset") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
ylim(0, 1)
print(missing_plot)
```
Discussion points
1. Missing variables:
* Baseline:
- comed_acoa: double-check
- sero
- variant
* Outcomes:
- qol_28
2. Missing data in:
- clinstatus_baseline
- comed_dexa & comed_cat
- sympdur
- crp
- vl_baseline
- new_mv_28: part of denominator
- new_mvd_28
- viral load outcomes
# Missing data: Explore for MI
```{r message=FALSE, warning=FALSE}
# keep the core df
# names(df_all)
df_core <- df_all %>%
select(id_pat, trt, sex, age, trial, JAKi, ethn,
# vacc,
country, icu, sympdur, 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, vl_baseline,
# sero, variant,
clinstatus_1, clinstatus_2, clinstatus_3, clinstatus_4, clinstatus_5, clinstatus_6, clinstatus_7, clinstatus_8, clinstatus_9, clinstatus_10, clinstatus_11, clinstatus_12, clinstatus_13, clinstatus_14, clinstatus_15, clinstatus_16, clinstatus_17, clinstatus_18, clinstatus_19, clinstatus_20, clinstatus_21, clinstatus_22, clinstatus_23, clinstatus_24, clinstatus_25, clinstatus_26, clinstatus_27, clinstatus_28, clinstatus_60, clinstatus_29, clinstatus_30,
clinstatus_28_imp,
mort_28, mort_28_dimp, mort_60, death_reached, death_time,
new_mv_28, new_mvd_28,
discharge_reached, discharge_time, discharge_time_sens, discharge_reached_sus, discharge_time_sus,
vir_clear_5, vir_clear_10, vir_clear_15,
ae_28, ae_28_sev
)
# Convert character variables to factors
char_vars <- c("id_pat", "sex", "trial", "JAKi", "country", "icu", "ethn", "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", "any_comorb", "comorb_cat", "comorb_any", "comorb_autoimm","comorb_cancer", "comorb_kidney", "vl_baseline", "clinstatus_28_imp", "mort_28", "mort_28_dimp", "mort_60", "death_reached", "new_mv_28", "new_mvd_28","discharge_reached", "discharge_reached_sus", "ae_28", "vir_clear_5", "vir_clear_10", "vir_clear_15")
df_core <- df_core %>%
mutate(across(all_of(char_vars), factor))
# Bar plot, missing data, each data point, core dataset
original_order <- colnames(df_core)
missing_plot <- df_core %>%
summarise_all(~ mean(is.na(.))) %>%
gather() %>%
mutate(key = factor(key, levels = original_order)) %>%
ggplot(aes(x = key, y = value)) +
geom_bar(stat = "identity") +
labs(x = "Columns", y = "Proportion of Missing Values", title = "Missing Data - core dataset") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
ylim(0, 1)
print(missing_plot)
# Bar plot, missing data, each data point, core dataset, by arm
df_core_int <- df_core %>%
filter(trt == 1)
original_order <- colnames(df_core_int)
missing_plot <- df_core_int %>% # Intervention arm
summarise_all(~ mean(is.na(.))) %>%
gather() %>%
mutate(key = factor(key, levels = original_order)) %>%
ggplot(aes(x = key, y = value)) +
geom_bar(stat = "identity") +
labs(x = "Columns", y = "Proportion of Missing Values", title = "Missing Data - core dataset, intervention") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
ylim(0, 1)
print(missing_plot)
df_core_cont <- df_core %>%
filter(trt == 0)
original_order <- colnames(df_core_cont)
missing_plot <- df_core_cont %>% # Control arm
summarise_all(~ mean(is.na(.))) %>%
gather() %>%
mutate(key = factor(key, levels = original_order)) %>%
ggplot(aes(x = key, y = value)) +
geom_bar(stat = "identity") +
labs(x = "Columns", y = "Proportion of Missing Values", title = "Missing Data - core dataset, control") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
ylim(0, 1)
print(missing_plot)
### Baseline table, by individuals with no missing data vs any missing data (or only in mort_28)
# df_core <- df_core %>% mutate(complete = ifelse(rowSums(is.na(.)) > 0, 0, 1));table(df_core$complete) # ANY missing
df_core$resp<-ifelse(is.na(df_core$mort_28), 0, 1);table(df_core$resp) # only mort_28 missing
# Assign variable list
vars.list <- c("resp", "age", "sympdur"
,"trt", "sex", "country", "icu", "ethn", "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", "any_comorb", "comorb_cat", "comorb_any", "comorb_count","comorb_autoimm","comorb_cancer", "comorb_kidney", "crp", "vl_baseline"
, "mort_28", "mort_28_dimp", "mort_60", "death_reached","death_time", "new_mv_28", "new_mvd_28","discharge_reached", "discharge_time", "discharge_reached_sus", "discharge_time_sus", "ae_28", "ae_28_sev", "vir_clear_5", "vir_clear_10", "vir_clear_15")
# By completeness (only mort_28)
table_resp <- CreateTableOne(data = df_core, vars = vars.list[!vars.list %in% c("resp")], strata = "resp", includeNA = T, test = T, addOverall = TRUE)
# Print and display the table
capture.output(
table_resp <- print(
table_resp,
nonnormal = vars.list,
catDigits = 1,
SMD = TRUE,
showAllLevels = TRUE,
test = TRUE,
printToggle = FALSE,
missing = TRUE))
kable(table_resp, format = "markdown", table.attr = 'class="table"', caption = "By completeness (only mort_28)") %>%
kable_styling(bootstrap_options = "striped", full_width = FALSE)
### Define variables to be included in imputation set
# table(df_core$vl_baseline)
df_imp <- df_core %>%
select("id_pat"
, "trt", "sex", "age" , "ethn"
, "country", "sympdur"
# ,"vacc" # no info
# , "trial", "JAKi" # only 0
,"clinstatus_baseline"
# , "vbaseline" # derived
# , "comed_rdv" # no info
# , "comed_toci", "comed_interferon" # no info
#, "comed_cat", # derived
, "comed_dexa", "comed_ab"
# , "comed_acoa" # no info
, "comed_other"
# , "comorb_lung", "comorb_liver", "comorb_cvd", "comorb_aht", "comorb_dm", "comorb_obese",
# "comorb_smoker", "immunosupp", "comorb_autoimm", "comorb_cancer", "comorb_kidney", "any_comorb",
# "comorb_count",
# "comorb_any",
,"comorb_cat" # derived from above, contains most information, and needed as interaction term
,"crp"
,"vl_baseline"
# , "sero" , "variant" # very little info
, clinstatus_1, clinstatus_2, clinstatus_3, clinstatus_4, clinstatus_5, clinstatus_6, clinstatus_7, clinstatus_8, clinstatus_9, clinstatus_10, clinstatus_11, clinstatus_12, clinstatus_13, clinstatus_14, clinstatus_15, clinstatus_16, clinstatus_17, clinstatus_18, clinstatus_19, clinstatus_20, clinstatus_21, clinstatus_22, clinstatus_23, clinstatus_24, clinstatus_25, clinstatus_26, clinstatus_27, clinstatus_28
# , "clinstatus_28_imp" # imputed via LOVCF above
, "mort_28"
# , "mort_28_dimp" # imputed deterministically
# , "mort_60" # does not contain any additional information compared to death reached
, "death_reached", "death_time", "new_mv_28", "new_mvd_28", "discharge_reached", "discharge_time"
# , "discharge_reached_sus", "discharge_time_sus" # same as discharge, does not contain any addition information
, "ae_28", "ae_28_sev", "vir_clear_5", "vir_clear_10", "vir_clear_15"
)
# First, table and visualize missing data in various ways
# df_imp %>%
# ff_glimpse() # from finalfit package
df_imp %>%
missing_plot() # from finalfit package
explanatory = c("age",
"clinstatus_baseline", "sex",
"ethn", "country", "sympdur", "comorb_cat", "comed_dexa", "comed_ab", "comed_other", "crp", "vl_baseline", "ae_28_sev")
dependent = "mort_28"
df_imp %>% # from finalfit package, missing plot
missing_pairs(dependent, explanatory, position = "fill", )
# Second, let's explore the missingness patterns
md.pattern(df_imp[,c("mort_28", "age",
"clinstatus_baseline", "sex",
"ethn", "country", "sympdur", "comorb_cat", "comed_dexa", "comed_ab", "comed_other", "crp","vl_baseline", "ae_28_sev")], rotate.names = T)
# Third, let's explore if the variables from my substantive model plus auxiliary variables are associated with mort_28
mort28.aux <- glm(mort_28 ~ trt
+ age
+ clinstatus_baseline
+ sex
+ ethn
+ country
+ sympdur
+ comorb_cat
+ comed_dexa
+ comed_ab
+ comed_other
+ vl_baseline
+ crp