-
Notifications
You must be signed in to change notification settings - Fork 0
/
07_manuscript_visualisations.R
2272 lines (2073 loc) · 117 KB
/
07_manuscript_visualisations.R
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
#### Master Script 06: Visualise study results for manuscript ####
#
# Shubhayu Bhattacharyay
# University of Cambridge
# email address: [email protected]
#
### Contents:
# I. Initialisation
# II. Figure 1
# III. Figure 2
# IV. Figure 3
# V. Figure 4
# VI. Supplementary Figures 5 and 6
# VII. Supplementary Figures 8 and 9
# VIII. Supplementary Figure 7
# IX. Supplementary Appendix
# X. Unused
# XI. Addendum to figure 2
# XII. Supplementary Figures 2 and 3
# XIII. Supplementary Figure 4
# XIV. Appendix variable lists
# XV. Create table of cutoffs defining significant transitions
# XVI. Stacked proportion barplots of characteristics over time
# XVII. Sensitivity analysis difference plots
# XVIII. Kaplan-Meier ICU stay curve for patients who died vs. survived in ICU
# XIX. Supplementary Figure: WLST vs. non-WLST TimeSHAP
### I. Initialisation
# Import necessary libraries
library(tidyverse)
library(readxl)
library(plotly)
library(ggbeeswarm)
library(cowplot)
library(rvg)
library(svglite)
library(openxlsx)
library(gridExtra)
library(extrafont)
library(survminer)
library(survival)
# Import custom plotting functions
source('functions/plotting.R')
### II. Figure 1
## Prepare overall calibration dataframes
# Calibration curve results
calib.curves.CIs <- read.csv('../model_performance/v6-0/test_set_calib_curves_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 6,
SinceAdmission = WINDOW_IDX > 0)
calib.curves.CIs$WINDOW_IDX[!calib.curves.CIs$SinceAdmission] <- calib.curves.CIs$WINDOW_IDX[!calib.curves.CIs$SinceAdmission] + 1
calib.curves.CIs <- calib.curves.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12,
hi = pmax(0,hi),
lo = pmax(0,lo),
median = pmax(0,median)) %>%
mutate(hi = pmin(1,hi),
lo = pmin(1,lo),
median = pmin(1,median))
# Calibration metrics results
calibration.CIs <- read.csv('../model_performance/v6-0/test_set_calibration_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 6,
SinceAdmission = WINDOW_IDX > 0)
calibration.CIs$WINDOW_IDX[!calibration.CIs$SinceAdmission] <- calibration.CIs$WINDOW_IDX[!calibration.CIs$SinceAdmission] + 1
calibration.CIs <- calibration.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
# Static calibration metric results
static.calibration.CIs <- read.csv('../model_performance/v6-0/static_set_calibration_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 'Static',
SinceAdmission = WINDOW_IDX > 0)
static.calibration.CIs$WINDOW_IDX[!static.calibration.CIs$SinceAdmission] <- static.calibration.CIs$WINDOW_IDX[!static.calibration.CIs$SinceAdmission] + 1
static.calibration.CIs <- static.calibration.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
# Baseline calibration metric results
baseline.calibration.CIs <- read.csv('../model_performance/BaselineComparison/test_set_calibration_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 'Baseline',
SinceAdmission = WINDOW_IDX > 0)
baseline.calibration.CIs$WINDOW_IDX[!baseline.calibration.CIs$SinceAdmission] <- baseline.calibration.CIs$WINDOW_IDX[!baseline.calibration.CIs$SinceAdmission] + 1
baseline.calibration.CIs <- baseline.calibration.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
## Create threshold-level calibration slope plot
# Since admission calibration slope plot
since.adm.calib.slope <- rbind(calibration.CIs,baseline.calibration.CIs) %>%
filter(SinceAdmission,
METRIC == 'CALIB_SLOPE',
THRESHOLD=='Average') %>%
ggplot() +
coord_cartesian(xlim=c(0,7),ylim=c(0,1.5)) +
geom_vline(xintercept = 0.33333333, color='dark gray',alpha = 1, size=1.3/.pt, linetype = "dashed")+
geom_vline(xintercept = 1, color='#bc5090',alpha = 1, size=1.3/.pt, linetype = "dashed")+
geom_hline(yintercept = 1, color='#ffa600',alpha = 1, size=2/.pt)+
# geom_line(data=old.calibration.CIs,aes(x=DaysAfterICUAdmission,y=median),alpha = 1, size=1.3/.pt,color='dark gray')+
# geom_line(data=old.calibration.CIs,aes(x=DaysAfterICUAdmission,y=lo),alpha = 1, size=1.3/.pt,color='dark gray',linetype = "dashed")+
# geom_line(data=old.calibration.CIs,aes(x=DaysAfterICUAdmission,y=hi),alpha = 1, size=1.3/.pt,color='dark gray',linetype = "dashed")+
geom_line(aes(x=DaysAfterICUAdmission,y=median,color=VERSION),alpha = 1, size=1.3/.pt) +
geom_ribbon(aes(x=DaysAfterICUAdmission,ymin=lo,ymax=hi,fill=VERSION),alpha=.2,size=.75/.pt) +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(0,0))) +
ylab('Calibration slope')+
xlab('Days since ICU admission') +
scale_fill_manual(values = c("#003f5c", "#bc5090"))+
scale_color_manual(values = c("#003f5c", "#bc5090"))+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Before discharge calibration slope plot
before.disch.calib.slope <- rbind(calibration.CIs,baseline.calibration.CIs) %>%
filter(!SinceAdmission,
METRIC == 'CALIB_SLOPE',
THRESHOLD=='Average') %>%
mutate(DaysBeforeICUDischarge = abs(DaysAfterICUAdmission)) %>%
ggplot() +
coord_cartesian(xlim=c(7,0), ylim = c(0,1.5)) +
geom_hline(yintercept = 1, color='#ffa600',alpha = 1, size=2/.pt) +
# geom_line(data=old.calibration.CIs,aes(x=DaysBeforeICUDischarge,y=median),alpha = 1, size=1.3/.pt,color='dark gray')+
# geom_line(data=old.calibration.CIs,aes(x=DaysBeforeICUDischarge,y=lo),alpha = 1, size=1.3/.pt,color='dark gray',linetype = "dashed")+
# geom_line(data=old.calibration.CIs,aes(x=DaysBeforeICUDischarge,y=hi),alpha = 1, size=1.3/.pt,color='dark gray',linetype = "dashed")+
geom_line(aes(x=DaysBeforeICUDischarge,y=median,color=VERSION),alpha = 1, size=1.3/.pt) +
geom_ribbon(aes(x=DaysBeforeICUDischarge,ymin=lo,ymax=hi,fill=VERSION),alpha=.2,size=.75/.pt) +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(0,0))) +
ylab('Calibration slope') +
xlab('Days before ICU discharge') +
scale_fill_manual(values = c("#003f5c", "#bc5090"))+
scale_color_manual(values = c("#003f5c", "#bc5090"))+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Create directory for current date and save post-admission and pre-discharge calibration slope plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'since_adm_calib_slope.svg'),since.adm.calib.slope,device=svglite,units='in',dpi=600,width=3.7,height=1.1)
ggsave(file.path('../plots',Sys.Date(),'before_disch_calib_slope.svg'),before.disch.calib.slope,device=svglite,units='in',dpi=600,width=3.7,height=1.1)
## Create threshold-level calibration curve plot
# Since admission calibration curve plot
since.adm.calib.curves <- calib.curves.CIs %>%
filter(WINDOW_IDX %in% c(1,4,12,24)) %>%
mutate(WINDOW_IDX = plyr::mapvalues(WINDOW_IDX,
from=c(1,4,12,24),
to=c('2 hrs.','8 hrs.','1 day','2 days'))) %>%
mutate(WINDOW_IDX = fct_relevel(WINDOW_IDX,'2 hrs.','8 hrs.','1 day','2 days')) %>%
ggplot(aes(x=100*PREDPROB)) +
facet_wrap( ~ THRESHOLD,
scales = 'free',
ncol = 4) +
coord_cartesian(ylim = c(0,100),xlim = c(0,100))+
geom_segment(x = 0, y = 0, xend = 100, yend = 100,alpha = 0.5,linetype = "dashed",size=.75/.pt, color = 'gray')+
geom_ribbon(aes(ymin = 100*lo, ymax = 100*hi, fill = WINDOW_IDX), alpha = 0.3,size=.75/.pt,color=NA) +
geom_line(aes(y = 100*median, color = WINDOW_IDX), alpha = 1, size=1.3/.pt) +
scale_x_continuous(expand = expansion(mult = c(.01, .01))) +
scale_y_continuous(expand = expansion(mult = c(.01, .01))) +
guides(fill=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE)) +
scale_fill_manual(name = "Time since ICU admission",
values = c("#003f5c", "#7a5195", "#ef5675",'#ffa600'))+
scale_color_manual(name = "Time since ICU admission",
values = c("#003f5c", "#7a5195", "#ef5675",'#ffa600'))+
xlab("Predicted probability") +
ylab("Observed probability") +
theme_classic(base_family = 'Roboto Condensed') +
theme(
strip.text = element_text(size=6, color = "black",face = 'bold',margin = margin(b = .5)),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
panel.spacing = unit(0.05, "lines"),
axis.text.x = element_text(size = 5, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 5, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
strip.background = element_blank(),
aspect.ratio = 1,
panel.border = element_rect(colour = 'black', fill=NA, size = 1/.pt),
#plot.margin=grid::unit(c(0,0,0,0), "mm"),
legend.position = 'bottom',
legend.title = element_text(size = 7, color = "black", face = 'bold'),
legend.text=element_text(size=6),
axis.line = element_blank(),
legend.key.size = unit(1.3/.pt,"line")
)
# Create directory for current date and save post-admission calibration curve plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'since_adm_calib_curves.svg'),since.adm.calib.curves,device=svglite,units='in',dpi=600,width=7.5,height=4.46)
# Calculate integrated calibration index (ICI) for plot
since.adm.ICI <- calibration.CIs %>%
filter(THRESHOLD != 'Average',
METRIC == 'ICI',
WINDOW_IDX %in% c(1,4,12,24)) %>%
mutate(WINDOW_IDX = plyr::mapvalues(WINDOW_IDX,
from=c(1,4,12,24),
to=c('2 hrs.','8 hrs.','1 day','2 days'))) %>%
mutate(WINDOW_IDX = fct_relevel(WINDOW_IDX,'2 hrs.','8 hrs.','1 day','2 days')) %>%
mutate(formatted = sprintf('%s: %.2f (%.2f–%.2f)',WINDOW_IDX,median,lo,hi)) %>%
arrange(THRESHOLD,WINDOW_IDX)
### III. Figure 2
## Prepare overall performance dataframes
# Discrimination results
discrimination.CIs <- read.csv('../model_performance/v6-0/test_set_discrimination_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 6,
SinceAdmission = WINDOW_IDX > 0)
discrimination.CIs$WINDOW_IDX[!discrimination.CIs$SinceAdmission] <- discrimination.CIs$WINDOW_IDX[!discrimination.CIs$SinceAdmission] + 1
discrimination.CIs <- discrimination.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
# Static discrimination results
static.discrimination.CIs <- read.csv('../model_performance/v6-0/static_set_discrimination_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 'Static',
SinceAdmission = WINDOW_IDX > 0)
static.discrimination.CIs$WINDOW_IDX[!static.discrimination.CIs$SinceAdmission] <- static.discrimination.CIs$WINDOW_IDX[!static.discrimination.CIs$SinceAdmission] + 1
static.discrimination.CIs <- static.discrimination.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
# Baseline discrimination results
baseline.discrimination.CIs <- read.csv('../model_performance/BaselineComparison/test_set_discrimination_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 'Baseline',
SinceAdmission = WINDOW_IDX > 0)
baseline.discrimination.CIs$WINDOW_IDX[!baseline.discrimination.CIs$SinceAdmission] <- baseline.discrimination.CIs$WINDOW_IDX[!baseline.discrimination.CIs$SinceAdmission] + 1
baseline.discrimination.CIs <- baseline.discrimination.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
# Difference in discrimination between full-model and static variables
static.difference.CIs <- read.csv('../model_performance/v6-0/static_test_set_discrimination_difference_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
filter(METRIC == 'Somers D') %>%
mutate(SinceAdmission = WINDOW_IDX > 0,
VERSION = 'Static') %>%
drop_na(median)
static.difference.CIs$WINDOW_IDX[!static.difference.CIs$SinceAdmission] <- static.difference.CIs$WINDOW_IDX[!static.difference.CIs$SinceAdmission] + 1
static.difference.CIs <- static.difference.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
# Difference in discrimination between full-model and IMPACT
baseline.difference.CIs <- read.csv('../model_performance/BaselineComparison/test_set_discrimination_difference_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
filter(METRIC == 'Somers D') %>%
mutate(SinceAdmission = WINDOW_IDX > 0,
VERSION = 'Baseline') %>%
drop_na(median)
baseline.difference.CIs$WINDOW_IDX[!baseline.difference.CIs$SinceAdmission] <- baseline.difference.CIs$WINDOW_IDX[!baseline.difference.CIs$SinceAdmission] + 1
baseline.difference.CIs <- baseline.difference.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
## Create overall discrimination performance plots
# Since admission Somers' D plot
since.adm.somers <- rbind(discrimination.CIs,baseline.discrimination.CIs) %>%
filter(SinceAdmission,
METRIC == 'Somers D') %>%
ggplot() +
coord_cartesian(xlim=c(0,7), ylim = c(27.5,55)) +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(.0, .0)))+
geom_vline(xintercept = 1, color='#bc5090',alpha = 1, size=1.3/.pt, linetype = "dashed")+
# geom_line(data=old.discrimination.CIs,aes(x=DaysAfterICUAdmission,y=100*median),alpha = 1, size=1.3/.pt,color='dark gray')+
# geom_line(data=old.discrimination.CIs,aes(x=DaysAfterICUAdmission,y=100*lo),alpha = 1, size=1.3/.pt,color='dark gray',linetype = "dashed")+
# geom_line(data=old.discrimination.CIs,aes(x=DaysAfterICUAdmission,y=100*hi),alpha = 1, size=1.3/.pt,color='dark gray',linetype = "dashed")+
geom_line(aes(x=DaysAfterICUAdmission,y=100*median,color=VERSION),alpha = 1, size=1.3/.pt)+
geom_ribbon(aes(x=DaysAfterICUAdmission,ymin=lo*100,ymax=hi*100,fill=VERSION),alpha=.2) +
ylab('Explanation of ordinal GOSE (%)')+
xlab('Days since ICU admission')+
scale_fill_manual(values = c("#003f5c", "#bc5090"))+
scale_color_manual(values = c("#003f5c", "#bc5090"))+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Before discharge Somers' D plot
before.disch.somers <- rbind(discrimination.CIs,baseline.discrimination.CIs) %>%
filter(!SinceAdmission,
METRIC == 'Somers D') %>%
mutate(DaysBeforeICUDischarge = abs(DaysAfterICUAdmission)) %>%
ggplot() +
scale_x_reverse(expand = expansion(mult = c(.0, .0)),breaks=seq(0,7,by=1))+
coord_cartesian(xlim=c(7,0), ylim = c(27.5,55)) +
# geom_line(data=old.discrimination.CIs,aes(x=DaysBeforeICUDischarge,y=100*median),alpha = 1, size=1.3/.pt,color='dark gray')+
# geom_line(data=old.discrimination.CIs,aes(x=DaysBeforeICUDischarge,y=100*lo),alpha = 1, size=1.3/.pt,color='dark gray',linetype = "dashed")+
# geom_line(data=old.discrimination.CIs,aes(x=DaysBeforeICUDischarge,y=100*hi),alpha = 1, size=1.3/.pt,color='dark gray',linetype = "dashed")+
geom_line(aes(x=DaysBeforeICUDischarge,y=100*median,color=VERSION),alpha = 1, size=1.3/.pt)+
geom_ribbon(aes(x=DaysBeforeICUDischarge,ymin=lo*100,ymax=hi*100,fill=VERSION),alpha=.2) +
ylab('Explanation of ordinal GOSE (%)')+
xlab('Days before ICU discharge')+
scale_fill_manual(values = c("#003f5c", "#bc5090"))+
scale_color_manual(values = c("#003f5c", "#bc5090"))+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Create directory for current date and save post-admission and pre-discharge Somers' D plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'since_adm_somers.svg'),since.adm.somers,device= svglite,units='in',dpi=600,width=3.7,height = 1.38)
ggsave(file.path('../plots',Sys.Date(),'before_disch_somers.svg'),before.disch.somers,device= svglite,units='in',dpi=600,width=3.7,height = 1.38)
## Create overall discrimination difference over baseline plots
# Since admission difference in Somers' D plot
since.adm.baseline.diff.somers <- rbind(baseline.difference.CIs,static.difference.CIs) %>%
filter(SinceAdmission) %>%
ggplot() +
coord_cartesian(xlim=c(0,7), ylim = c(0,15)) +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(.0, .0)))+
geom_vline(xintercept = 1, color='#bc5090',alpha = 1, size=1.3/.pt, linetype = "dashed")+
geom_line(aes(x=DaysAfterICUAdmission,y=100*median,color=VERSION),alpha = 1, size=1.3/.pt)+
geom_ribbon(aes(x=DaysAfterICUAdmission,ymin=lo*100,ymax=hi*100,fill=VERSION),alpha=.2) +
ylab('Added explanation of ordinal GOSE (d%)')+
xlab('Days since ICU admission')+
scale_fill_manual(values = c("#bc5090","#003f5c"))+
scale_color_manual(values = c("#bc5090","#003f5c"))+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Before discharge difference in Somers' D plot
before.disch.baseline.diff.somers <- rbind(baseline.difference.CIs,static.difference.CIs) %>%
filter(!SinceAdmission) %>%
mutate(DaysBeforeICUDischarge = abs(DaysAfterICUAdmission)) %>%
ggplot() +
scale_x_reverse(expand = expansion(mult = c(.0, .0)),breaks=seq(0,7,by=1))+
coord_cartesian(xlim=c(7,0), ylim = c(0,15)) +
geom_line(aes(x=DaysBeforeICUDischarge,y=100*median,color=VERSION),alpha = 1, size=1.3/.pt)+
geom_ribbon(aes(x=DaysBeforeICUDischarge,ymin=lo*100,ymax=hi*100,fill=VERSION),alpha=.2) +
ylab('Added explanation of ordinal GOSE (d%)')+
xlab('Days before ICU discharge')+
scale_fill_manual(values = c("#bc5090","#003f5c"))+
scale_color_manual(values = c("#bc5090","#003f5c"))+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Create directory for current date and save post-admission and pre-discharge Somers' D plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'since_adm_baseline_diff_somers.svg'),since.adm.baseline.diff.somers,device= svglite,units='in',dpi=600,width=3.7,height = 1.38)
ggsave(file.path('../plots',Sys.Date(),'before_disch_baseline_diff_somers.svg'),before.disch.baseline.diff.somers,device= svglite,units='in',dpi=600,width=3.7,height = 1.38)
## Discharge cutoff sensitivity analysis
# Load and prepare cutoff mean analysis dataframe
cutoff.mean.analysis <- read.csv('../model_performance/v6-0/sensitivity_cutoff_mean_difference_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(CutoffDays = CUTOFF_IDX/12)
# Load and prepare cutoff discrimination difference dataframe
cutoff.discrimination <- read.csv('../model_performance/v6-0/full_69_sensitivity_cutoff_discrimination_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 6,
SinceAdmission = WINDOW_IDX > 0)
cutoff.discrimination$WINDOW_IDX[!cutoff.discrimination$SinceAdmission] <- cutoff.discrimination$WINDOW_IDX[!cutoff.discrimination$SinceAdmission] + 1
cutoff.discrimination <- cutoff.discrimination %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
# Trajectory of mean difference in Somers' D vs. discharge cutoff
cutoff.mean.somers.diff.plot <- cutoff.mean.analysis %>%
filter(METRIC == 'Somers D',
CutoffDays>1) %>%
ggplot() +
coord_cartesian(xlim=c(0,7), ylim = c(-15,19)) +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(.0, .0)))+
geom_vline(xintercept = 13/12, color='dark gray',alpha = 1, size=1.3/.pt, linetype = "dashed")+
geom_vline(xintercept = 69/12, color='#bc5090',alpha = 1, size=1.3/.pt, linetype = "dashed")+
geom_hline(yintercept = 0, color='#ffa600',alpha = 1, size=2/.pt) +
geom_line(aes(x=CutoffDays,y=100*median),alpha = 1, size=1.3/.pt,color="#003f5c")+
geom_ribbon(aes(x=CutoffDays,ymin=lo*100,ymax=hi*100),alpha=.2,fill="#003f5c") +
ylab('Mean difference in ordinal GOSE explanation (%)')+
xlab('ICU stay duration cutoff (days)')+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Create directory for current date and save trajectory of mean difference in Somers' D vs. discharge cutoff
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'cutoff_diff_Somers_plot.svg'),cutoff.mean.somers.diff.plot,device= svglite,units='in',dpi=600,width=3.7,height = 1.29)
# Somers D pre- and post-discharge cutoff from admission
cutoff.somers.plot <- cutoff.discrimination %>%
filter(SinceAdmission,
CUTOFF_IDX == 69,
variable %in% c('DROPOUT_VALUE','REMAINING_VALUE'),
METRIC == 'Somers D',
((WINDOW_IDX<65)|(variable=='REMAINING_VALUE'))) %>%
ggplot() +
coord_cartesian(xlim=c(0,7), ylim = c(39,86)) +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(.0, .0)))+
geom_vline(xintercept = 69/12, color='#bc5090',alpha = 1, size=1.3/.pt, linetype = "dashed")+
geom_line(aes(x=DaysAfterICUAdmission,y=100*median,color=variable),alpha = 1, size=1.3/.pt)+
geom_ribbon(aes(x=DaysAfterICUAdmission,ymin=lo*100,ymax=hi*100,fill=variable),alpha=.2) +
ylab('Explanation of ordinal GOSE (%)')+
xlab('Days since ICU admission')+
scale_fill_manual(values = c("#003f5c", "#bc5090"))+
scale_color_manual(values = c("#003f5c", "#bc5090"))+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Somers D pre- and post-discharge cutoff before discharge
before.disch.cutoff.somers.plot <- cutoff.discrimination %>%
filter(!SinceAdmission,
CUTOFF_IDX == 69,
variable %in% c('DROPOUT_VALUE','REMAINING_VALUE'),
METRIC == 'Somers D',
((WINDOW_IDX>-64)|(variable=='REMAINING_VALUE'))) %>%
mutate(DaysBeforeICUDischarge = abs(DaysAfterICUAdmission)) %>%
ggplot() +
scale_x_reverse(expand = expansion(mult = c(.0, .0)),breaks=seq(0,7,by=1))+
coord_cartesian(xlim=c(7,0), ylim = c(39,86)) +
geom_vline(xintercept = 68/12, color='#bc5090',alpha = 1, size=1.3/.pt, linetype = "dashed")+
geom_line(aes(x=DaysBeforeICUDischarge,y=100*median,color=variable),alpha = 1, size=1.3/.pt)+
geom_ribbon(aes(x=DaysBeforeICUDischarge,ymin=lo*100,ymax=hi*100,fill=variable),alpha=.2) +
ylab('Explanation of ordinal GOSE (%)')+
xlab('Days before ICU discharge')+
scale_fill_manual(values = c("#003f5c", "#bc5090"))+
scale_color_manual(values = c("#003f5c", "#bc5090"))+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'none'
)
# Create directory for current date and save trajectory of mean difference in Somers' D vs. discharge cutoff
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'cutoff_since_adm_somers_plot.svg'),cutoff.somers.plot,device= svglite,units='in',dpi=600,width=3.7,height = 1.38)
ggsave(file.path('../plots',Sys.Date(),'cutoff_before_disch_somers_plot.svg'),before.disch.cutoff.somers.plot,device= svglite,units='in',dpi=600,width=3.7,height = 1.38)
## Create bi-directional distribution plot of significant transitions
# Load dataframe of significant transitions
sig.transitions.df <- read.csv('../model_interpretations/v6-0/timeSHAP/significant_transition_points.csv',
na.strings = c("NA","NaN","", " ")) %>%
# filter(WindowIdx > 4) %>%
mutate(DaysAfterICUAdmission = WindowIdx/12)
# Partition dataframe by above and below threshold
above.transitions.df <- sig.transitions.df %>%
filter(Above=='True')
below.transitions.df <- sig.transitions.df %>%
filter(Above=='False')
# Create bidirectional bar plot
transition.distrib.plot <- ggplot() +
annotate('rect',xmin=(1/12),xmax=(4.5/12),ymin=-1,ymax=1,alpha=0.3,fill='#de425b') +
geom_density(data = above.transitions.df, aes(x=DaysAfterICUAdmission, y=..scaled..),fill=NA,color='#003f5c',alpha=0.2,trim=TRUE, size=1.3/.pt) +
geom_density(data = below.transitions.df, aes(x=DaysAfterICUAdmission, y=-..scaled..),fill=NA,color='#76488b',alpha=0.2,trim=TRUE, size=1.3/.pt) +
geom_histogram(data = above.transitions.df, aes(x=DaysAfterICUAdmission, y=..ndensity..),alpha=0.2,fill='#003f5c',color='#003f5c',binwidth = 1/12, size=1/.pt) +
geom_histogram(data = below.transitions.df, aes(x=DaysAfterICUAdmission, y=-..ndensity..),alpha=0.2,fill='#76488b',color='#76488b',binwidth = 1/12, size=1/.pt) +
geom_segment(data = above.transitions.df, aes(x = median(DaysAfterICUAdmission),xend = median(DaysAfterICUAdmission)),y = 0,yend = 1.1,colour = "orange",alpha = 1, size=1.3/.pt,linetype = "dashed") +
geom_segment(data = below.transitions.df, aes(x = median(DaysAfterICUAdmission),xend = median(DaysAfterICUAdmission)),y = 0,yend = -1.1,colour = "orange",alpha = 1, size=1.3/.pt,linetype = "dashed") +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(.0, .0))) +
coord_cartesian(xlim=c(0,7), ylim = c(-1,1)) +
xlab('Days since ICU admission')+
ggtitle('Scaled density of significant transitions')+
theme_minimal(base_family = 'Roboto Condensed') +
theme(panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_blank(),
axis.text.y = element_blank(),
axis.title.y = element_blank(),
plot.title = element_text(size = 7, color = "black",face = 'bold',hjust = 0.5,margin = margin(b = 0,r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)))
# Create directory for current date and save post-admission and pre-discharge Somers' D plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'transition_distributions.svg'),transition.distrib.plot,device= svglite,units='in',dpi=600,width=3.7,height = 1.53)
### IV. Figure 3
## Prepare dataframe of filtered TimeSHAP values for plotting
# Load TimeSHAP value dataframe
filt.timeSHAP.df <- read.csv('../model_interpretations/v6-0/timeSHAP/filtered_plotting_timeSHAP_values.csv',
na.strings = c("NA","NaN","", " ")) %>%
filter(Threshold == 'ExpectedValue') %>%
mutate(Baseline = as.logical(Baseline),
Numeric = as.logical(Numeric),
GROUPS = case_when((RankIdx >= 11) ~ 'Top',
(RankIdx <= 10) ~'Bottom')) %>%
mutate(GROUPS = factor(GROUPS,levels=c('Top','Middle','Bottom')))
# Isolate and save unique `BaseTokens` to manually create labels and designate ordered variables
exp.GOSE.var.df <- filt.timeSHAP.df %>%
select(Baseline,Numeric,RankIdx,BaseToken) %>%
unique() %>%
mutate(PLOT_LABEL = '',
ORDERED = case_when(Numeric ~ TRUE,
!Numeric ~ NA))
write.xlsx(exp.GOSE.var.df,'../model_interpretations/v6-0/timeSHAP/expected_GOSE_timeSHAP_labels.xlsx')
# Load manually created labels of unique `BaseTokens` in plotting datafame
exp.GOSE.var.df <- read_xlsx('../model_interpretations/v6-0/timeSHAP/expected_GOSE_timeSHAP_labels_filled.xlsx')
# Merge manually created labels to filtered TimeSHAP plotting dataframe
filt.timeSHAP.df <- filt.timeSHAP.df %>%
left_join(exp.GOSE.var.df)
# Isolate and save unique `Tokens` to manually verify and fill variable order (if applicable)
exp.GOSE.token.df <- filt.timeSHAP.df %>%
select(RankIdx,PLOT_LABEL,BaseToken,Token,Baseline,Numeric,Missing,ORDERED,TokenRankIdx) %>%
unique() %>%
mutate(OrderIdx = case_when((!ORDERED)|Numeric ~ (TokenRankIdx-1)))
write.xlsx(exp.GOSE.token.df,'../model_interpretations/v6-0/timeSHAP/expected_GOSE_timeSHAP_orders.xlsx')
# Load manually inspected orders of unique `Tokens` in plotting datafame
exp.GOSE.token.df <- read_xlsx('../model_interpretations/v6-0/timeSHAP/expected_GOSE_timeSHAP_orders_filled.xlsx')
# Calculate the number of unique known values per predictor
max.order.indices <- exp.GOSE.token.df %>%
group_by(BaseToken) %>%
summarise(MaxOrderIdx = max(OrderIdx))
# Merge manually created labels to filtered TimeSHAP plotting dataframe
filt.timeSHAP.df <- filt.timeSHAP.df %>%
left_join(exp.GOSE.token.df) %>%
left_join(max.order.indices) %>%
arrange(TUNE_IDX,Threshold,RankIdx,OrderIdx) %>%
mutate(ColorScale = OrderIdx/MaxOrderIdx) %>%
mutate(ColorScale = case_when(is.na(ColorScale)~1,
((!is.na(ColorScale))&(ColorScale>=0))~ColorScale))
# Complete formatting dataframe prior to plotting
filt.timeSHAP.df <- filt.timeSHAP.df %>%
mutate(Baseline = recode(as.character(Baseline),'TRUE'='Static','FALSE'='Dynamic')) %>%
mutate(Baseline = fct_relevel(Baseline, 'Static', 'Dynamic')) %>%
mutate(PLOT_LABEL = fct_reorder(PLOT_LABEL, RankIdx))
# Create feature importance beeswarm plot for static predictors
static.timeshap.plot <- filt.timeSHAP.df %>%
filter(Baseline=='Static',
abs(SHAP) <= 0.5) %>%
ggplot() +
geom_vline(xintercept = 0, color = "darkgray") +
geom_quasirandom(aes(y=PLOT_LABEL,x=SHAP,color=ColorScale),groupOnX=FALSE,varwidth = FALSE,alpha = 0.6,stroke = 0,size=.75) +
scale_color_gradient2(na.value='#488f31',low='#003f5c',mid='#eacaf4',high='#de425b',midpoint=.5,limits = c(0,1),breaks = c(0.05,.95), labels = c('Low','High')) +
theme_minimal(base_family = 'Roboto Condensed') +
guides(color = guide_colourbar(title='Feature Value',title.vjust=1,barwidth = 10, barheight = .25,ticks = FALSE))+
facet_grid(rows = vars(GROUPS), scales = 'free_y', switch = 'y', space = 'free_y') +
theme(
strip.background = element_blank(),
strip.text = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(size = 5, color = 'black'),
# axis.text.y = element_text(size = 6, color = 'black',angle = 30, hjust=1),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
panel.border = element_blank(),
axis.line.x = element_line(size=1/.pt),
axis.text = element_text(color='black'),
# legend.position = 'bottom',
legend.position = 'none',
panel.grid.major.y = element_blank(),
panel.spacing = unit(10, 'points'),
#legend.key.size = unit(1.3/.pt,'line'),
# legend.title = element_text(size = 7, color = 'black',face = 'bold'),
# legend.text=element_text(size=6),
plot.margin=grid::unit(c(0,2,0,0), "mm")
)
# Create feature importance beeswarm plot for dynamic predictors
dynamic.timeshap.plot <- filt.timeSHAP.df %>%
filter(Baseline=='Dynamic',
SHAP >= -0.25,
SHAP <= .375) %>%
ggplot() +
geom_vline(xintercept = 0, color = "darkgray") +
geom_quasirandom(aes(y=PLOT_LABEL,x=SHAP,color=ColorScale),groupOnX=FALSE,varwidth = FALSE,alpha = 0.6,stroke = 0,size=.75) +
scale_color_gradient2(na.value='#488f31',low='#003f5c',mid='#eacaf4',high='#de425b',midpoint=.5,limits = c(0,1),breaks = c(0.05,.95), labels = c('Low','High')) +
theme_minimal(base_family = 'Roboto Condensed') +
guides(color = guide_colourbar(title='Feature Value',title.vjust=1,barwidth = 10, barheight = .25,ticks = FALSE))+
facet_grid(rows = vars(GROUPS), scales = 'free_y', switch = 'y', space = 'free_y') +
theme(
strip.background = element_blank(),
strip.text = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(size = 5, color = 'black'),
# axis.text.y = element_text(size = 6, color = 'black',angle = 30, hjust=1),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
panel.border = element_blank(),
axis.line.x = element_line(size=1/.pt),
axis.text = element_text(color='black'),
legend.position = 'none',
panel.grid.major.y = element_blank(),
panel.spacing = unit(10, 'points'),
plot.margin=grid::unit(c(0,2,0,0), "mm")
)
# Extract color bar legend
plot.legend <- filt.timeSHAP.df %>%
filter(Baseline=='Static',
abs(SHAP) <= 0.5) %>%
ggplot() +
geom_vline(xintercept = 0, color = "darkgray") +
geom_quasirandom(aes(y=PLOT_LABEL,x=SHAP,color=ColorScale),groupOnX=FALSE,varwidth = FALSE,alpha = 0.6,stroke = 0,size=.75) +
scale_color_gradient2(na.value='black',low='#003f5c',mid='#eacaf4',high='#de425b',midpoint=.5,limits = c(0,1),breaks = c(0.05,.95), labels = c('Low','High')) +
theme_minimal(base_family = 'Roboto Condensed') +
guides(color = guide_colourbar(title='Feature Value',title.vjust=1,barwidth = 10, barheight = .25,ticks = FALSE))+
facet_grid(rows = vars(GROUPS), scales = 'free_y', switch = 'y', space = 'free_y') +
theme(
strip.background = element_blank(),
strip.text = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(size = 5, color = 'black'),
# axis.text.y = element_text(size = 6, color = 'black',angle = 30, hjust=1),
axis.text.y = element_blank(),
axis.title.x = element_blank(),
panel.border = element_blank(),
axis.line.x = element_line(size=1/.pt),
axis.text = element_text(color='black'),
legend.position = 'bottom',
# legend.position = 'none',
panel.grid.major.y = element_blank(),
panel.spacing = unit(10, 'points'),
legend.key.size = unit(1.3/.pt,'line'),
legend.title = element_text(size = 7, color = 'black',face = 'bold'),
legend.text=element_text(size=6),
plot.margin=grid::unit(c(0,0,0,0), "mm")
)
# Create directory for current date and save feature-level TimeSHAP plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'static_timeshap.png'),static.timeshap.plot,units='in',dpi=600,height=3.38,width=2.47)
ggsave(file.path('../plots',Sys.Date(),'dynamic_timeshap.png'),dynamic.timeshap.plot,units='in',dpi=600,height=3.38,width=2.47)
## Prepare dataframe of event-level TimeSHAP values for plotting
# Load and format event TimeSHAP value dataframe
event.timeSHAP.df <- read.csv('../model_interpretations/v6-0/timeSHAP/filtered_plotting_event_timeSHAP_values.csv',
na.strings = c("NA","NaN","", " ")) %>%
filter(Threshold == 'ExpectedValue') %>%
mutate(HoursBeforeTransition = sprintf('%d–%d',abs(2*(TimePreTransition+1)),abs(2*TimePreTransition))) %>%
mutate(HoursBeforeTransition = fct_reorder(HoursBeforeTransition,TimePreTransition))
# Create event importance violin plots for points before transition
event.timeshap.violin.plot <- event.timeSHAP.df %>%
ggplot(aes(x = HoursBeforeTransition, y = absSHAP)) +
geom_violin(scale = "width",trim=TRUE,fill='#9cc3dc',lwd=1.3/.pt) +
geom_quasirandom(varwidth = TRUE,alpha = 0.15,stroke = 0,size=.5) +
geom_boxplot(width=0.1,outlier.shape = NA,lwd=1.3/.pt) +
coord_cartesian(ylim = c(0,1.25)) +
ylab('Absolute effect on average prognosis (|TimeSHAP|)') +
xlab('Hours before significant transition') +
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold')
)
# Create directory for current date and save event-level TimeSHAP plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'event_timeshap.svg'),event.timeshap.violin.plot,device= svglite,units='in',dpi=600,width=7.5,height = 2.3)
### V. Figure 4
## Prepare dataframe of filtered test set predictions for plotting
# Load filtered test set predictions
plotting.test.preds <- read.csv('../model_outputs/v6-0/plotting_test_predictions.csv',
na.strings = c("NA","NaN","", " ")) %>%
select(GUPI,WindowIdx,REPEAT,FOLD,Pr.GOSE.1.,Pr.GOSE.3.,Pr.GOSE.4.,Pr.GOSE.5.,Pr.GOSE.6.,Pr.GOSE.7.) %>%
pivot_longer(cols=c(Pr.GOSE.1.,Pr.GOSE.3.,Pr.GOSE.4.,Pr.GOSE.5.,Pr.GOSE.6.,Pr.GOSE.7.),
names_to = "Threshold",
values_to = "Probability") %>%
mutate(Threshold = plyr::mapvalues(Threshold,
from = c("Pr.GOSE.1.","Pr.GOSE.3.","Pr.GOSE.4.","Pr.GOSE.5.","Pr.GOSE.6.","Pr.GOSE.7."),
to = c("GOSE>1","GOSE>3","GOSE>4","GOSE>5","GOSE>6","GOSE>7")))
# Calculate mean and variance of prediction values
summ.plotting.test.preds <- plotting.test.preds %>%
group_by(GUPI,WindowIdx,Threshold) %>%
summarise(meanProb = 100*mean(Probability),
stdProb = 100*sd(Probability)) %>%
mutate(stdProb = replace_na(stdProb,5)) %>%
rowwise() %>%
mutate(hiProb = min(meanProb+stdProb,100),
loProb = max(meanProb-stdProb,0),
DaysAfterICUAdmission = WindowIdx/12)
# Create line plots for individual patient trajectories at each GOSE
GOSE.1.plot <- indiv.pt.trajectory.plot(summ.plotting.test.preds,'5sMQ758',.1,'left') +
annotate('rect',xmin=(32/12),xmax=(36/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31')
GOSE.2.3.plot <- indiv.pt.trajectory.plot(summ.plotting.test.preds,'9isg322',.1,'right') +
annotate('rect',xmin=(3/12),xmax=(5/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(40/12),xmax=(46/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(76/12),xmax=(78/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(88/12),xmax=(90/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31')
GOSE.4.plot <- indiv.pt.trajectory.plot(summ.plotting.test.preds,'7YeE448',.05,'right') +
annotate('rect',xmin=(23/12),xmax=(26/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(48/12),xmax=(52/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(59/12),xmax=(62/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31')
GOSE.5.plot <- indiv.pt.trajectory.plot(summ.plotting.test.preds,'2DLL573',.7,'right') +
annotate('rect',xmin=(20/12),xmax=(24/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(68/12),xmax=(71/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(92/12),xmax=(96/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31')
GOSE.6.plot <- indiv.pt.trajectory.plot(summ.plotting.test.preds,'6xrH956',0,'right') +
annotate('rect',xmin=(8/12),xmax=(12/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(44/12),xmax=(49/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31')
GOSE.7.plot <- indiv.pt.trajectory.plot(summ.plotting.test.preds,'5HZz257',.25,'left') +
annotate('rect',xmin=(23/12),xmax=(27/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31')
GOSE.8.plot <- indiv.pt.trajectory.plot(summ.plotting.test.preds,'2BWg753',.1,'left') +
annotate('rect',xmin=(3/12),xmax=(7/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(42/12),xmax=(46/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31') +
annotate('rect',xmin=(30/12),xmax=(35/12),ymin=0,ymax=100,alpha=0.3,fill='#488f31')
# Create directory for current date and save individual patient trajectory
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'indiv_trajectory.svg'),GOSE.2.3.plot,device= svglite,units='in',dpi=600,width=7.5,height = 2.3)
ggsave(file.path('../plots',Sys.Date(),'GOSE_1_plot.png'),GOSE.1.plot,units='in',dpi=600,width=7.5,height = 2.3)
ggsave(file.path('../plots',Sys.Date(),'GOSE_4_plot.png'),GOSE.4.plot,units='in',dpi=600,width=7.5,height = 2.3)
ggsave(file.path('../plots',Sys.Date(),'GOSE_5_plot.png'),GOSE.5.plot,units='in',dpi=600,width=7.5,height = 2.3)
ggsave(file.path('../plots',Sys.Date(),'GOSE_6_plot.png'),GOSE.6.plot,units='in',dpi=600,width=7.5,height = 2.3)
ggsave(file.path('../plots',Sys.Date(),'GOSE_7_plot.png'),GOSE.7.plot,units='in',dpi=600,width=7.5,height = 2.3)
ggsave(file.path('../plots',Sys.Date(),'GOSE_8_plot.png'),GOSE.8.plot,units='in',dpi=600,width=7.5,height = 2.3)
## Create individual SHAP plots
# Load individual feature-level SHAP values
indiv.timeSHAP.df <- read.csv('../model_interpretations/v6-0/timeSHAP/individual_plotting_timeSHAP_values.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(Baseline = recode(as.character(Baseline),'True'='Static','False'='Dynamic')) %>%
mutate(Baseline = fct_relevel(Baseline, 'Static', 'Dynamic'))
indiv.timeSHAP.df$SHAP[(indiv.timeSHAP.df$Token=='Others')&(indiv.timeSHAP.df$Baseline=='Static')] = indiv.timeSHAP.df$SHAP[(indiv.timeSHAP.df$Token=='Others')&(indiv.timeSHAP.df$Baseline=='Static')]/253
indiv.timeSHAP.df$SHAP[(indiv.timeSHAP.df$Token=='Others')&(indiv.timeSHAP.df$Baseline=='Dynamic')] = indiv.timeSHAP.df$SHAP[(indiv.timeSHAP.df$Token=='Others')&(indiv.timeSHAP.df$Baseline=='Dynamic')]/138
# Create barplots
GOSE.1.static.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'5sMQ758','Static')
GOSE.2.3.static.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'9isg322','Static',T)
GOSE.4.static.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'7YeE448','Static')
GOSE.5.static.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'2DLL573','Static')
GOSE.6.static.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'6xrH956','Static')
GOSE.7.static.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'5HZz257','Static')
GOSE.8.static.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'2BWg753','Static')
GOSE.1.dynamic.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'5sMQ758','Dynamic')
GOSE.2.3.dynamic.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'9isg322','Dynamic',T)
GOSE.4.dynamic.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'7YeE448','Dynamic')
GOSE.5.dynamic.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'2DLL573','Dynamic')
GOSE.6.dynamic.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'6xrH956','Dynamic')
GOSE.7.dynamic.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'5HZz257','Dynamic')
GOSE.8.dynamic.plot <- indiv.pt.feature.barplot(indiv.timeSHAP.df,'2BWg753','Dynamic')
# Create directory for current date and save individual feature-level bar plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'indiv_static_barplots.svg'),GOSE.2.3.static.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_1_static_shap.svg'),GOSE.1.static.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_4_static_shap.svg'),GOSE.4.static.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_5_static_shap.svg'),GOSE.5.static.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_6_static_shap.svg'),GOSE.6.static.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_7_static_shap.svg'),GOSE.7.static.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_8_static_shap.svg'),GOSE.8.static.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'indiv_dynamic_barplots.svg'),GOSE.2.3.dynamic.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_1_dynamic_shap.svg'),GOSE.1.dynamic.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_4_dynamic_shap.svg'),GOSE.4.dynamic.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_5_dynamic_shap.svg'),GOSE.5.dynamic.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_6_dynamic_shap.svg'),GOSE.6.dynamic.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_7_dynamic_shap.svg'),GOSE.7.dynamic.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
ggsave(file.path('../plots',Sys.Date(),'GOSE_8_dynamic_shap.svg'),GOSE.8.dynamic.plot,device= svglite,units='in',dpi=600,width=2.34,height = 1.72)
## Create individual eventSHAP heatmaps
# Load individual event-level SHAP values
indiv.event.timeSHAP.df <- read.csv('../model_interpretations/v6-0/timeSHAP/individual_plotting_event_timeSHAP_values.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(HoursBeforeTransition = plyr::mapvalues(TimePreTransition,
from=c('-1','-2','-3','-4','-5','-6','-7','Pruned Events'),
to=c('0–2','2–4','4–6','6–8','8–10','10–12','12–14','Previous windows'))) %>%
mutate(HoursBeforeTransition = factor(HoursBeforeTransition,levels=c('Previous windows','12–14','10–12','8–10','6–8','4–6','2–4','0–2')),
SHAPLabel = sprintf('%.2f',SHAP))
# Create local event importance heat plot
GOSE.1.event.plot <- indiv.pt.event.heatmap(indiv.event.timeSHAP.df,'5sMQ758')
GOSE.2.3.event.plot <- indiv.pt.event.heatmap(indiv.event.timeSHAP.df,'9isg322')
GOSE.4.event.plot <- indiv.pt.event.heatmap(indiv.event.timeSHAP.df,'7YeE448')
GOSE.5.event.plot <- indiv.pt.event.heatmap(indiv.event.timeSHAP.df,'2DLL573')
GOSE.6.event.plot <- indiv.pt.event.heatmap(indiv.event.timeSHAP.df,'6xrH956')
GOSE.7.event.plot <- indiv.pt.event.heatmap(indiv.event.timeSHAP.df,'5HZz257')
GOSE.8.event.plot <- indiv.pt.event.heatmap(indiv.event.timeSHAP.df,'2BWg753')
# Create directory for current date and save individual feature-level bar plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'indiv_event_heatmaps.svg'),GOSE.2.3.event.plot,device= svglite,units='in',dpi=600,width=2.17,height = 1)
ggsave(file.path('../plots',Sys.Date(),'GOSE_1_event_shap.svg'),GOSE.1.event.plot,device= svglite,units='in',dpi=600,width=2.17,height = 1)
ggsave(file.path('../plots',Sys.Date(),'GOSE_4_event_shap.svg'),GOSE.4.event.plot,device= svglite,units='in',dpi=600,width=2.17,height = 1)
ggsave(file.path('../plots',Sys.Date(),'GOSE_5_event_shap.svg'),GOSE.5.event.plot,device= svglite,units='in',dpi=600,width=2.17,height = 1)
ggsave(file.path('../plots',Sys.Date(),'GOSE_6_event_shap.svg'),GOSE.6.event.plot,device= svglite,units='in',dpi=600,width=2.17,height = 1)
ggsave(file.path('../plots',Sys.Date(),'GOSE_7_event_shap.svg'),GOSE.7.event.plot,device= svglite,units='in',dpi=600,width=2.17,height = 1)
ggsave(file.path('../plots',Sys.Date(),'GOSE_8_event_shap.svg'),GOSE.8.event.plot,device= svglite,units='in',dpi=600,width=2.17,height = 1)
### VI. Supplementary Figures 5 and 6
## Prepare dataframes
physician.difference.CIs <- read.csv('../model_performance/v6-0/test_set_discrimination_difference_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
filter(METRIC == 'Somers D') %>%
mutate(SinceAdmission = WINDOW_IDX > 0) %>%
drop_na(median)
physician.difference.CIs$WINDOW_IDX[!physician.difference.CIs$SinceAdmission] <- physician.difference.CIs$WINDOW_IDX[!physician.difference.CIs$SinceAdmission] + 1
physician.difference.CIs <- physician.difference.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
discrimination.CIs <- read.csv('../model_performance/v6-0/test_set_discrimination_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 'All variables',
SinceAdmission = WINDOW_IDX > 0) %>%
filter(SinceAdmission,
METRIC == 'Somers D')
discrimination.CIs$WINDOW_IDX[!discrimination.CIs$SinceAdmission] <- discrimination.CIs$WINDOW_IDX[!discrimination.CIs$SinceAdmission] + 1
discrimination.CIs <- discrimination.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
v7.discrimination.CIs <- read.csv('../model_performance/v7-0/test_set_discrimination_CI.csv',
na.strings = c("NA","NaN","", " ")) %>%
mutate(VERSION = 'Without physician impressions',
SinceAdmission = WINDOW_IDX > 0) %>%
filter(SinceAdmission,
METRIC == 'Somers D',
TUNE_IDX==171)
v7.discrimination.CIs$WINDOW_IDX[!v7.discrimination.CIs$SinceAdmission] <- v7.discrimination.CIs$WINDOW_IDX[!v7.discrimination.CIs$SinceAdmission] + 1
v7.discrimination.CIs <- v7.discrimination.CIs %>%
mutate(DaysAfterICUAdmission = WINDOW_IDX/12)
discrimination.CIs <- rbind(discrimination.CIs,v7.discrimination.CIs)
## Create overall discrimination added with physician impression plots
# Since admission Somers' D plot with both models
since.adm.both.models.somers <- discrimination.CIs %>%
ggplot() +
coord_cartesian(xlim=c(0,7), ylim = c(35,55)) +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(.0, .0)))+
geom_line(aes(x=DaysAfterICUAdmission,y=100*median,color=VERSION),alpha = 1, size=1.3/.pt)+
geom_ribbon(aes(x=DaysAfterICUAdmission,ymin=lo*100,ymax=hi*100,fill=VERSION),alpha=.2) +
scale_fill_manual(values=c('#bc5090','#ffa600'))+
scale_color_manual(values=c('#bc5090','#ffa600'))+
ylab('Explanation of ordinal GOSE (%)')+
xlab('Days since ICU admission')+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold'),
legend.position = 'bottom',
legend.key.size = unit(1.3/.pt,'line'),
legend.title = element_blank(),
legend.text=element_text(size = 7, color = 'black',face = 'bold')
)
# Since admission difference in Somers' D plot
since.adm.physician.diff.somers <- physician.difference.CIs %>%
filter(SinceAdmission) %>%
ggplot() +
coord_cartesian(xlim=c(0,7), ylim = c(-5,10)) +
scale_x_continuous(breaks=seq(0,7,by=1),expand = expansion(mult = c(.0, .0)))+
geom_hline(yintercept = 0, color='dark gray',alpha = 1, size=1.3/.pt)+
geom_line(aes(x=DaysAfterICUAdmission,y=100*median),alpha = 1, size=1.3/.pt,color='#003f5c')+
geom_ribbon(aes(x=DaysAfterICUAdmission,ymin=lo*100,ymax=hi*100),alpha=.2,fill='#003f5c') +
ylab('Added explanation of ordinal GOSE (d%)')+
xlab('Days since ICU admission')+
theme_minimal(base_family = 'Roboto Condensed') +
theme(
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.text.y = element_text(size = 6, color = "black",margin = margin(r = 0)),
axis.title.x = element_text(size = 7, color = "black",face = 'bold'),
axis.title.y = element_text(size = 7, color = "black",face = 'bold')
)
# Create directory for current date and save post-admission and pre-discharge Somers' D plots
dir.create(file.path('../plots',Sys.Date()),showWarnings = F,recursive = T)
ggsave(file.path('../plots',Sys.Date(),'since_adm_both_models_somers.svg'),since.adm.both.models.somers,device= svglite,units='in',dpi=600,width=3.7,height = 1.78)
ggsave(file.path('../plots',Sys.Date(),'since_adm_physician_diff_somers.svg'),since.adm.physician.diff.somers,device= svglite,units='in',dpi=600,width=3.7,height = 1.38)
### VII. Supplementary Figures 8 and 9
## Global feature-level TimeSHAP plots for missing variables
# Load missing token TimeSHAP values
missing.value.timeSHAP.df <- read.csv('../model_interpretations/v6-0/timeSHAP/filtered_plotting_missing_timeSHAP_values.csv',
na.strings = c("NA","NaN","", " ")) %>%
filter(Threshold == 'ExpectedValue') %>%
mutate(Baseline = as.logical(Baseline),
Numeric = as.logical(Numeric),
GROUPS = case_when((RankIdx >= 11) ~ 'Top',
(RankIdx <= 10) ~'Bottom')) %>%
mutate(GROUPS = factor(GROUPS,levels=c('Top','Middle','Bottom')))
# Complete formatting dataframe prior to plotting
missing.value.timeSHAP.df <- missing.value.timeSHAP.df %>%
mutate(Baseline = recode(as.character(Baseline),'TRUE'='Static','FALSE'='Dynamic')) %>%
mutate(Baseline = fct_relevel(Baseline, 'Static', 'Dynamic')) %>%
mutate(BaseToken = fct_reorder(BaseToken, RankIdx))
# Create feature importance beeswarm plot for missing static predictors
missing.static.timeshap.plot <- missing.value.timeSHAP.df %>%
filter(Baseline=='Static') %>%
ggplot() +
geom_vline(xintercept = 0, color = "darkgray") +
geom_quasirandom(aes(y=BaseToken,x=SHAP),groupOnX=FALSE,varwidth = FALSE,alpha = 0.6,stroke = 0,size=.75,color='#003f5c') +
theme_minimal(base_family = 'Roboto Condensed') +
facet_grid(rows = vars(GROUPS), scales = 'free_y', switch = 'y', space = 'free_y') +
theme(
strip.background = element_blank(),
strip.text = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(size = 5, color = 'black'),
axis.text.y = element_text(size = 6, color = 'black'),
axis.title.x = element_blank(),
panel.border = element_blank(),
axis.line.x = element_line(size=1/.pt),
axis.text = element_text(color='black'),
legend.position = 'none',
panel.grid.major.y = element_blank(),
panel.spacing = unit(10, 'points'),
plot.margin=grid::unit(c(0,2,0,0), "mm")
)
# Create feature importance beeswarm plot for missing dynamic predictors
missing.dynamic.timeshap.plot <- missing.value.timeSHAP.df %>%
filter(Baseline=='Dynamic',
abs(SHAP) <= .1) %>%
ggplot() +
geom_vline(xintercept = 0, color = "darkgray") +
geom_quasirandom(aes(y=BaseToken,x=SHAP),groupOnX=FALSE,varwidth = FALSE,alpha = 0.6,stroke = 0,size=.75,color='#bc5090') +
theme_minimal(base_family = 'Roboto Condensed') +
facet_grid(rows = vars(GROUPS), scales = 'free_y', switch = 'y', space = 'free_y') +
theme(
strip.background = element_blank(),
strip.text = element_blank(),
axis.title.y = element_blank(),
axis.text.x = element_text(size = 5, color = 'black'),
axis.text.y = element_text(size = 6, color = 'black'),
axis.title.x = element_blank(),
panel.border = element_blank(),
axis.line.x = element_line(size=1/.pt),
axis.text = element_text(color='black'),
legend.position = 'none',
panel.grid.major.y = element_blank(),
panel.spacing = unit(10, 'points'),
plot.margin=grid::unit(c(0,2,0,0), "mm")
)
# Create directory for current date and save missing feature-level TimeSHAP plots