This repository has been archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
08.2.slade_aurum_sup_mat_plots.R
2418 lines (1982 loc) · 147 KB
/
08.2.slade_aurum_sup_mat_plots.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
####################
## Description:
## - In this file we create the plots used in the supplementary material of the paper
####################
## Load libraries
library(tidyverse)
library(patchwork)
library(scales)
library(forestplot)
library(rms)
## Load functions required
source("11.01.slade_aurum_functions.R")
source("11.02.slade_aurum_set_data.R")
## make directory for outputs
dir.create("Plots/Paper")
## make directory for outputs
dir.create("Plots/Paper/Sup_Mat")
#### Supplementary manuscript plots / stuff
## Flowchart 1
# Finding the number of individuals discarded for the training/validation dataset used in the model
# training dataset
hba1c.train <- set_up_data_sglt2_glp1(dataset.type = "hba1c.train")
hba1c.train.complete <- set_up_data_sglt2_glp1(dataset.type = "hba1c.train") %>%
# drop the variables with the most missingness (>40%)
select(-preacr, -preast, -prehaematocrit, -prehaemoglobin, -pretriglyceride) %>%
# only complete cases
drop_na() %>%
as.data.frame()
# nrow(hba1c.train)
# nrow(hba1c.train.complete)
# validation dataset
hba1c.test <- set_up_data_sglt2_glp1(dataset.type = "hba1c.test")
hba1c.test.complete <- set_up_data_sglt2_glp1(dataset.type = "hba1c.test") %>%
# selected variables from SparseBCF
select(patid, pated, posthba1cfinal, drugclass, unique(c(readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/variables_mu.rds"), readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/variables_tau.rds")))) %>%
# only complete cases
drop_na() %>%
as.data.frame()
# nrow(hba1c.test)
# nrow(hba1c.test.complete)
## Flowchart 2
# Finding the number of individuals discarded for the weight dataset (incomplete vars)
# weight dataset
weight.dataset <- set_up_data_sglt2_glp1(dataset.type = "weight.dataset")
weight.dataset.effects <- set_up_data_sglt2_glp1(dataset.type = "weight.dataset") %>%
left_join(readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/patient_effects.rds"), by = c("patid", "pated")) %>%
drop_na(effects)
# nrow(weight.dataset)
# nrow(weight.dataset.effects)
# no comorbidities
no_co.dataset <- set_up_data_sglt2_glp1(dataset.type = "no_co.dataset")
no_co.dataset.effects <- set_up_data_sglt2_glp1(dataset.type = "no_co.dataset") %>%
left_join(readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/patient_effects.rds"), by = c("patid", "pated")) %>%
drop_na(effects)
# nrow(no_co.dataset)
# nrow(no_co.dataset.effects)
# discontinuation
discontinuation.dataset <- set_up_data_sglt2_glp1(dataset.type = "discontinuation.dataset")
discontinuation.dataset.effects <- set_up_data_sglt2_glp1(dataset.type = "discontinuation.dataset") %>%
left_join(readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/patient_effects.rds"), by = c("patid", "pated")) %>%
drop_na(effects)
# nrow(discontinuation.dataset)
# nrow(discontinuation.dataset.effects)
# microvascular complications
micro_comp.dataset <- set_up_data_sglt2_glp1(dataset.type = "micro_comp.dataset")
micro_comp.dataset.effects <- set_up_data_sglt2_glp1(dataset.type = "micro_comp.dataset") %>%
left_join(readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/patient_effects.rds"), by = c("patid", "pated")) %>%
drop_na(effects)
# nrow(micro_comp.dataset)
# nrow(micro_comp.dataset.effects)
#:--------------------------------------------------------------------------------
### Variable selection from the Sparse BCF model
## Variable selection of sparcebcf for the moderator effect
variables_tau <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/assessment/variables_tau_original_chain_1.rds")
plot_variables_tau <- variables_tau %>%
rename("Current age" = "agetx",
"Sex" = "sex",
"Duration of diabetes" = "t2dmduration",
"Number of glucose-lowering drug classes ever prescribed" = "drugline",
"Number of other current glucose-lowering drugs" = "ncurrtx",
"Month of Hba1C measure" = "hba1cmonth",
"HbA1c" = "prehba1c",
"BMI" = "prebmi",
"eGFR" = "preegfr",
"Albumin" = "prealbuminblood",
"Alanine transaminase" = "prealt",
"Bilirubin" = "prebilirubin",
"HDL" = "prehdl",
"Mean arterial blood pressure" = "premap",
"Total cholesterol" = "pretotalcholesterol",
"Angina" = "preangina",
"Chronic liver disease" = "precld",
"Nephropathy" = "prediabeticnephropathy",
"Heart failure" = "preheartfailure",
"Hypertension" = "prehypertension",
"Ischaemic heart disease" = "preihd",
"Myocardial infarction" = "premyocardialinfarction",
"Neuropathy" = "preneuropathy",
"Peripheral arterial disease" = "prepad",
"Retinopathy" = "preretinopathy",
"Atherosclerotic cardiovascular disease" = "prerevasc",
"Stroke" = "prestroke",
"Transient ischaemic attack" = "pretia",
"Atrial fibrillation" = "preaf") %>%
as.data.frame() %>%
gather(key, value) %>%
arrange(desc(value)) %>%
mutate(key = factor(key),
colour = ifelse(value > 0.023, "Above", "Below"),
value = value*100) %>%
ggplot(aes(y = forcats::fct_reorder(key, value), x = value, colour = colour)) +
geom_vline(aes(xintercept = 0.023 * 100), colour = "red") +
geom_segment(aes(x = 0, xend = value, yend = forcats::fct_reorder(key, value)), linetype = "dashed") +
geom_point(size = 2) +
ggtitle("Moderator component") +
xlab("Posterior inclusion proportions (%)") +
scale_colour_manual(values = c("Above" = "black", "Below" = "grey")) +
theme_light() +
theme(axis.text.y = element_text(angle = 30, face = "bold", colour = c(rep("grey70", 18), rep("black", 12))),
axis.title.y = element_blank(),
legend.position = "none")
## Variable selection of sparcebcf for the prognostic effect
variables_mu <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/assessment/variables_mu_original_chain_1.rds")
plot_variables_mu <- variables_mu %>%
rename("Current age" = "agetx",
"Sex" = "sex",
"Duration of diabetes" = "t2dmduration",
"Number of glucose-lowering drug classes ever prescribed" = "drugline",
"Number of other current glucose-lowering drugs" = "ncurrtx",
"Month of Hba1C measure" = "hba1cmonth",
"HbA1c" = "prehba1c",
"BMI" = "prebmi",
"eGFR" = "preegfr",
"Albumin" = "prealbuminblood",
"Alanine transaminase" = "prealt",
"Bilirubin" = "prebilirubin",
"HDL" = "prehdl",
"Mean arterial blood pressure" = "premap",
"Total cholesterol" = "pretotalcholesterol",
"Angina" = "preangina",
"Chronic liver disease" = "precld",
"Nephropathy" = "prediabeticnephropathy",
"Heart failure" = "preheartfailure",
"Hypertension" = "prehypertension",
"Ischaemic heart disease" = "preihd",
"Myocardial infarction" = "premyocardialinfarction",
"Neuropathy" = "preneuropathy",
"Peripheral arterial disease" = "prepad",
"Retinopathy" = "preretinopathy",
"Atherosclerotic cardiovascular disease" = "prerevasc",
"Stroke" = "prestroke",
"Transient ischaemic attack" = "pretia",
"Atrial fibrillation" = "preaf",
"Propensity score" = "propensity score") %>%
as.data.frame() %>%
gather(key, value) %>%
arrange(desc(value)) %>%
mutate(key = factor(key),
colour = ifelse(value > 0.023, "Above", "Below"),
value = value*100) %>%
ggplot(aes(y = forcats::fct_reorder(key, value), x = value, colour = colour)) +
geom_vline(aes(xintercept = 0.023 * 100), colour = "red") +
geom_segment(aes(x = 0, xend = value, yend = forcats::fct_reorder(key, value)), linetype = "dashed") +
geom_point(size = 2) +
ggtitle("Prognostic component") +
xlab("Posterior inclusion proportions (%)") +
scale_colour_manual(values = c("Above" = "black", "Below" = "grey")) +
theme_light() +
theme(axis.text.y = element_text(angle = 30, face = "bold", colour = c(rep("grey70", 21), rep("black", 9))),
axis.title.y = element_blank(),
legend.position = "none")
# combining plots
plot_sup_1 <- patchwork::wrap_plots(list(plot_variables_mu, plot_variables_tau), ncol = 2) +
patchwork::plot_annotation(tag_levels = c('A'),
title = "BART model variable selection") # title of full plot
# pdf of plot
pdf(width = 14, height = 6, "Plots/Paper/Sup_Mat/11.08.plot_sup_1.pdf")
plot_sup_1
dev.off()
#:--------------------------------------------------------------------------------
### Comparing predictions of mu and tau for BCF prop / no prop
# comparing mu predictions
prop.score.comparison.mu <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/prop.score.comparison.mu.rds")
# comparing tau predictions
prop.score.comparison.tau <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/prop.score.comparison.rds")
# plot comparisons
plot_sup_2 <- patchwork::wrap_plots(
# scatter plot of mu values
prop.score.comparison.mu %>%
as.data.frame() %>%
ggplot(aes(x = bcf_prop, y = bcf_no_prop)) +
geom_abline(aes(intercept = 0, slope = 1), colour = "red", lty = "dashed") +
geom_point() +
theme_bw() +
labs(
x = "BCF model with propensity score",
y = "BCF model without propensity score",
title = "Predicted HbA1c outcome (mmol/mol)",
subtitle = "BCF without propensity score vs BCF with propensity score"
)
,
# density plot of residuals for mu (BCF without prop - BCF with prop)
prop.score.comparison.mu %>%
as.data.frame() %>%
mutate(effect.difference = bcf_no_prop - bcf_prop) %>%
ggplot() +
theme_bw() +
geom_density(aes(x = effect.difference)) +
labs(
x = "Difference in predicted HbA1c outcome (mmol/mol)",
y = "density",
title = "Predicted HbA1c outcome (mmol/mol)",
subtitle = "BCF without propensity score - BCF with propensity score"
) +
xlim(-10, 10)
,
# scatter plot of tau values
prop.score.comparison.tau %>%
as.data.frame() %>%
ggplot(aes(x = bcf_prop, y = bcf_no_prop)) +
theme_bw() +
geom_abline(aes(intercept = 0, slope = 1), colour = "red", lty = "dashed") +
geom_point() +
labs(
x = "BCF model with propensity score",
y = "BCF model without propensity score",
title = "Predicted conditional average treatment effects (CATE)",
subtitle = "BCF without propensity score vs BCF with propensity score"
)
,
# density plot of residuals for tau (BCF without prop - BCF with prop)
prop.score.comparison.tau %>%
as.data.frame() %>%
mutate(effect.difference = bcf_no_prop - bcf_prop) %>%
ggplot() +
theme_bw() +
geom_density(aes(x = effect.difference)) +
labs(
x = "Difference in predicted CATE (mmol/mol)",
y = "density",
title = "Predicted conditional average treatment effects (CATE)",
subtitle = "BCF without propensity score - BCF with propensity score"
) +
xlim(-4, 4)
, ncol = 2, nrow = 2) +
plot_annotation(tag_levels = list(c("A.1", "A.2", "B.1", "B.2")))
## PDF with the plot for the best therapy
pdf(width = 11, height = 11, "Plots/Paper/Sup_Mat/11.08.plot_sup_2.pdf")
plot_sup_2
dev.off()
#:--------------------------------------------------------------------------------
### Calibration of the model using PSM and PSM + adjusted
# load development cohort model calibration
ATE_matching_1_1_validation_dev <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/assessment/ATE_matching_1_1_validation_dev.rds")
ATE_matching_1_1_validation_val <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/assessment/ATE_matching_1_1_validation_val.rds")
ATE_matching_1_1_adjust_validation_dev <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/assessment/ATE_matching_1_1_adjust_validation_dev.rds")
ATE_matching_1_1_adjust_validation_val <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/assessment/ATE_matching_1_1_adjust_validation_val.rds")
# plot development cohort calibration
plot_ATE_matching_1_1_validation_dev <- ATE_plot(ATE_matching_1_1_validation_dev[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Derivation cohort (n=", format(sum(ATE_matching_1_1_validation_dev[["effects"]]$n_drug1)*2,big.mark=",",scientific=FALSE), ")"),
subtitle = "Propensity score matching"
)
plot_ATE_matching_1_1_validation_val <- ATE_plot(ATE_matching_1_1_validation_val[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Validation cohort (n=", format(sum(ATE_matching_1_1_validation_val[["effects"]]$n_drug1)*2,big.mark=",",scientific=FALSE), ")"),
subtitle = "Propensity score matching"
)
plot_ATE_matching_1_1_adjust_validation_dev <- ATE_plot(ATE_matching_1_1_adjust_validation_dev[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Derivation cohort (n=", format(sum(ATE_matching_1_1_validation_dev[["effects"]]$n_drug1)*2,big.mark=",",scientific=FALSE), ")"),
subtitle = "Propensity score matching and estimate adjustment"
)
plot_ATE_matching_1_1_adjust_validation_val <- ATE_plot(ATE_matching_1_1_adjust_validation_val[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Validation cohort (n=", format(sum(ATE_matching_1_1_validation_val[["effects"]]$n_drug1)*2,big.mark=",",scientific=FALSE), ")"),
subtitle = "Propensity score matching and estimate adjustment"
)
plot_sup_3 <- (plot_ATE_matching_1_1_validation_dev | plot_ATE_matching_1_1_validation_val) / (plot_ATE_matching_1_1_adjust_validation_dev | plot_ATE_matching_1_1_adjust_validation_val) +
plot_annotation(tag_levels = list(c("A.1", "A.2", "B.1", "B.2")))
## PDF with the plot for the best therapy
pdf(width = 10, height = 10, "Plots/Paper/Sup_Mat/11.08.plot_sup_3.pdf")
plot_sup_3
dev.off()
#:--------------------------------------------------------------------------------
### Clinical subgroup HbA1c outcome
## PSM
# levels needed
interval_breaks <- c(-5, -3, 0, 3, 5)
variables_mu <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/variables_mu.rds")
variables_tau <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/variables_tau.rds")
## Read in propensity scores
patient_prop_scores <- readRDS("Samples/SGLT2-GLP1/Aurum/ps_model/patient_prop_scores.rds")
## Read in treatment effects
treatment_effects <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/patient_effects.rds")
full.dataset <- set_up_data_sglt2_glp1(dataset.type = "full.cohort") %>%
left_join(patient_prop_scores, by = c("patid", "pated")) %>%
left_join(treatment_effects, by = c("patid", "pated")) %>%
mutate(hba1c.change = posthba1cfinal - prehba1c,
drugclass = factor(drugclass, levels = c("GLP1", "SGLT2")))
# still population into subgroups
group.full.dataset <- group_values(data = full.dataset,
variable = "effects",
breaks = interval_breaks) %>%
drop_na(intervals) %>%
rename("hba1c_diff" = "effects")
breakdown_adjust <- unique(c(variables_mu, variables_tau))
# categorical variables in breakdown
factors <- sapply(group.full.dataset[,breakdown_adjust], is.factor)
matching_hba1c <- MatchIt::matchit(
formula = formula(paste0("drugclass ~ agetx + t2dmduration + prehba1c + preegfr + prealt +", paste(breakdown_adjust[factors], collapse = "+"))),
data = group.full.dataset,
method = "nearest",
distance = group.full.dataset[,"prop.score"],
replace = FALSE,
m.order = "largest",
caliper = 0.05,
mahvars = NULL, estimand = "ATT", exact = NULL, antiexact = NULL, discard = "none", reestimate = FALSE, s.weights = NULL, std.caliper = TRUE, ratio = 1, verbose = FALSE, include.obj = FALSE,
)
# require(cobalt)
# cobalt::love.plot(matching_hba1c, binary = "std", thresholds = c(m = .1), sample.names = c("Unmatched", "Matched"), title = "Full dataset")
n_drug <- 2*sum(!is.na(matching_hba1c$match.matrix))
group.full.dataset.matched <- group.full.dataset %>%
slice(which(matching_hba1c$weights == 1))
# predictions for the hba1c adjusted model
predictions_hba1c_stan_psm_1_1_overall <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_hba1c_stan_psm_1_1_overall.rds") %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
uci = as.numeric(uci))
predictions_hba1c_stan_psm_1_1_full <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_hba1c_stan_psm_1_1_full.rds") %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
uci = as.numeric(uci))
# calculate axis limits for the plots
hba1c_strata_axis_min <- plyr::round_any(floor(min(c(predictions_hba1c_stan_psm_1_1_overall %>% select(c("mean","lci","uci")) %>% min(),
predictions_hba1c_stan_psm_1_1_full %>% select(c("mean","lci","uci")) %>% min()))), 5, f = floor)
hba1c_strata_axis_max <- plyr::round_any(floor(max(c(predictions_hba1c_stan_psm_1_1_overall %>% select(c("mean","lci","uci")) %>% max(),
predictions_hba1c_stan_psm_1_1_full %>% select(c("mean","lci","uci")) %>% max()))), 5, f = ceiling)
# plot predicted hba1c change
plot_a <- rbind(
cbind(intervals = "Predicted HbA1c benefit on SGLT2i", mean = 50, lci = 50, uci = 50, drugclass = "SGLT2"),
cbind(intervals = "Predicted HbA1c benefit on SGLT2i", mean = 50, lci = 50, uci = 50, drugclass = "GLP1"),
predictions_hba1c_stan_psm_1_1_overall %>% select(intervals, drugclass, mean, lci, uci) %>% slice(1:6),
cbind(intervals = "Predicted HbA1c benefit on GLP-1 RA", mean = 50, lci = 50, uci = 50, drugclass = "SGLT2"),
cbind(intervals = "Predicted HbA1c benefit on GLP-1 RA", mean = 50, lci = 50, uci = 50, drugclass = "GLP1"),
predictions_hba1c_stan_psm_1_1_overall %>% select(intervals, drugclass, mean, lci, uci) %>% slice(7:12),
predictions_hba1c_stan_psm_1_1_full %>% select(drugclass, mean, lci, uci) %>% mutate(intervals = "Average treatment effect")
) %>%
as.data.frame() %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
uci = as.numeric(uci),
intervals = ifelse(intervals == levels(group.full.dataset.matched$intervals)[1], paste0(">5 mmol/mol (n=", format(group.full.dataset.matched%>%filter(intervals == levels(group.full.dataset.matched$intervals)[1])%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.full.dataset.matched$intervals)[2], paste0("3-5 mmol/mol (n=", format(group.full.dataset.matched%>%filter(intervals == levels(group.full.dataset.matched$intervals)[2])%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.full.dataset.matched$intervals)[3], paste0("0-3 mmol/mol (n=", format(group.full.dataset.matched%>%filter(intervals == levels(group.full.dataset.matched$intervals)[3])%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.full.dataset.matched$intervals)[4], paste0("0-3 mmol/mol (n=", format(group.full.dataset.matched%>%filter(intervals == levels(group.full.dataset.matched$intervals)[4])%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.full.dataset.matched$intervals)[5], paste0("3-5 mmol/mol (n=", format(group.full.dataset.matched%>%filter(intervals == levels(group.full.dataset.matched$intervals)[5])%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.full.dataset.matched$intervals)[6], paste0(">5 mmol/mol (n=", format(group.full.dataset.matched%>%filter(intervals == levels(group.full.dataset.matched$intervals)[6])%>%nrow(),big.mark=",",scientific=FALSE), ")"), intervals))))))) %>%
rename("lower" = "lci", "upper" = "uci", "group" = "drugclass", "labeltext" = "intervals") %>%
group_by(group) %>%
mutate(group = ifelse(group == "SGLT2", "SGLT2i", "GLP-1RA")) %>%
forestplot(ci.vertices = TRUE,
fn.ci_norm = c(fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawDiamondCI),
ci.vertices.height = 0.1,
title = "Average HbA1c change",
clip = c(hba1c_strata_axis_min, hba1c_strata_axis_max),
xticks = seq(hba1c_strata_axis_min, hba1c_strata_axis_max, 5),
boxsize = .2,
txt_gp = fpTxtGp(ticks=gpar(cex=0.8), xlab=gpar(cex=1)),
xlab = "Predicted HbA1c change (mmol/mol)") %>%
fp_add_header(paste0("Overall population (n=", format(group.full.dataset.matched%>%nrow(),big.mark=",",scientific=FALSE), ")")) %>%
fp_set_style(box = c("#f1a340", "dodgerblue2") |> lapply(function(x) gpar(fill = x, col = "#555555")),
default = gpar(vertices = TRUE)) %>%
fp_add_lines(h_2 = "black",
h_6 = gpar(col = "black", lty = 2),
h_10 = "black")
### B - Weight
## Read in data for weight
weight.dataset <- set_up_data_sglt2_glp1(dataset.type = "weight.dataset") %>%
left_join(patient_prop_scores, by = c("patid", "pated")) %>%
left_join(treatment_effects, by = c("patid", "pated")) %>%
mutate(w.change = postweight - preweight)
group.weight.dataset <- group_values(data = weight.dataset,
variable = "effects",
breaks = interval_breaks) %>%
drop_na(intervals)
breakdown_adjust <- unique(c(variables_mu, variables_tau))
# categorical variables in breakdown
factors <- sapply(group.weight.dataset[,breakdown_adjust], is.factor)
matching_weight <- MatchIt::matchit(
formula = formula(paste0("drugclass ~ preweight + agetx + t2dmduration + prehba1c + preegfr + prealt +", paste(breakdown_adjust[factors], collapse = "+"))),
data = group.weight.dataset,
method = "nearest",
distance = group.weight.dataset[,"prop.score"],
replace = FALSE,
m.order = "largest",
caliper = 0.05,
mahvars = NULL, estimand = "ATT", exact = NULL, antiexact = NULL, discard = "none", reestimate = FALSE, s.weights = NULL, std.caliper = TRUE, ratio = 1, verbose = FALSE, include.obj = FALSE,
)
# require(cobalt)
# cobalt::love.plot(matching_weight, binary = "std", thresholds = c(m = .1), sample.names = c("Unmatched", "Matched"), title = "Full dataset")
n_drug <- 2*sum(!is.na(matching_weight$match.matrix))
group.weight.dataset.matched <- group.weight.dataset %>%
slice(which(matching_weight$weights == 1))
# predictions for the weight adjusted model
predictions_weight_stan_psm_1_1_overall <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_weight_stan_psm_1_1_overall.rds")
# predictions for the weight adjusted model full
predictions_weight_stan_psm_1_1_full <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_weight_stan_psm_1_1_full.rds")
weight_strata_axis_min <- plyr::round_any(floor(min(c(predictions_weight_stan_psm_1_1_overall %>% select(c("mean","lci","uci")) %>% as.data.frame() %>% gather() %>% select(value) %>% unlist() %>% as.numeric() %>% min(),
predictions_weight_stan_psm_1_1_full %>% select(c("mean","lci","uci")) %>% as.data.frame() %>% gather() %>% select(value) %>% unlist() %>% as.numeric() %>% min()))), 1, f = floor)
weight_strata_axis_max <- plyr::round_any(ceiling(max(c(predictions_weight_stan_psm_1_1_overall %>% select(c("mean","lci","uci")) %>% as.data.frame() %>% gather() %>% select(value) %>% unlist() %>% as.numeric() %>% max(),
predictions_weight_stan_psm_1_1_full %>% select(c("mean","lci","uci")) %>% as.data.frame() %>% gather() %>% select(value) %>% unlist() %>% as.numeric() %>% max()))), 2, f = ceiling)
plot_b <- rbind(
cbind(mean = 50, lci = 50, uci = 50, drugclass = "SGLT2", intervals = "Predicted HbA1c benefit on SGLT2i"),
cbind(mean = 50, lci = 50, uci = 50, drugclass = "GLP1", intervals = "Predicted HbA1c benefit on SGLT2i"),
predictions_weight_stan_psm_1_1_overall %>%
slice(c(1:6)),
cbind(mean = 50, lci = 50, uci = 50, drugclass = "SGLT2", intervals = "Predicted HbA1c benefit on GLP1-RA"),
cbind(mean = 50, lci = 50, uci = 50, drugclass = "GLP1", intervals = "Predicted HbA1c benefit on GLP1-RA"),
predictions_weight_stan_psm_1_1_overall %>%
slice(-c(1:6)),
predictions_weight_stan_psm_1_1_full %>% cbind(intervals = "Average treatment effect")
) %>%
as.data.frame() %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
intervals = ifelse(intervals == levels(group.weight.dataset.matched$intervals)[1], paste0(">5 mmol/mol (n=", format(group.weight.dataset.matched%>%filter(intervals==levels(group.weight.dataset.matched$intervals)[1])%>%nrow(),big.mark=",",scientific=FALSE),")"),
ifelse(intervals == levels(group.weight.dataset.matched$intervals)[2], paste0("3-5 mmol/mol (n=", format(group.weight.dataset.matched%>%filter(intervals==levels(group.weight.dataset.matched$intervals)[2])%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.weight.dataset.matched$intervals)[3], paste0("0-3 mmol/mol (n=", format(group.weight.dataset.matched%>%filter(intervals==levels(group.weight.dataset.matched$intervals)[3])%>%nrow(),big.mark=",",scientific=FALSE),")"),
ifelse(intervals == levels(group.weight.dataset.matched$intervals)[4], paste0("0-3 mmol/mol (n=", format(group.weight.dataset.matched%>%filter(intervals==levels(group.weight.dataset.matched$intervals)[4])%>%nrow(),big.mark=",",scientific=FALSE),")"),
ifelse(intervals == levels(group.weight.dataset.matched$intervals)[5], paste0("3-5 mmol/mol (n=", format(group.weight.dataset.matched%>%filter(intervals==levels(group.weight.dataset.matched$intervals)[5])%>%nrow(),big.mark=",",scientific=FALSE),")"),
ifelse(intervals == levels(group.weight.dataset.matched$intervals)[6], paste0(">5 mmol/mol (n=", format(group.weight.dataset.matched%>%filter(intervals==levels(group.weight.dataset.matched$intervals)[6])%>%nrow(),big.mark=",",scientific=FALSE),")"), intervals)))))),
uci = as.numeric(uci)) %>%
rename("lower" = "lci", "upper" = "uci", "group" = "drugclass", "labeltext" = "intervals") %>%
group_by(group) %>%
forestplot(ci.vertices = TRUE,
fn.ci_norm = c(fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawDiamondCI),
ci.vertices.height = 0.1,
title = "Average weight change",
clip = c(weight_strata_axis_min, weight_strata_axis_max),
xticks = seq(weight_strata_axis_min, weight_strata_axis_max, 1),
boxsize = .2,
txt_gp = fpTxtGp(ticks=gpar(cex=0.8), xlab=gpar(cex=1)),
xlab = "Predicted weight change (kg)") %>%
fp_add_header(paste0("Overall population (n=", format(group.weight.dataset.matched%>%nrow(),big.mark=",",scientific=FALSE), ")")) %>%
fp_set_style(box = c("#f1a340", "dodgerblue2") |> lapply(function(x) gpar(fill = x, col = "#555555")),
default = gpar(vertices = TRUE)) %>%
fp_add_lines(h_2 = "black",
h_6 = gpar(col = "black", lty = 2),
h_10 = "black")
### C - Discontinuation
discontinuation.dataset <- set_up_data_sglt2_glp1(dataset.type = "discontinuation.dataset") %>%
left_join(patient_prop_scores, by = c("patid", "pated")) %>%
left_join(treatment_effects, by = c("patid", "pated")) %>%
mutate(stopdrug_6m_3mFU = factor(stopdrug_6m_3mFU))
group.discontinuation.dataset <- group_values(data = discontinuation.dataset,
variable = "effects",
breaks = interval_breaks) %>%
drop_na(intervals)
breakdown_adjust <- unique(c(variables_mu, variables_tau))
# categorical variables in breakdown
factors <- sapply(group.discontinuation.dataset[,breakdown_adjust], is.factor)
matching_discontinuation <- MatchIt::matchit(
formula = formula(paste0("drugclass ~ agetx + t2dmduration + + prehba1c + preegfr + prealt +", paste(breakdown_adjust[factors], collapse = "+"))),
data = group.discontinuation.dataset,
method = "nearest",
distance = group.discontinuation.dataset[,"prop.score"],
replace = FALSE,
m.order = "largest",
caliper = 0.05,
mahvars = NULL, estimand = "ATT", exact = NULL, antiexact = NULL, discard = "none", reestimate = FALSE, s.weights = NULL, std.caliper = TRUE, ratio = 1, verbose = FALSE, include.obj = FALSE,
)
# require(cobalt)
# cobalt::love.plot(matching_discontinuation, binary = "std", thresholds = c(m = .1), sample.names = c("Unmatched", "Matched"), title = "Full dataset")
n_drug <- 2*sum(!is.na(matching_discontinuation$match.matrix))
group.discontinuation.dataset.matched <- group.discontinuation.dataset %>%
slice(which(matching_discontinuation$weights == 1))
# predictions for the discontinuation adjusted model
predictions_discontinuation_stan_psm_1_1_overall <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_discontinuation_stan_psm_1_1_overall.rds")
# predictions for the discontinuation model sex strata
predictions_discontinuation_stan_psm_1_1_full <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_discontinuation_stan_psm_1_1_full.rds")
discontinuation_overall_axis_max <- plyr::round_any(ceiling(max(c(predictions_discontinuation_stan_psm_1_1_overall %>% select(c("mean","lci","uci")) %>% as.data.frame() %>% gather() %>% select(value) %>% unlist() %>% as.numeric() %>% max() * 100,
predictions_discontinuation_stan_psm_1_1_full %>% select(c("mean","lci","uci")) %>% as.data.frame() %>% gather() %>% select(value) %>% unlist() %>% as.numeric() %>% max() * 100))), 5, f = ceiling)
discontinuation_strata_axis_max <- plyr::round_any(ceiling(max(c(predictions_discontinuation_stan_psm_1_1_overall %>% select(c("mean","lci","uci")) %>% as.data.frame() %>% gather() %>% select(value) %>% unlist() %>% as.numeric() %>% max() * 100,
predictions_discontinuation_stan_psm_1_1_full %>% select(c("mean","lci","uci")) %>% as.data.frame() %>% gather() %>% select(value) %>% unlist() %>% as.numeric() %>% max() * 100))), 5, f = ceiling)
plot_c <- rbind(
cbind(mean = 150, lci = 150, uci = 150, drugclass = "SGLT2", intervals = "Predicted HbA1c benefit on SGLT2i"),
cbind(mean = 150, lci = 150, uci = 150, drugclass = "GLP1", intervals = "Predicted HbA1c benefit on SGLT2i"),
predictions_discontinuation_stan_psm_1_1_overall %>%
slice(c(1:6)) %>%
mutate(mean = as.numeric(mean)*100,
lci = as.numeric(lci)*100,
uci = as.numeric(uci)*100),
cbind(mean = 150, lci = 150, uci = 150, drugclass = "SGLT2", intervals = "Predicted HbA1c benefit on GLP1-RA"),
cbind(mean = 150, lci = 150, uci = 150, drugclass = "GLP1", intervals = "Predicted HbA1c benefit on GLP1-RA"),
predictions_discontinuation_stan_psm_1_1_overall %>%
slice(-c(1:6)) %>%
mutate(mean = as.numeric(mean)*100,
lci = as.numeric(lci)*100,
uci = as.numeric(uci)*100),
predictions_discontinuation_stan_psm_1_1_full %>% cbind(intervals = "Average treatment effect") %>%
mutate(mean = as.numeric(mean)*100,
lci = as.numeric(lci)*100,
uci = as.numeric(uci)*100)
) %>%
as.data.frame() %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
intervals = ifelse(intervals == levels(group.discontinuation.dataset.matched$intervals)[1], paste0(">5 mmol/mol (n=", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[1])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[1])%>%filter(stopdrug_6m_3mFU==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.discontinuation.dataset.matched$intervals)[2], paste0("3-5 mmol/mol (n=", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[2])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[2])%>%filter(stopdrug_6m_3mFU==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.discontinuation.dataset.matched$intervals)[3], paste0("0-3 mmol/mol (n=", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[3])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[3])%>%filter(stopdrug_6m_3mFU==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.discontinuation.dataset.matched$intervals)[4], paste0("0-3 mmol/mol (n=", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[4])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[4])%>%filter(stopdrug_6m_3mFU==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.discontinuation.dataset.matched$intervals)[5], paste0("3-5 mmol/mol (n=", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[5])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[5])%>%filter(stopdrug_6m_3mFU==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.discontinuation.dataset.matched$intervals)[6], paste0(">5 mmol/mol (n=", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[6])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.discontinuation.dataset.matched%>%filter(intervals==levels(group.discontinuation.dataset.matched$intervals)[6])%>%filter(stopdrug_6m_3mFU==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"), intervals)))))),
uci = as.numeric(uci)) %>%
rename("lower" = "lci", "upper" = "uci", "group" = "drugclass", "labeltext" = "intervals") %>%
group_by(group) %>%
forestplot(ci.vertices = TRUE,
fn.ci_norm = c(fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawDiamondCI),
ci.vertices.height = 0.1,
title = "Risk of discontinuation",
clip = c(0, discontinuation_overall_axis_max),
xticks = seq(0, discontinuation_overall_axis_max, 5),
boxsize = .2,
txt_gp = fpTxtGp(ticks=gpar(cex=0.8), xlab=gpar(cex=1)),
xlab = "Discontinuation (%)") %>%
fp_add_header(paste0("Overall population (n=", format(group.discontinuation.dataset.matched%>%nrow(),big.mark=",",scientific=FALSE), ")")) %>%
fp_set_style(box = c("#f1a340", "dodgerblue2") |> lapply(function(x) gpar(fill = x, col = "#555555")),
default = gpar(vertices = TRUE)) %>%
fp_add_lines(h_2 = "black",
h_6 = gpar(col = "black", lty = 2),
h_10 = "black")
### D - Risk of developing microvascular complications
patient_prop_scores_qrisk <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/patient_prop_scores_qrisk.rds")
micro_comp.dataset <- set_up_data_sglt2_glp1(dataset.type="micro_comp.dataset") %>%
left_join(patient_prop_scores_qrisk, by = c("patid", "pated")) %>%
left_join(treatment_effects, by = c("patid", "pated"))
group.micro_comp.dataset <- group_values(data = micro_comp.dataset,
variable = "effects",
breaks = interval_breaks) %>%
drop_na(intervals)
matching_micro_comp <- MatchIt::matchit(
formula = formula(paste0("drugclass ~ agetx + t2dmduration + prehba1c + preegfr + prealt + drugline + ncurrtx + sex + preneuropathy + preretinopathy")),
data = group.micro_comp.dataset,
method = "nearest",
distance = group.micro_comp.dataset[,"prop.score"],
replace = FALSE,
m.order = "largest",
caliper = 0.05,
mahvars = NULL, estimand = "ATT", exact = NULL, antiexact = NULL, discard = "none", reestimate = FALSE, s.weights = NULL, std.caliper = TRUE, ratio = 1, verbose = FALSE, include.obj = FALSE,
)
# require(cobalt)
# cobalt::love.plot(matching_micro_comp, binary = "std", thresholds = c(m = .1), sample.names = c("Unmatched", "Matched"), title = "Full dataset")
n_drug <- 2*sum(!is.na(matching_micro_comp$match.matrix))
group.micro_comp.dataset.matched <- group.micro_comp.dataset %>%
slice(which(matching_micro_comp$weights == 1))
# predictions for the CVD outcomes in the population with no CVD/HF/CKD
predictions_micro_comp_micro_comp_stan_psm_1_1_overall <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_micro_comp_micro_comp_stan_psm_1_1_overall.rds")
# predictions for the CVD outcomes in the population with no CVD/HF/CKD
predictions_micro_comp_micro_comp_stan_psm_1_1_full <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_micro_comp_micro_comp_stan_psm_1_1_full.rds")
# plot of forest plot
plot_d <- rbind(
cbind(intervals = "Predicted HbA1c benefit on SGLT2i", mean = NA, lci = NA, uci = NA),
predictions_micro_comp_micro_comp_stan_psm_1_1_overall %>% slice(1:3),
cbind(intervals = "Predicted HbA1c benefit on GLP1-RA", mean = NA, lci = NA, uci = NA),
predictions_micro_comp_micro_comp_stan_psm_1_1_overall %>% slice(4:6),
predictions_micro_comp_micro_comp_stan_psm_1_1_full %>% cbind(intervals = "Average treatment effect")
) %>%
as.data.frame() %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
uci = as.numeric(uci),
intervals = ifelse(intervals == levels(group.micro_comp.dataset.matched$intervals)[1], paste0(">5 mmol/mol (n=", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[1])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[1])%>%filter(postdrug_micro_comp_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.micro_comp.dataset.matched$intervals)[2], paste0("3-5 mmol/mol (n=", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[2])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[2])%>%filter(postdrug_micro_comp_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.micro_comp.dataset.matched$intervals)[3], paste0("0-3 mmol/mol (n=", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[3])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[3])%>%filter(postdrug_micro_comp_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.micro_comp.dataset.matched$intervals)[4], paste0("0-3 mmol/mol (n=", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[4])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[4])%>%filter(postdrug_micro_comp_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.micro_comp.dataset.matched$intervals)[5], paste0("3-5 mmol/mol (n=", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[5])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[5])%>%filter(postdrug_micro_comp_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.micro_comp.dataset.matched$intervals)[6], paste0(">5 mmol/mol (n=", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[6])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.micro_comp.dataset.matched%>%filter(intervals==levels(group.micro_comp.dataset.matched$intervals)[6])%>%filter(postdrug_micro_comp_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"), intervals))))))) %>%
rename("lower" = "lci", "upper" = "uci") %>%
mutate(mean = exp(mean),
lower = exp(lower),
upper = exp(upper)) %>%
forestplot(labeltext = intervals,
fn.ci_norm = c(fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawDiamondCI),
ci.vertices = TRUE,
zero = 1,
title = "Microvascular complications",
xlog = TRUE,
ci.vertices.height = 0.05,
boxsize = .1,
txt_gp = fpTxtGp(ticks=gpar(cex=0.8), xlab=gpar(cex=1)),
xlab = "Hazard ratio (95% CI, log scale)") %>%
fp_add_header(paste0("Overall population (n=", format(nrow(group.micro_comp.dataset.matched),big.mark=",",scientific=FALSE), ")")) %>%
fp_add_lines(h_2 = "black",
h_6 = gpar(col = "black", lty = 2),
h_10 = "black")
### E - Risk of developing MACE/CVD
patient_prop_scores_qrisk <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/patient_prop_scores_qrisk.rds")
no_co.dataset <- set_up_data_sglt2_glp1(dataset.type="no_co.dataset") %>%
left_join(patient_prop_scores_qrisk, by = c("patid", "pated")) %>%
left_join(treatment_effects, by = c("patid", "pated"))
group.no_co.dataset <- group_values(data = no_co.dataset,
variable = "effects",
breaks = interval_breaks) %>%
drop_na(intervals)
breakdown_adjust <- unique(c(variables_mu, variables_tau))
# categorical variables in breakdown
factors <- sapply(group.no_co.dataset[,breakdown_adjust], is.factor)
matching_no_co <- MatchIt::matchit(
formula = formula(paste0("drugclass ~ agetx + t2dmduration + prehba1c + preegfr + prealt + drugline + ncurrtx + sex + preneuropathy + preretinopathy")),
data = group.no_co.dataset,
method = "nearest",
distance = group.no_co.dataset[,"prop.score"],
replace = FALSE,
m.order = "largest",
caliper = 0.05,
mahvars = NULL, estimand = "ATT", exact = NULL, antiexact = NULL, discard = "none", reestimate = FALSE, s.weights = NULL, std.caliper = TRUE, ratio = 1, verbose = FALSE, include.obj = FALSE,
)
# require(cobalt)
# cobalt::love.plot(matching_no_co, binary = "std", thresholds = c(m = .1), sample.names = c("Unmatched", "Matched"), title = "Full dataset")
n_drug <- 2*sum(!is.na(matching_no_co$match.matrix))
group.no_co.dataset.matched <- group.no_co.dataset %>%
slice(which(matching_no_co$weights == 1))
# predictions for the CVD outcomes in the population with no CVD/HF/CKD
predictions_no_co_cvd_stan_psm_1_1_overall <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_no_co_cvd_stan_psm_1_1_overall.rds")
# predictions for the CVD outcomes in the population with no CVD/HF/CKD
predictions_no_co_cvd_stan_psm_1_1_full <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_no_co_cvd_stan_psm_1_1_full.rds")
# plot of forest plot
plot_e <- rbind(
cbind(intervals = "Predicted HbA1c benefit on SGLT2i", mean = NA, lci = NA, uci = NA),
predictions_no_co_cvd_stan_psm_1_1_overall %>% slice(1:3),
cbind(intervals = "Predicted HbA1c benefit on GLP1-RA", mean = NA, lci = NA, uci = NA),
predictions_no_co_cvd_stan_psm_1_1_overall %>% slice(4:6),
predictions_no_co_cvd_stan_psm_1_1_full %>% cbind(intervals = "Average treatment effect")
) %>%
as.data.frame() %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
uci = as.numeric(uci),
intervals = ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[1], paste0(">5 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[1])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[1])%>%filter(postdrug_mace_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[2], paste0("3-5 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[2])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[2])%>%filter(postdrug_mace_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[3], paste0("0-3 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[3])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[3])%>%filter(postdrug_mace_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[4], paste0("0-3 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[4])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[4])%>%filter(postdrug_mace_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[5], paste0("3-5 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[5])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[5])%>%filter(postdrug_mace_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[6], paste0(">5 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[6])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[6])%>%filter(postdrug_mace_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"), intervals))))))) %>%
rename("lower" = "lci", "upper" = "uci") %>%
mutate(mean = exp(mean),
lower = exp(lower),
upper = exp(upper)) %>%
forestplot(labeltext = intervals,
fn.ci_norm = c(fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawDiamondCI),
ci.vertices = TRUE,
zero = 1,
title = "Major adverse cardiovascular events",
xlog = TRUE,
ci.vertices.height = 0.05,
boxsize = .1,
txt_gp = fpTxtGp(ticks=gpar(cex=0.8), xlab=gpar(cex=1)),
xlab = "Hazard ratio (95% CI, log scale)") %>%
fp_add_header(paste0("Overall population (n=", format(nrow(group.no_co.dataset.matched),big.mark=",",scientific=FALSE), ")")) %>%
fp_add_lines(h_2 = "black",
h_6 = gpar(col = "black", lty = 2),
h_10 = "black")
### F - Risk of developing Heart Failure
# predictions for the HF outcomes in the population with no CVD/HF/CKD
predictions_no_co_hf_stan_psm_1_1_overall <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_no_co_hf_stan_psm_1_1_overall.rds")
# predictions for the CVD outcomes in the population with no CVD/HF/CKD
predictions_no_co_hf_stan_psm_1_1_full <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_no_co_hf_stan_psm_1_1_full.rds")
plot_f <- rbind(
cbind(intervals = "Predicted HbA1c benefit on SGLT2i", mean = NA, lci = NA, uci = NA),
predictions_no_co_hf_stan_psm_1_1_overall %>% slice(1:3),
cbind(intervals = "Predicted HbA1c benefit on GLP1-RA", mean = NA, lci = NA, uci = NA),
predictions_no_co_hf_stan_psm_1_1_overall %>% slice(4:6),
predictions_no_co_hf_stan_psm_1_1_full %>% cbind(intervals = "Average treatment effect")
) %>%
as.data.frame() %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
uci = as.numeric(uci),
intervals = ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[1], paste0(">5 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[1])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[1])%>%filter(postdrug_hf_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[2], paste0("3-5 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[2])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[2])%>%filter(postdrug_hf_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[3], paste0("0-3 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[3])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[3])%>%filter(postdrug_hf_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[4], paste0("0-3 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[4])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[4])%>%filter(postdrug_hf_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[5], paste0("3-5 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[5])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[5])%>%filter(postdrug_hf_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"),
ifelse(intervals == levels(group.no_co.dataset.matched$intervals)[6], paste0(">5 mmol/mol (n=", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[6])%>%nrow(),big.mark=",",scientific=FALSE), ", events = ", format(group.no_co.dataset.matched%>%filter(intervals==levels(group.no_co.dataset.matched$intervals)[6])%>%filter(postdrug_hf_censvar==1)%>%nrow(),big.mark=",",scientific=FALSE), ")"), intervals))))))) %>%
rename("lower" = "lci", "upper" = "uci") %>%
mutate(mean = exp(mean),
lower = exp(lower),
upper = exp(upper)) %>%
forestplot(labeltext = intervals,
fn.ci_norm = c(fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawNormalCI, fpDrawDiamondCI),
ci.vertices = TRUE,
zero = 1,
title = "Heart failure",
xlog = TRUE,
ci.vertices.height = 0.05,
boxsize = .1,
txt_gp = fpTxtGp(ticks=gpar(cex=0.8), xlab=gpar(cex=1)),
xlab = "Hazard ratio (95% CI, log scale)") %>%
fp_add_header(paste0("Overall population (n=", format(nrow(group.no_co.dataset.matched),big.mark=",",scientific=FALSE), ")")) %>%
fp_add_lines(h_2 = "black",
h_6 = gpar(col = "black", lty = 2),
h_10 = "black")
pdf(width = 20, height = 10, "Plots/Paper/Sup_Mat/11.08.plot_sup_4.pdf")
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow = 2,
ncol = 3, heights = unit(c(5, 5), "null"))))
# 1 2 3
# 4 5 6
# first plot
pushViewport(viewport(layout.pos.row = 1,
layout.pos.col = 1))
plot_a
upViewport()
# second plot
pushViewport(viewport(layout.pos.row = 1,
layout.pos.col = 2))
plot_b
upViewport()
# third plot
pushViewport(viewport(layout.pos.row = 1,
layout.pos.col = 3))
plot_c
upViewport()
# forth plot
pushViewport(viewport(layout.pos.row = 2,
layout.pos.col = 1))
plot_d
upViewport()
# fifth plot
pushViewport(viewport(layout.pos.row = 2,
layout.pos.col = 2))
plot_e
upViewport()
# third plot
pushViewport(viewport(layout.pos.row = 2,
layout.pos.col = 3))
plot_f
upViewport()
# add legends
grid.text(expression(bold("A.1")), vp = viewport(layout.pos.row = 1, layout.pos.col = 1), hjust = 12, vjust = -18)
grid.text(expression(bold("A.2")), vp = viewport(layout.pos.row = 1, layout.pos.col = 2), hjust = 12, vjust = -18)
grid.text(expression(bold("A.3")), vp = viewport(layout.pos.row = 1, layout.pos.col = 3), hjust = 12, vjust = -17.5)
grid.text(expression(bold("B.1")), vp = viewport(layout.pos.row = 2, layout.pos.col = 1), hjust = 12, vjust = -18)
grid.text(expression(bold("B.2")), vp = viewport(layout.pos.row = 2, layout.pos.col = 2), hjust = 12, vjust = -18)
grid.text(expression(bold("B.3")), vp = viewport(layout.pos.row = 2, layout.pos.col = 3), hjust = 12, vjust = -17.5)
dev.off()
#:--------------------------------------------------------------------------------
### Clinical subgroup HbA1c outcome
## PSM + adjust
# levels needed
interval_breaks <- c(-5, -3, 0, 3, 5)
variables_mu <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/variables_mu.rds")
variables_tau <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/variables_tau.rds")
## Read in propensity scores
patient_prop_scores <- readRDS("Samples/SGLT2-GLP1/Aurum/ps_model/patient_prop_scores.rds")
## Read in treatment effects
treatment_effects <- readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/patient_effects.rds")
full.dataset <- set_up_data_sglt2_glp1(dataset.type = "full.cohort") %>%
left_join(patient_prop_scores, by = c("patid", "pated")) %>%
left_join(treatment_effects, by = c("patid", "pated")) %>%
mutate(hba1c.change = posthba1cfinal - prehba1c,
drugclass = factor(drugclass, levels = c("GLP1", "SGLT2")))
# still population into subgroups
group.full.dataset <- group_values(data = full.dataset,
variable = "effects",
breaks = interval_breaks) %>%
drop_na(intervals) %>%
rename("hba1c_diff" = "effects")
breakdown_adjust <- unique(c(variables_mu, variables_tau))
# categorical variables in breakdown
factors <- sapply(group.full.dataset[,breakdown_adjust], is.factor)
matching_hba1c <- MatchIt::matchit(
formula = formula(paste0("drugclass ~ agetx + t2dmduration + prehba1c + preegfr + prealt +", paste(breakdown_adjust[factors], collapse = "+"))),
data = group.full.dataset,
method = "nearest",
distance = group.full.dataset[,"prop.score"],
replace = FALSE,
m.order = "largest",
caliper = 0.05,
mahvars = NULL, estimand = "ATT", exact = NULL, antiexact = NULL, discard = "none", reestimate = FALSE, s.weights = NULL, std.caliper = TRUE, ratio = 1, verbose = FALSE, include.obj = FALSE,
)
# require(cobalt)
# cobalt::love.plot(matching_hba1c, binary = "std", thresholds = c(m = .1), sample.names = c("Unmatched", "Matched"), title = "Full dataset")
n_drug <- 2*sum(!is.na(matching_hba1c$match.matrix))
group.full.dataset.matched <- group.full.dataset %>%
slice(which(matching_hba1c$weights == 1))
# predictions for the hba1c adjusted model
predictions_hba1c_stan_psm_1_1_adjusted_overall <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_hba1c_stan_psm_1_1_adjusted_overall.rds") %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
uci = as.numeric(uci))
predictions_hba1c_stan_psm_1_1_adjusted_full <- readRDS("Samples/SGLT2-GLP1/Aurum/additional_outcomes/predictions_hba1c_stan_psm_1_1_adjusted_full.rds") %>%
mutate(mean = as.numeric(mean),
lci = as.numeric(lci),
uci = as.numeric(uci))
# calculate axis limits for the plots
hba1c_strata_axis_min <- plyr::round_any(floor(min(c(predictions_hba1c_stan_psm_1_1_adjusted_overall %>% select(c("mean","lci","uci")) %>% min(),
predictions_hba1c_stan_psm_1_1_adjusted_full %>% select(c("mean","lci","uci")) %>% min()))), 5, f = floor)
hba1c_strata_axis_max <- plyr::round_any(floor(max(c(predictions_hba1c_stan_psm_1_1_adjusted_overall %>% select(c("mean","lci","uci")) %>% max(),