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
/
07.slade_aurum_differential_response_effects.R
293 lines (254 loc) · 10 KB
/
07.slade_aurum_differential_response_effects.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
####################
## Description:
## - In this file we calculate the treatment effect / response for
## the average patient for a range of values at each covariate.
####################
## Load libraries
library(tidyverse)
## 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(paste0(output_path, "/differential_response"))
## 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")
# variables chosen
variables_mu <- readRDS(paste0(output_path, "/response_model_bcf/variables_mu.rds"))
variables_tau <- readRDS(paste0(output_path, "/response_model_bcf/variables_tau.rds"))
# treatment effects
patient_effects <- readRDS(paste0(output_path, "/response_model_bcf/patient_effects.rds"))
# Full cohort for average values
hba1c.train <- set_up_data_sglt2_glp1(dataset.type="hba1c.train") %>%
left_join(patient_effects, by = c("patid", "pated"))
levels(hba1c.train$sex) <- c("Females", "Males")
levels(hba1c.train$ncurrtx) <- c("0", "1", "2", "3", "4+")
#:------------------------------------------------------------------------
# Stratify predicted treatment effects by variables
# sex
plot_sex_strata <- hba1c.train %>%
select(sex, effects) %>%
ggplot(aes(x = sex, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
ylim(-10, 10) +
ggtitle("Sex") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5))
# number of other current drugs
plot_ncurrtx_strata <- hba1c.train %>%
select(ncurrtx, effects, sex) %>%
ggplot(aes(x = ncurrtx, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("Number of other current\nglucose-lowering drugs") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# Peripheral arterial disease
plot_prepad_strata <- hba1c.train %>%
select(prepad, effects, sex) %>%
ggplot(aes(x = prepad, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("Peripheral arterial disease") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# Ischaemic heart disease
plot_preihd_strata <- hba1c.train %>%
select(preihd, effects, sex) %>%
ggplot(aes(x = preihd, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("Ischaemic heart disease") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# Neuropathy
plot_preneuropathy_strata <- hba1c.train %>%
select(preneuropathy, effects, sex) %>%
ggplot(aes(x = preneuropathy, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("Neuropathy") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# Retinopathy
plot_preretinopathy_strata <- hba1c.train %>%
select(preretinopathy, effects, sex) %>%
ggplot(aes(x = preretinopathy, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("Retinopathy") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# Heart Failure
plot_preheartfailure_strata <- hba1c.train %>%
select(preheartfailure, effects, sex) %>%
ggplot(aes(x = preheartfailure, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("Heart failure") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# HbA1c at baseline
breaks_hba1c <- quantile(hba1c.train$prehba1c, probs = seq(0.2, 0.9, 0.2), na.rm = TRUE)
plot_prehba1c_strata <- group_values(data = hba1c.train,
variable = "prehba1c",
breaks = breaks_hba1c) %>%
select(intervals, effects, sex, prehba1c) %>%
drop_na() %>%
group_by(intervals) %>%
mutate(intervals_labels = round(mean(prehba1c, na.rm = TRUE)),
intervals_labels = factor(intervals_labels)) %>%
ungroup() %>%
ggplot(aes(x = intervals_labels, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("HbA1c") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# eGFR at baseline
breaks_egfr <- quantile(hba1c.train$preegfr, probs = seq(0.2, 0.9, 0.2), na.rm = TRUE)
plot_preegfr_strata <- group_values(data = hba1c.train,
variable = "preegfr",
breaks = breaks_egfr) %>%
select(intervals, effects, sex, preegfr) %>%
drop_na() %>%
group_by(intervals) %>%
mutate(intervals_labels = round(mean(preegfr, na.rm = TRUE)),
intervals_labels = factor(intervals_labels)) %>%
ungroup() %>%
ggplot(aes(x = intervals_labels, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("eGFR") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# Age at baseline
breaks_agetx <- quantile(hba1c.train$agetx, probs = seq(0.2, 0.9, 0.2), na.rm = TRUE)
plot_agetx_strata <- group_values(data = hba1c.train,
variable = "agetx",
breaks = breaks_agetx) %>%
select(intervals, effects, sex, agetx) %>%
drop_na() %>%
group_by(intervals) %>%
mutate(intervals_labels = round(mean(agetx, na.rm = TRUE)),
intervals_labels = factor(intervals_labels)) %>%
ungroup() %>%
ggplot(aes(x = intervals_labels, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("Current age") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# BMI at baseline
breaks_prebmi <- quantile(hba1c.train$prebmi, probs = seq(0.2, 0.9, 0.2), na.rm = TRUE)
plot_prebmi_strata <- group_values(data = hba1c.train,
variable = "prebmi",
breaks = breaks_prebmi) %>%
select(intervals, effects, sex, prebmi) %>%
drop_na() %>%
group_by(intervals) %>%
mutate(intervals_labels = round(mean(prebmi, na.rm = TRUE)),
intervals_labels = factor(intervals_labels)) %>%
ungroup() %>%
ggplot(aes(x = intervals_labels, y = effects)) +
geom_hline(aes(yintercept = 0), colour = "red") +
geom_boxplot(outlier.shape = NA) +
facet_wrap(~sex) +
ylim(-10, 10) +
ggtitle("BMI") +
ylab("Predicted treatment effects (mmol/mol)") +
theme_bw() +
theme(legend.position = "bottom",
axis.title = element_blank(),
plot.title = element_text(hjust = 0.5),
strip.background = element_rect(fill="white"))
# Combine all
plot_strata <- patchwork::wrap_plots(
list(
plot_ncurrtx_strata,
plot_sex_strata,
plot_preegfr_strata,
plot_agetx_strata,
plot_prebmi_strata +
theme(axis.title.y = element_text(size = 11)),
plot_prehba1c_strata,
plot_preretinopathy_strata,
plot_prepad_strata,
plot_preneuropathy_strata,
plot_preihd_strata,
plot_preheartfailure_strata
)) +
patchwork::plot_annotation(
title = "Boxplot of treatment effects for covariate strata"
)
# PDF containing the plot
pdf(width = 16, height = 10, "Plots/11.07.diff_treat_effect.pdf")
plot_strata
dev.off()