-
Notifications
You must be signed in to change notification settings - Fork 0
/
patient_data.qmd
312 lines (236 loc) · 7.55 KB
/
patient_data.qmd
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
---
title: "GECKO data dashboard"
format:
html:
embed-resources: true
theme: cerulean
editor: source
execute:
echo: false
warning: false
editor_options:
chunk_output_type: console
callout-appearance: simple
---
```{r}
library(tidyverse)
library(scales)
library(bslib)
library(bsicons)
library(shiny)
library(consort)
# GECKO green is #74a73e
source("patient_data_pull.R")
#save(patient_data_orig, file = "patient_data_orig.rda")
#load("patient_data_orig.rda")
source("registrations_pull.R")
#save(registrations_orig, file = "registrations_data_orig.rda")
#patient_data_orig$period %>% unique() %>% factor() %>% levels()
n_records = nrow(patient_data_orig)
# patient_data_orig %>%
# count(internal_check)
patient_data = patient_data_orig %>%
# REDCap sends the data fields including sub-var names in {}, removing here:
mutate(op_performed = str_extract(op_performed, "^.*(?=(\\{))")) %>%
mutate(period = fct_explicit_na(period, "Missing")) %>%
mutate(wb = fct_relevel(wb, "High income", "Upper middle income", "Lower middle income"))
# patient_data %>%
# count(inclusion_exclusion, internal_check)
patient_data_cleaned = patient_data %>%
filter(internal_check == "Pass - included in analysis")
patient_data = patient_data %>%
mutate(inclusion_exclusion = na_if(inclusion_exclusion, "Include - this is a valid record for a patient who fulfils inclusion criteria")) %>%
mutate(internal_check = na_if(internal_check, "Pass - included in analysis"))
# patient_data %>%
# count(inclusion_exclusion, internal_check)
n_records_cleaned = nrow(patient_data_cleaned)
registrations = registrations_orig
source("world_map.R")
```
```{r}
# Functions
theme_set(theme_classic())
theme_update(axis.text = element_text(size = 16, colour = "black"),
axis.title = element_text(size = 16, colour = "black"),
plot.title = element_text(size = 20, colour = "black"),
strip.text = element_text(size = 16, colour = "black"))
barplot_count = function(df, var, title = NA, high_n = 50, infreq = TRUE){
if (infreq){
df = df %>%
mutate(plotvar = fct_infreq({{var}}))
} else{
df = df %>%
mutate(plotvar = {{var}})
}
df %>%
drop_na({{var}}) %>%
ggplot(aes(y = fct_rev(plotvar) %>% fct_relevel("Missing"))) +
geom_bar(colour = "#2166ac", fill = "#d1e5f0") +
geom_text(stat='count', aes(label=comma(after_stat(count)),
hjust = if_else(after_stat(count) > high_n, 1, 0)),
size = 10,
label.padding=unit(0.3, "lines")) +
scale_y_discrete(labels = label_wrap(15)) +
scale_x_continuous(expand = expansion(mult = c(0, 0), add = c(0, 0))) +
ggtitle(str_wrap(title, 30)) +
ylab("") +
xlab("Number of patients")
}
histogram = function(df, var, title = NA, xlab = NA, ylab = NA){
df %>%
ggplot(aes({{var}})) +
geom_histogram(binwidth = 10) +
ggtitle(str_wrap(title, 30)) +
xlab(xlab) +
ylab(ylab) +
scale_x_continuous(expand = expansion(mult = c(0, 0), add = c(0, 0))) +
scale_y_continuous(expand = expansion(mult = c(0, 0.1), add = c(0, 0)))
}
```
::: {layout-ncol="1"}
Records that pass internal quality check:
```{r}
bslib::value_box(
title = "GECKO patient data:",
value = paste(prettyNum(n_records_cleaned, big.mark = ","), "records from"),
showcase = bs_icon("clipboard2-pulse-fill"),
h3(paste(n_distinct(patient_data_cleaned$redcap_data_access_group) %>%
prettyNum(big.mark = ","), "hospitals in")),
h3(paste(n_distinct(patient_data_cleaned$country), "countries")),
br(),
p("Updated:"),
p(format(Sys.time(), "%d-%b %Y")),
theme_color = "success"
)
```
```{r}
#| include: false
consort_plot(patient_data,
order = list(record_id = "Records started on REDCap",
inclusion_exclusion = "Excluded with reasons:",
record_id = "Records considered",
internal_check = "Internal DQ check",
#record_id = "Included in analysis",
wb = "Included in analysis",
record_id = " "),
side_box = c("inclusion_exclusion", "internal_check"),
allocation = "wb",
cex = 0.8,
text_width = 30)
```
Records started on REDCap:
```{r}
bslib::value_box(
title = "GECKO patient data:",
value = paste(prettyNum(n_records, big.mark = ","), "records from"),
showcase = bs_icon("clipboard2-pulse-fill"),
h3(paste(n_distinct(patient_data$redcap_data_access_group) %>%
prettyNum(big.mark = ","), "hospitals in")),
h3(paste(n_distinct(patient_data$country), "countries")),
br(),
p("Updated:"),
p(format(Sys.time(), "%d-%b %Y")),
theme_color = "success"
)
```
```{r}
bslib::value_box(
title = "GECKO registrations:",
value = paste(nrow(registrations)%>%
prettyNum(big.mark = ","), "hospitals from"),
showcase = bs_icon("clipboard2-pulse-fill"),
h3(paste(n_distinct(registrations$country), "countries")),
br(),
p("Updated:"),
p(format(Sys.time(), "%d-%b %Y")),
theme_color = "warning"
)
```
```{r}
map_patients
```
```{r}
map_registrations
```
:::
::: {layout-ncol="2"}
::: {.callout-tip icon=false collapse=true}
# Patient numbers Top 10
```{r}
patient_data %>%
count(country, sort = TRUE, name = "n_patients") %>%
slice(1:10) %>%
knitr::kable()
```
## NIHR Global Surgery Unit hub countries
```{r}
hub_countries = c("Mexico", "Nigeria", "India", "Ghana", "Rwanda", "Benin", "South Africa")
patient_data %>%
filter(country %in% hub_countries) %>%
mutate(country = fct_expand(country, hub_countries)) %>%
count(country, sort = TRUE, name = "n_patients", .drop = FALSE) %>%
knitr::kable()
```
:::
::: {.callout-warning icon=false collapse=true}
# Registrations Top 10
```{r}
patient_data %>%
count(redcap_data_access_group, sort = TRUE, name = "n_patients") %>%
slice(1:10) %>%
knitr::kable()
```
#### Registrations NIHR Global Surgery Unit hub countries
```{r}
hub_countries = c("Mexico", "Nigeria", "India", "Ghana", "Rwanda", "Benin", "South Africa")
registrations %>%
filter(country %in% hub_countries) %>%
mutate(country = fct_expand(country, hub_countries)) %>%
count(country, sort = TRUE, name = "n_hospitals", .drop = FALSE) %>%
knitr::kable()
```
:::
:::
# Operative approach - Minimally invasive surgery (MIS) vs Open
::: panel-tabset
## Map
```{r}
map_op_approach
```
## Plot
Interactive dataset explorer: https://argoshare.is.ed.ac.uk/gecko_shinyviz/
```{r, fig.width = 12, fig.height = 12}
barplot_count(patient_data_cleaned, op_approach,
"Operative approach by World Bank income group",
high_n = 1500) +
scale_x_continuous(expand = expansion(mult = c(0, 0.01), add = c(0, 0)), labels = scales::label_comma()) +
facet_wrap(~wb, ncol = 1)
```
## Table
```{r}
op_approach %>%
gt::gt() %>%
gt::opt_interactive(use_search = TRUE,
use_pagination = FALSE)
```
## Histogram
```{r}
op_approach %>%
ggplot(aes(prop_laprob)) +
geom_histogram() +
xlab("Proportion of Lap/Rob/Conv") +
ylab("n countries")
```
:::
::: {layout-ncol="2"}
```{r, fig.height=10}
barplot_count(patient_data_cleaned, period, "Data collection period", high_n = 2000, infreq = FALSE)
```
```{r}
barplot_count(patient_data_cleaned, wb, "World bank income group", high_n = 2000, infreq = FALSE)
```
```{r}
barplot_count(patient_data_cleaned, op_performed, "Operation performed", high_n = 4000) +
scale_x_continuous(expand = expansion(mult = c(0, 0.01), add = c(0, 0)))
```
:::