generated from opensafely/research-template
/
anaphylaxis_update.R
344 lines (238 loc) · 13.9 KB
/
anaphylaxis_update.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
logfilename <- "./logs/anaphylaxis_update.txt"
sink(logfilename, append = FALSE, split = FALSE)
# Clear workspace
rm(list = ls())
# Import dataset
dataset <- read.csv("./output/input_anaphylaxis_update.csv", header = TRUE)
dataset <- subset(dataset, sotrovimab_covid_therapeutics!=""|molnupiravir_covid_therapeutics!=""|paxlovid_covid_therapeutics!="")
library(lubridate)
date_vars <- c("sotrovimab_covid_therapeutics", "molnupiravir_covid_therapeutics", "paxlovid_covid_therapeutics",
"remdesivir_covid_therapeutics", "casirivimab_covid_therapeutics", "date_treated", "start_date",
"death_date", "dereg_date", "last_vaccination_date",
"death_with_anaphylaxis_date", "death_with_anaph_underly_date", "death_with_anaphylaxis_date2",
"death_with_anaph_underly_date2", "death_with_anaphylaxis_date3", "death_with_anaphylaxis_date_pre",
"death_with_anaph_underly_date_pre", "hospitalisation_anaph", "hosp_discharge_anaph",
"hospitalisation_anaph_underly", "hospitalisation_anaph2", "hospitalisation_anaph_underly2",
"hospitalisation_anaph3", "hospitalisation_anaph_pre", "hosp_anaph_underly_pre", "AE_anaph",
"AE_anaph2", "AE_anaph3", "AE_anaph4", "AE_anaph_pre", "AE_anaph2_pre", "GP_anaph", "GP_anaph2",
"GP_anaph_pre", "GP_anaph2_pre", "date_treated1", "sotrovimab_covid_therapeutics1",
"molnupiravir_covid_therapeutics1", "paxlovid_covid_therapeutics1",
"hosp_anaph_pre_1y",
"AE_anaph_pre_1y", "AE_anaph2_pre_1y", "GP_anaph_pre_1y", "hosp_anaph_pre_1m", "AE_anaph2_pre_1m", "GP_anaph_pre_1m")
for (var in date_vars) {
if (var %in% names(dataset)) {
dataset[[var]] <- as.Date(dataset[[var]], format = "%Y-%m-%d")
}
}
dataset <- subset(dataset, !is.na(date_treated)& start_date >= as.Date("2021-12-16") & start_date <= as.Date("2023-01-28"))
print("sotro")
dataset_sotro <- subset(dataset,!is.na(sotrovimab_covid_therapeutics))
print("Calculate day_hosp variable as the difference between hospitalisation_anaph and start_date")
dataset_sotro$day_hosp <- as.integer(dataset_sotro$hospitalisation_anaph - dataset_sotro$start_date)
print("Generate binary variable hosp_28d based on conditions")
dataset_sotro$hosp_28d <- as.integer(!is.na(dataset_sotro$hospitalisation_anaph) & dataset_sotro$day_hosp <= 28& dataset_sotro$day_hosp >=0)
print("Frequency table for hosp_28d variable")
table(dataset_sotro$hosp_28d)
print("Frequency table for AE_anaph variable when AE_28d is equal to 1")
table(dataset_sotro$hospitalisation_anaph[dataset_sotro$hosp_28d == 1])
print("Summarize hospitalisation_anaph_pre variable")
summary(dataset_sotro$hospitalisation_anaph_pre)
print("Summarize hosp_anaph_pre_1y variable")
summary(dataset_sotro$hosp_anaph_pre_1y)
table(dataset_sotro$registered_pre_4y)
table(dataset_sotro$registered_treated)
table(dataset_sotro$registered_treated, dataset_sotro$registered_pre_4y, useNA = "ifany")
table(dataset_sotro$hosp_anaph_pre_1y_n)
summary(dataset_sotro$hosp_anaph_pre_1m)
# Calculate day_AE variable as the difference between AE_anaph and start_date
dataset_sotro$day_AE2 <- as.integer(dataset_sotro$AE_anaph2 - dataset_sotro$start_date)
print("Summarize day_AE variable")
summary(dataset_sotro$day_AE2)
# Generate binary variable AE_28d based on conditions
dataset_sotro$AE_28d2 <- as.integer(!is.na(dataset_sotro$AE_anaph2) & dataset_sotro$day_AE2 <= 28& dataset_sotro$day_AE2 >=0)
print("Frequency table for AE_28d variable")
table(dataset_sotro$AE_28d2)
print("Frequency table for AE_anaph variable when AE_28d is equal to 1")
table(dataset_sotro$AE_anaph2[dataset_sotro$AE_28d2 == 1])
print("Summarize AE_anaph2_pre variable")
summary(dataset_sotro$AE_anaph2_pre)
print("Summarize AE_anaph_pre_1y variable")
summary(dataset_sotro$AE_anaph_pre_1y)
print("Summarize AE_anaph2_pre_1y variable")
summary(dataset_sotro$AE_anaph2_pre_1y)
table(dataset_sotro$AE_anaph2_pre_1y_n)
summary(dataset_sotro$AE_anaph2_pre_1m)
# Calculate day_GP variable as the difference between GP_anaph and start_date
dataset_sotro$day_GP <- as.integer(dataset_sotro$GP_anaph - dataset_sotro$start_date)
print("Summarize day_GP variable")
summary(dataset_sotro$day_GP)
# Generate binary variable GP_28d based on conditions
dataset_sotro$GP_28d <- as.integer(!is.na(dataset_sotro$GP_anaph) & dataset_sotro$day_GP <= 28& dataset_sotro$day_GP >=0)
print("Frequency table for GP_28d variable")
table(dataset_sotro$GP_28d)
print("Frequency table for GP_anaph variable when GP_28d is equal to 1")
table(dataset_sotro$GP_anaph[dataset_sotro$GP_28d == 1])
print("Summarize GP_anaph_pre variable")
summary(dataset_sotro$GP_anaph_pre)
print("Summarize GP_anaph_pre_1y variable")
summary(dataset_sotro$GP_anaph_pre_1y)
table(dataset_sotro$GP_anaph_pre_1y_n)
table(dataset_sotro$GP_anaph_pre_1y_episode)
summary(dataset_sotro$GP_anaph_pre_1m)
# Generate anaph_all variable based on conditions
dataset_sotro$anaph_all2 <- as.integer((dataset_sotro$hosp_28d + dataset_sotro$AE_28d2 + dataset_sotro$GP_28d) > 0)
print("Frequency table for anaph_all2 variable")
table(dataset_sotro$anaph_all2)
# Generate anaph_ever variable based on conditions
dataset_sotro$anaph_ever2 <- as.integer((!is.na(dataset_sotro$hospitalisation_anaph_pre) | !is.na(dataset_sotro$AE_anaph2_pre) | !is.na(dataset_sotro$GP_anaph_pre) ))
print("Frequency table for anaph_ever variable")
table(dataset_sotro$anaph_ever2)
# Generate anaph_pre_1y2 variable based on conditions
dataset_sotro$anaph_pre_1y2 <- as.integer((!is.na(dataset_sotro$hosp_anaph_pre_1y) | !is.na(dataset_sotro$AE_anaph2_pre_1y) | !is.na(dataset_sotro$GP_anaph_pre_1y)))
print("Frequency table for anaph_pre_1y2 variable")
table(dataset_sotro$anaph_pre_1y2)
# Generate anaph_pre_1m2 variable based on conditions
dataset_sotro$anaph_pre_1m2 <- as.integer((!is.na(dataset_sotro$hosp_anaph_pre_1m) | !is.na(dataset_sotro$AE_anaph2_pre_1m) | !is.na(dataset_sotro$GP_anaph_pre_1m)))
print("Frequency table for anaph_pre_1m2 variable")
table(dataset_sotro$anaph_pre_1m2)
print("pax")
dataset_pax <- subset(dataset,!is.na(paxlovid_covid_therapeutics))
print("Calculate day_hosp variable as the difference between hospitalisation_anaph and start_date")
dataset_pax$day_hosp <- as.integer(dataset_pax$hospitalisation_anaph - dataset_pax$start_date)
print("Generate binary variable hosp_28d based on conditions")
dataset_pax$hosp_28d <- as.integer(!is.na(dataset_pax$hospitalisation_anaph) & dataset_pax$day_hosp <= 28& dataset_pax$day_hosp >=0)
print("Frequency table for hosp_28d variable")
table(dataset_pax$hosp_28d)
print("Frequency table for AE_anaph variable when AE_28d is equal to 1")
table(dataset_pax$hospitalisation_anaph[dataset_pax$hosp_28d == 1])
print("Summarize hospitalisation_anaph_pre variable")
summary(dataset_pax$hospitalisation_anaph_pre)
print("Summarize hosp_anaph_pre_1y variable")
summary(dataset_pax$hosp_anaph_pre_1y)
table(dataset_pax$registered_pre_4y)
table(dataset_pax$registered_treated)
table(dataset_pax$registered_treated, dataset_pax$registered_pre_4y, useNA = "ifany")
table(dataset_pax$hosp_anaph_pre_1y_n)
summary(dataset_pax$hosp_anaph_pre_1m)
# Calculate day_AE variable as the difference between AE_anaph and start_date
dataset_pax$day_AE2 <- as.integer(dataset_pax$AE_anaph2 - dataset_pax$start_date)
print("Summarize day_AE variable")
summary(dataset_pax$day_AE2)
# Generate binary variable AE_28d based on conditions
dataset_pax$AE_28d2 <- as.integer(!is.na(dataset_pax$AE_anaph2) & dataset_pax$day_AE2 <= 28& dataset_pax$day_AE2 >=0)
print("Frequency table for AE_28d variable")
table(dataset_pax$AE_28d2)
print("Frequency table for AE_anaph variable when AE_28d is equal to 1")
table(dataset_pax$AE_anaph2[dataset_pax$AE_28d2 == 1])
print("Summarize AE_anaph2_pre variable")
summary(dataset_pax$AE_anaph2_pre)
print("Summarize AE_anaph_pre_1y variable")
summary(dataset_pax$AE_anaph_pre_1y)
print("Summarize AE_anaph2_pre_1y variable")
summary(dataset_pax$AE_anaph2_pre_1y)
table(dataset_pax$AE_anaph2_pre_1y_n)
summary(dataset_pax$AE_anaph2_pre_1m)
# Calculate day_GP variable as the difference between GP_anaph and start_date
dataset_pax$day_GP <- as.integer(dataset_pax$GP_anaph - dataset_pax$start_date)
print("Summarize day_GP variable")
summary(dataset_pax$day_GP)
# Generate binary variable GP_28d based on conditions
dataset_pax$GP_28d <- as.integer(!is.na(dataset_pax$GP_anaph) & dataset_pax$day_GP <= 28& dataset_pax$day_GP >=0)
print("Frequency table for GP_28d variable")
table(dataset_pax$GP_28d)
print("Frequency table for GP_anaph variable when GP_28d is equal to 1")
table(dataset_pax$GP_anaph[dataset_pax$GP_28d == 1])
print("Summarize GP_anaph_pre variable")
summary(dataset_pax$GP_anaph_pre)
print("Summarize GP_anaph_pre_1y variable")
summary(dataset_pax$GP_anaph_pre_1y)
table(dataset_pax$GP_anaph_pre_1y_n)
table(dataset_pax$GP_anaph_pre_1y_episode)
summary(dataset_pax$GP_anaph_pre_1m)
# Generate anaph_all variable based on conditions
dataset_pax$anaph_all2 <- as.integer((dataset_pax$hosp_28d + dataset_pax$AE_28d2 + dataset_pax$GP_28d) > 0)
print("Frequency table for anaph_all2 variable")
table(dataset_pax$anaph_all2)
# Generate anaph_ever variable based on conditions
dataset_pax$anaph_ever2 <- as.integer((!is.na(dataset_pax$hospitalisation_anaph_pre) | !is.na(dataset_pax$AE_anaph2_pre) | !is.na(dataset_pax$GP_anaph_pre) ))
print("Frequency table for anaph_ever variable")
table(dataset_pax$anaph_ever2)
# Generate anaph_pre_1y2 variable based on conditions
dataset_pax$anaph_pre_1y2 <- as.integer((!is.na(dataset_pax$hosp_anaph_pre_1y) | !is.na(dataset_pax$AE_anaph2_pre_1y) | !is.na(dataset_pax$GP_anaph_pre_1y)))
print("Frequency table for anaph_pre_1y2 variable")
table(dataset_pax$anaph_pre_1y2)
# Generate anaph_pre_1m2 variable based on conditions
dataset_pax$anaph_pre_1m2 <- as.integer((!is.na(dataset_pax$hosp_anaph_pre_1m) | !is.na(dataset_pax$AE_anaph2_pre_1m) | !is.na(dataset_pax$GP_anaph_pre_1m)))
print("Frequency table for anaph_pre_1m2 variable")
table(dataset_pax$anaph_pre_1m2)
print("mol")
dataset_mol <- subset(dataset,!is.na(molnupiravir_covid_therapeutics))
print("Calculate day_hosp variable as the difference between hospitalisation_anaph and start_date")
dataset_mol$day_hosp <- as.integer(dataset_mol$hospitalisation_anaph - dataset_mol$start_date)
print("Generate binary variable hosp_28d based on conditions")
dataset_mol$hosp_28d <- as.integer(!is.na(dataset_mol$hospitalisation_anaph) & dataset_mol$day_hosp <= 28& dataset_mol$day_hosp >=0)
print("Frequency table for hosp_28d variable")
table(dataset_mol$hosp_28d)
print("Frequency table for AE_anaph variable when AE_28d is equal to 1")
table(dataset_mol$hospitalisation_anaph[dataset_mol$hosp_28d == 1])
print("Summarize hospitalisation_anaph_pre variable")
summary(dataset_mol$hospitalisation_anaph_pre)
print("Summarize hosp_anaph_pre_1y variable")
summary(dataset_mol$hosp_anaph_pre_1y)
table(dataset_mol$registered_pre_4y)
table(dataset_mol$registered_treated)
table(dataset_mol$registered_treated, dataset_mol$registered_pre_4y, useNA = "ifany")
table(dataset_mol$hosp_anaph_pre_1y_n)
summary(dataset_mol$hosp_anaph_pre_1m)
# Calculate day_AE variable as the difference between AE_anaph and start_date
dataset_mol$day_AE2 <- as.integer(dataset_mol$AE_anaph2 - dataset_mol$start_date)
print("Summarize day_AE variable")
summary(dataset_mol$day_AE2)
# Generate binary variable AE_28d based on conditions
dataset_mol$AE_28d2 <- as.integer(!is.na(dataset_mol$AE_anaph2) & dataset_mol$day_AE2 <= 28& dataset_mol$day_AE2 >=0)
print("Frequency table for AE_28d variable")
table(dataset_mol$AE_28d2)
print("Frequency table for AE_anaph variable when AE_28d is equal to 1")
table(dataset_mol$AE_anaph2[dataset_mol$AE_28d2 == 1])
print("Summarize AE_anaph2_pre variable")
summary(dataset_mol$AE_anaph2_pre)
print("Summarize AE_anaph_pre_1y variable")
summary(dataset_mol$AE_anaph_pre_1y)
print("Summarize AE_anaph2_pre_1y variable")
summary(dataset_mol$AE_anaph2_pre_1y)
table(dataset_mol$AE_anaph2_pre_1y_n)
summary(dataset_mol$AE_anaph2_pre_1m)
# Calculate day_GP variable as the difference between GP_anaph and start_date
dataset_mol$day_GP <- as.integer(dataset_mol$GP_anaph - dataset_mol$start_date)
print("Summarize day_GP variable")
summary(dataset_mol$day_GP)
# Generate binary variable GP_28d based on conditions
dataset_mol$GP_28d <- as.integer(!is.na(dataset_mol$GP_anaph) & dataset_mol$day_GP <= 28& dataset_mol$day_GP >=0)
print("Frequency table for GP_28d variable")
table(dataset_mol$GP_28d)
print("Frequency table for GP_anaph variable when GP_28d is equal to 1")
table(dataset_mol$GP_anaph[dataset_mol$GP_28d == 1])
print("Summarize GP_anaph_pre variable")
summary(dataset_mol$GP_anaph_pre)
print("Summarize GP_anaph_pre_1y variable")
summary(dataset_mol$GP_anaph_pre_1y)
table(dataset_mol$GP_anaph_pre_1y_n)
table(dataset_mol$GP_anaph_pre_1y_episode)
summary(dataset_mol$GP_anaph_pre_1m)
# Generate anaph_all variable based on conditions
dataset_mol$anaph_all2 <- as.integer((dataset_mol$hosp_28d + dataset_mol$AE_28d2 + dataset_mol$GP_28d) > 0)
print("Frequency table for anaph_all2 variable")
table(dataset_mol$anaph_all2)
# Generate anaph_ever variable based on conditions
dataset_mol$anaph_ever2 <- as.integer((!is.na(dataset_mol$hospitalisation_anaph_pre) | !is.na(dataset_mol$AE_anaph2_pre) | !is.na(dataset_mol$GP_anaph_pre) ))
print("Frequency table for anaph_ever variable")
table(dataset_mol$anaph_ever2)
# Generate anaph_pre_1y2 variable based on conditions
dataset_mol$anaph_pre_1y2 <- as.integer((!is.na(dataset_mol$hosp_anaph_pre_1y) | !is.na(dataset_mol$AE_anaph2_pre_1y) | !is.na(dataset_mol$GP_anaph_pre_1y)))
print("Frequency table for anaph_pre_1y2 variable")
table(dataset_mol$anaph_pre_1y2)
# Generate anaph_pre_1m2 variable based on conditions
dataset_mol$anaph_pre_1m2 <- as.integer((!is.na(dataset_mol$hosp_anaph_pre_1m) | !is.na(dataset_mol$AE_anaph2_pre_1m) | !is.na(dataset_mol$GP_anaph_pre_1m)))
print("Frequency table for anaph_pre_1m2 variable")
table(dataset_mol$anaph_pre_1m2)
sink()