/
usability_limits.Rmd
302 lines (239 loc) · 11.6 KB
/
usability_limits.Rmd
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
---
title: "Address Usability Limits of Bootstrap Method"
output:
html_document:
toc: true
toc_depth: 3
toc_float: true
number_sections: true
code_folding: show
collapse: false
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, cache = TRUE)
```
# Load
```{r}
suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(knitr))
suppressPackageStartupMessages(library(furrr))
suppressPackageStartupMessages(library(future))
suppressPackageStartupMessages(library(simaerep))
```
# Introduction
As we already mentioned in the [introduction](file:///git_repos/simaerep/docs/articles/intro.html#disadvantages-over-classic-statistical-tests) bootstrap resampling comes at a price. We need a good proportion of sites that are compliant and are not under-reporting AEs. Otherwise the patient pool we draw from will be tainted. Also, in general for count data, negative deviations from overall small integer values (3 or less) are hard to detect. Here we will assess the usability limits of the bootstrap resampling method by applying it to different simulated scenarios.
# Parameter Grid
We start by defining a parameter grid.
**Fixed Parameters:**
- n_pat: 1000
- n_sites: 100
- max_visit_mean: 20
- max_visit_sd: 4
**Variable Parameters:**
- ae_visit: 0.05 - 2
- frac_sites_wit_ur: 0.05 - 0.75
- ur_rate: 0.05 - 1
```{r}
set.seed(1)
df_grid <- tibble( ae_per_visit_mean = seq(0.05, 2, length.out = 10)) %>%
mutate(frac_site_with_ur = list(seq(0.05, 0.75, length.out = 10))) %>%
unnest(frac_site_with_ur) %>%
mutate(ur_rate = list(seq(0.05, 1, length.out = 10)) ) %>%
unnest(ur_rate)
df_grid
```
# Apply
We use the [`furrr`](https://github.com/DavisVaughan/furrr) and the [`future`](https://github.com/HenrikBengtsson/future) package for multiprocessing. We proceed in applying all functions we already [introduced](https://openpharma.github.io/simaerep/articles/intro.html).
```{r}
suppressWarnings(future::plan(multiprocess))
```
## Simulate Test Data
We iteratively apply [sim_test_data_study()](https://openpharma.github.io/simaerep/reference/sim_test_data_study.html) on the different parameter combination of the grid
```{r}
df_grid <- df_grid %>%
mutate(
df_visit = furrr::future_pmap(
list(am = ae_per_visit_mean,
fr = frac_site_with_ur,
ur = ur_rate),
function(am, fr, ur) sim_test_data_study(n_pat = 1000,
n_sites = 100,
max_visit_mean = 20,
max_visit_sd = 4,
ae_per_visit_mean = am,
frac_site_with_ur = fr,
ur_rate = ur),
.progress = FALSE,
.options = furrr_options(seed = TRUE)
)
)
df_grid
```
## Aggregate Test Data
We apply [site_aggr()](https://openpharma.github.io/simaerep/reference/site_aggr.html) on the different simulated data sets.
```{r}
df_grid <- df_grid %>%
mutate(
df_visit = map2(df_visit, row_number(),
function(x,y) mutate(x, study_id = paste("S", y))),
df_site = furrr::future_map(df_visit,
site_aggr,
.progress = FALSE,
.options = furrr_options(seed = TRUE)
)
)
df_grid
```
## Simulate Sites
We apply [sim_sites()](https://openpharma.github.io/simaerep/reference/sim_sites.html) to to calculate the AE under-reporting probability.
```{r}
df_grid <- df_grid %>%
mutate( df_sim_sites = furrr::future_map2(df_site, df_visit,
sim_sites,
r = 1000,
poisson_test = TRUE,
prob_lower = TRUE,
.progress = FALSE,
.options = furrr_options(seed = TRUE)
)
)
df_grid
```
## Evaluate Sites
We apply [eval_sites()](https://openpharma.github.io/simaerep/reference/eval_sites.html) to balance the bootstrapped probabilities by the expected number of false positives.
```{r}
df_grid <- df_grid %>%
mutate( df_eval = furrr::future_map(df_sim_sites,
eval_sites,
.progress = FALSE,
.options = furrr_options(seed = TRUE)
)
)
df_grid
```
## Get Metrics
Apart from calculating true and false positives rate for the final under-reporting probability we also calculate the same metrics for a couple of benchmark probabilities.
- p-values returned from `poisson.test()`
- and the probabilities and p-values before adjusting for the expected false positives
In all cases we use a 95% probability threshold.
```{r}
get_metrics <- function(df_visit, df_eval, method) {
if (method == "ptest") {
prob_ur_adj = "pval_prob_ur"
prob_ur_unadj = "pval"
} else {
prob_ur_adj = "prob_low_prob_ur"
prob_ur_unadj = "prob_low"
}
df_ur <- df_visit %>%
select(site_number, is_ur) %>%
distinct()
df_metric_prep <- df_eval %>%
left_join(df_ur, "site_number") %>%
rename( prob_ur_adj = !! as.name(prob_ur_adj),
prob_ur_unadj = !! as.name(prob_ur_unadj) )
df_metric_adjusted <- df_metric_prep %>%
select(study_id, site_number, is_ur, prob_ur_adj) %>%
mutate( tp = ifelse(is_ur & prob_ur_adj >= 0.95, 1, 0),
fn = ifelse(is_ur & prob_ur_adj < 0.95, 1, 0),
tn = ifelse((! is_ur) & prob_ur_adj < 0.95, 1, 0),
fp = ifelse((! is_ur) & prob_ur_adj >= 0.95, 1, 0),
p = ifelse(prob_ur_adj >= 0.95, 1, 0),
n = ifelse(prob_ur_adj < 0.95, 1, 0),
P = ifelse(is_ur, 1, 0),
N = ifelse(! is_ur, 1, 0)
) %>%
group_by(study_id) %>%
select(-site_number, - is_ur, - prob_ur_adj) %>%
summarize_all(sum) %>%
mutate(prob_type = "adjusted")
df_metric_unadjusted <- df_metric_prep %>%
select(study_id, site_number, is_ur, prob_ur_unadj) %>%
mutate( tp = ifelse(is_ur & prob_ur_unadj <= 0.05, 1, 0),
fn = ifelse(is_ur & prob_ur_unadj > 0.05, 1, 0),
tn = ifelse((! is_ur) & prob_ur_unadj > 0.05, 1, 0),
fp = ifelse((! is_ur) & prob_ur_unadj <= 0.05, 1, 0),
p = ifelse(prob_ur_unadj <= 0.05, 1, 0),
n = ifelse(prob_ur_unadj > 0.05, 1, 0),
P = ifelse(is_ur, 1, 0),
N = ifelse(! is_ur, 1, 0)
) %>%
group_by(study_id) %>%
select(-site_number, - is_ur, - prob_ur_unadj) %>%
summarize_all(sum) %>%
mutate(prob_type = "unadjusted")
df_metric <- bind_rows(df_metric_adjusted, df_metric_unadjusted) %>%
mutate(method = method)
}
df_grid <- df_grid %>%
mutate(df_metric_pval = furrr::future_map2(df_visit, df_eval,
get_metrics,
method = "ptest"),
df_metric_prob_low = furrr::future_map2(df_visit, df_eval,
get_metrics,
method = "bootstrap"),
df_metric = map2(df_metric_pval, df_metric_prob_low, bind_rows)
)
df_grid
```
# Plot
```{r}
df_plot <- df_grid %>%
select(ae_per_visit_mean, frac_site_with_ur, ur_rate, df_metric) %>%
unnest(df_metric)
df_plot
```
# True positive rate - P - TP/P
When comparing bootstrap method against the poisson.test benchmark test, we find that they perform mostly similar from a 0.05 - 0.3 ratio of under-reporting sites. Its performance is still acceptable from a 0.3 - 0.5 ratio and then becomes pretty useless.
As expected detection of under-reporting sites is close too impossible when the ae/visit ratio is very low (0.05) with detection rates close to zero for all tested scenarios.
```{r fig.asp=1, fig.width=10}
p <- df_plot %>%
mutate( tp_P_ratio = tp/P) %>%
select(ae_per_visit_mean, frac_site_with_ur, ur_rate, tp_P_ratio, method, prob_type) %>%
mutate_if(is.numeric, round, 3) %>%
mutate(metric = case_when(method == "ptest" & prob_type == "unadjusted" ~ "ptest unadjusted",
method == "ptest" & prob_type == "adjusted" ~ "ptest adjusted",
method == "bootstrap" & prob_type == "unadjusted" ~ "bootstrap unadjusted",
method == "bootstrap" & prob_type == "adjusted" ~ "bootstrap adjusted"),
metric = fct_relevel(metric, c("ptest unadjusted", "ptest adjusted",
"bootstrap unadjusted", "bootstrap adjusted"))) %>%
ggplot(aes(ae_per_visit_mean, tp_P_ratio, color = metric)) +
geom_line(aes(linetype = prob_type), size = 0.5, alpha = 0.5) +
facet_grid( frac_site_with_ur ~ ur_rate) +
scale_color_manual(values = c("dodgerblue3", "skyblue1", "sienna4", "peru")) +
theme(panel.grid = element_blank(), legend.position = "bottom",
axis.text.x = element_text(angle = 90, vjust = 0.5)) +
labs(title = "AE Under Reporting Rate ~ Rate of AE Under-Reporting Sites",
y = "True positive rate - tp/P",
x = "AEs per Visit")
p
```
# False positive rate FP/N
We can show that adjusting the AE under-reporting probability for the expected number of false positives is quite effective.As the false positive rate is almost zero for all tested scenarios. However, this also comes at a cost lowering the true positive rate as well.
```{r fig.asp=1, fig.width=10}
p <- df_plot %>%
mutate( fpr = fp/N) %>%
select(ae_per_visit_mean, frac_site_with_ur, ur_rate, fpr, method, prob_type) %>%
mutate_if(is.numeric, round, 3) %>%
mutate(metric = case_when(method == "ptest" & prob_type == "unadjusted" ~ "ptest unadjusted",
method == "ptest" & prob_type == "adjusted" ~ "ptest adjusted",
method == "bootstrap" & prob_type == "unadjusted" ~ "bootstrap unadjusted",
method == "bootstrap" & prob_type == "adjusted" ~ "bootstrap adjusted"),
metric = fct_relevel(metric, c("ptest unadjusted", "ptest adjusted",
"bootstrap unadjusted", "bootstrap adjusted"))) %>%
ggplot(aes(ae_per_visit_mean, fpr, color = metric, linetype = prob_type)) +
geom_line(size = 0.5, alpha = 0.5) +
facet_grid( frac_site_with_ur ~ ur_rate) +
scale_color_manual(values = c("dodgerblue3", "skyblue1", "sienna4", "peru")) +
theme(panel.grid = element_blank(), legend.position = "bottom",
axis.text.x = element_text(angle = 90, vjust = 0.5)) +
labs(title = "AE Under Reporting Rate by Rate of AE Under-Reporting Sites",
y = "False positive rate - fp/N",
x = "AEs per Visit")
p
```
# Conclusion
As already outlined in the [introduction](https://openpharma.github.io/simaerep/articles/intro.html#advantage-over-classic-statistical-tests) the true AE generating process is unlikely to be a standard poisson process. Therefore using a non-parametric test remains our recommended option unless that there is a reason to believe that 50% or more of all sites are under-reporting AEs. We also show that it is important to adjust for the expected false positive rate when calculating the final probabilities.
In general we can say that we do not recommend any method for detecting AE under-reporting that involves comparing AE counts if the ae per visit rate is 0.05 or lower.