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
/
Copy path13.slade_aurum_cvd-n_cvd_validation.R
150 lines (110 loc) · 8.21 KB
/
13.slade_aurum_cvd-n_cvd_validation.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
####################
## Description:
## - In this file we validate the model in those with and without CVD.
####################
## Load libraries
library(tidyverse)
library(patchwork)
## Set up directory path to save files (stagered to ensure folders are created)
dir.create("Samples")
dir.create("Samples/SGLT2-GLP1")
output_path <- "Samples/SGLT2-GLP1/Aurum"
dir.create(output_path)
## make directory for outputs
dir.create("Plots")
###############################################################################
###############################################################################
############################### Read Data In ##################################
###############################################################################
###############################################################################
## Load functions required
source("01.slade_aurum_functions.R")
source("02.slade_aurum_set_data.R")
###############################################################################
###############################################################################
########################## General variables ##################################
###############################################################################
###############################################################################
# load in variables used in the model
variables_mu <- readRDS(paste0(output_path, "/response_model_bcf/variables_mu.rds"))
variables_tau <- readRDS(paste0(output_path, "/response_model_bcf/variables_tau.rds"))
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")
hba1c.test <- set_up_data_sglt2_glp1(dataset.type = "hba1c.test") %>%
left_join(readRDS("Samples/SGLT2-GLP1/Aurum/response_model_bcf/patient_effects.rds"), by = c("patid", "pated")) %>%
left_join(readRDS("Samples/SGLT2-GLP1/Aurum/ps_model/patient_prop_scores.rds"), by = c("patid", "pated"))
hba1c.test.with.cvd <- hba1c.test %>%
filter(preangina == "Yes" | preaf == "Yes" | prerevasc == "Yes" | preheartfailure == "Yes" |preihd == "Yes" | premyocardialinfarction == "Yes" | prestroke == "Yes" | pretia == "Yes") %>%
mutate(hba1c_diff.q = ntile(effects, 10)) %>%
rename("hba1c_diff" = "effects") %>%
drop_na(hba1c_diff.q)
ATE_psm_1_1_hba1c.test.with.cvd <- calc_ATE(data = hba1c.test.with.cvd,
validation_type = "PSM", variable = "posthba1cfinal",
quantile_var = "hba1c_diff.q", prop_scores = hba1c.test.with.cvd$prop.score,
order = "largest", breakdown = unique(c(variables_tau, variables_mu)))
ATE_psm_1_1_adjusted_hba1c.test.with.cvd <- calc_ATE(data = hba1c.test.with.cvd,
validation_type = "PSM + adjust", variable = "posthba1cfinal",
quantile_var = "hba1c_diff.q", prop_scores = hba1c.test.with.cvd$prop.score,
order = "largest", breakdown = unique(c(variables_tau, variables_mu)))
ATE_adjusted_hba1c.test.with.cvd <- calc_ATE(data = hba1c.test.with.cvd,
validation_type = "Adjust", variable = "posthba1cfinal",
quantile_var = "hba1c_diff.q",
order = "largest", breakdown = unique(c(variables_tau, variables_mu)))
plot_ATE_psm_1_1_hba1c.test.with.cvd <- ATE_plot(ATE_psm_1_1_hba1c.test.with.cvd[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Cohort with CVD (n=", format(sum(ATE_psm_1_1_hba1c.test.with.cvd[["effects"]]$n_drug1)*2,big.mark=",",scientific=FALSE), ")"),
subtitle = "Propensity score matching"
)
plot_ATE_psm_1_1_adjusted_hba1c.test.with.cvd <- ATE_plot(ATE_psm_1_1_adjusted_hba1c.test.with.cvd[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Cohort with CVD (n=", format(sum(ATE_psm_1_1_adjusted_hba1c.test.with.cvd[["effects"]]$n_drug1)*2,big.mark=",",scientific=FALSE), ")"),
subtitle = "Propensity score matching and estimate adjustment"
)
plot_ATE_adjusted_hba1c.test.with.cvd <- ATE_plot(ATE_adjusted_hba1c.test.with.cvd[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Cohort with CVD (n=", format(sum(ATE_adjusted_hba1c.test.with.cvd[["effects"]]$N),big.mark=",",scientific=FALSE), ")"),
subtitle = "Estimate adjustment"
)
hba1c.test.without.cvd <- hba1c.test %>%
filter(!pated %in% hba1c.test.with.cvd$pated) %>%
mutate(hba1c_diff.q = ntile(effects, 10)) %>%
rename("hba1c_diff" = "effects") %>%
drop_na(hba1c_diff.q)
ATE_psm_1_1_hba1c.test.without.cvd <- calc_ATE(data = hba1c.test.without.cvd,
validation_type = "PSM", variable = "posthba1cfinal",
quantile_var = "hba1c_diff.q", prop_scores = hba1c.test.without.cvd$prop.score,
order = "largest", breakdown = unique(c(variables_tau, variables_mu)))
ATE_psm_1_1_adjusted_hba1c.test.without.cvd <- calc_ATE(data = hba1c.test.without.cvd,
validation_type = "PSM + adjust", variable = "posthba1cfinal",
quantile_var = "hba1c_diff.q", prop_scores = hba1c.test.without.cvd$prop.score,
order = "largest", breakdown = unique(c(variables_tau, variables_mu)))
ATE_adjusted_hba1c.test.without.cvd <- calc_ATE(data = hba1c.test.without.cvd,
validation_type = "Adjust", variable = "posthba1cfinal",
quantile_var = "hba1c_diff.q",
order = "largest", breakdown = unique(c(variables_tau, variables_mu)))
plot_ATE_psm_1_1_hba1c.test.without.cvd <- ATE_plot(ATE_psm_1_1_hba1c.test.without.cvd[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Cohort without CVD (n=", format(sum(ATE_psm_1_1_hba1c.test.without.cvd[["effects"]]$n_drug1)*2,big.mark=",",scientific=FALSE), ")"),
subtitle = "Propensity score matching"
)
plot_ATE_psm_1_1_adjusted_hba1c.test.without.cvd <- ATE_plot(ATE_psm_1_1_adjusted_hba1c.test.without.cvd[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Cohort without CVD (n=", format(sum(ATE_psm_1_1_adjusted_hba1c.test.without.cvd[["effects"]]$n_drug1)*2,big.mark=",",scientific=FALSE), ")"),
subtitle = "Propensity score matching and estimate adjustment"
)
plot_ATE_adjusted_hba1c.test.without.cvd <- ATE_plot(ATE_adjusted_hba1c.test.without.cvd[["effects"]], "hba1c_diff.pred", "obs", "lci", "uci", -12, 12) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(
title = paste0("Cohort without CVD (n=", format(sum(ATE_adjusted_hba1c.test.without.cvd[["effects"]]$N),big.mark=",",scientific=FALSE), ")"),
subtitle = "Estimate adjustment"
)
plot_all <- (plot_ATE_psm_1_1_hba1c.test.with.cvd | plot_ATE_psm_1_1_hba1c.test.without.cvd) / (plot_ATE_psm_1_1_adjusted_hba1c.test.with.cvd | plot_ATE_psm_1_1_adjusted_hba1c.test.without.cvd) / (plot_ATE_adjusted_hba1c.test.with.cvd | plot_ATE_adjusted_hba1c.test.without.cvd) +
plot_annotation(tag_levels = list(c("A.1", "A.2", "B.1", "B.2", "C.1", "C.2")))
pdf(width = 10, height = 15, "Plots/11.13.cvd_no_cvd_validation.pdf")
plot_all
dev.off()