forked from kkmann/adoptr-validation-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04-scenario-IV.Rmd
489 lines (378 loc) · 13.5 KB
/
04-scenario-IV.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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# Scenario IV: smaller effect, point prior {#scenarioIV}
## Details
In this scenario, we return to point priors as investigated in
[Scenario I](#scenarioI).
The main goal is to validate `adoptr`'s sensitivity with regard to
the assumed effect size and the constraints on power and type one error rate.
Therefore, we still assume a two-armed trial with normally distributed outcomes.
The assumed effect size under the alternative is $\delta = 0.2$ in this setting.
Type one error rate is protected at $2.5\%$ and the power should be at least
$80\%$. We will vary these values in the variants [IV.2](#variantIV.2) and
[IV.3](#variantIV.3)
```{r}
# data distribution and hypotheses
datadist <- Normal(two_armed = TRUE)
H_0 <- PointMassPrior(.0, 1)
prior <- PointMassPrior(.2, 1)
# constraints
alpha <- 0.025
min_power <- 0.8
toer_cnstr <- Power(datadist, H_0) <= alpha
pow_cnstr <- Power(datadist, prior) >= min_power
```
## Variant IV-1: Minimizing Expected Sample Size under Point Prior {#variantIV_1}
### Objective
Expected sample size under the alternative point prior $\delta = 0.2$
is minimized.
```{r objective}
ess <- ExpectedSampleSize(datadist, prior)
```
### Constraints
No additional constraints are considered in this variant.
### Initial Design
For this example, the optimal one-stage, group-sequential, and generic
two-stage designs are computed.
The initial design that is used as starting value of optimization is defined
as a group-sequential design by the package `rpact` that fulfills
type one error rate and power constraints in the case of group-sequential and
two-stage design.
The initial one-stage design is chosen heuristically.
The order of integration is set to $5$.
```{r}
order <- 5L
tbl_designs <- tibble(
type = c("one-stage", "group-sequential", "two-stage"),
initial = list(
OneStageDesign(500, 2.0),
rpact_design(datadist, 0.2, 0.025, 0.8, TRUE, order),
TwoStageDesign(rpact_design(datadist, 0.2, 0.025, 0.8, TRUE, order))) )
```
### Optimization
```{r}
tbl_designs <- tbl_designs %>%
mutate(
optimal = purrr::map(initial, ~minimize(
ess,
subject_to(
toer_cnstr,
pow_cnstr
),
initial_design = .,
opts = opts)) )
```
### Test Cases
Firstly, it is checked whether the maximum number of iterations was
not exceeded in all three cases.
```{r}
tbl_designs %>%
transmute(
type,
iterations = purrr::map_int(tbl_designs$optimal,
~.$nloptr_return$iterations) ) %>%
{print(.); .} %>%
{testthat::expect_true(all(.$iterations < opts$maxeval))}
```
Now, the constraints on type one error rate and power are tested via simulation.
```{r}
tbl_designs %>%
transmute(
type,
toer = purrr::map(tbl_designs$optimal,
~sim_pr_reject(.[[1]], .0, datadist)$prob),
power = purrr::map(tbl_designs$optimal,
~sim_pr_reject(.[[1]], .2, datadist)$prob) ) %>%
unnest(., cols = c(toer, power)) %>%
{print(.); .} %>% {
testthat::expect_true(all(.$toer <= alpha * (1 + tol)))
testthat::expect_true(all(.$power >= min_power * (1 - tol))) }
```
Due to increasing degrees of freedom, the expected sample sizes under the
alternative should be ordered as 'one-stage > group-sequential > two-stage'.
They are evaluated by simulation as well as by `evaluate()`.
```{r}
tbl_designs %>%
mutate(
ess = map_dbl(optimal,
~evaluate(ess, .$design) ),
ess_sim = map_dbl(optimal,
~sim_n(.$design, .2, datadist)$n ) ) %>%
{print(.); .} %>% {
# sim/evaluate same under alternative?
testthat::expect_equal(.$ess, .$ess_sim,
tolerance = tol_n,
scale = 1)
# monotonicity with respect to degrees of freedom
testthat::expect_true(all(diff(.$ess) < 0)) }
```
Furthermore, the expected sample size under the alternative of the
optimal group-sequential design should be lower than for the
group-sequential design by `rpact` that is based on the inverse normal
combination test.
```{r}
tbl_designs %>%
filter(type == "group-sequential") %>%
{ expect_lte(
evaluate(ess, {.[["optimal"]][[1]]$design}),
evaluate(ess, {.[["initial"]][[1]]})
) }
```
Finally, the $n_2$ function of the optimal two-stage design is expected to be
monotonously decreasing:
```{r}
expect_true(
all(diff(
# get optimal two-stage design n2 pivots
tbl_designs %>% filter(type == "two-stage") %>%
{.[["optimal"]][[1]]$design@n2_pivots}
) < 0) )
```
## Variant IV-2: Increase Power {#variantIV_2}
### Objective
The objective remains expected sample size under the alternative $\delta = 0.2$.
### Constraints
The minimal required power is increased to $90\%$.
```{r}
min_power_2 <- 0.9
pow_cnstr_2 <- Power(datadist, prior) >= min_power_2
```
### Initial Design
For both flavours with two stages (group-sequential, generic two-stage)
the initial design is created by `rpact` to fulfill the error rate constraints.
```{r}
tbl_designs_9 <- tibble(
type = c("one-stage", "group-sequential", "two-stage"),
initial = list(
OneStageDesign(500, 2.0),
rpact_design(datadist, 0.2, 0.025, 0.9, TRUE, order),
TwoStageDesign(rpact_design(datadist, 0.2, 0.025, 0.9, TRUE, order))) )
```
### Optimization
```{r}
tbl_designs_9 <- tbl_designs_9 %>%
mutate(
optimal = purrr::map(initial, ~minimize(
ess,
subject_to(
toer_cnstr,
pow_cnstr_2
),
initial_design = .,
opts = opts)) )
```
### Test Cases
We start checking if the maximum number of iterations was not exceeded in all
three cases.
```{r}
tbl_designs_9 %>%
transmute(
type,
iterations = purrr::map_int(tbl_designs_9$optimal,
~.$nloptr_return$iterations) ) %>%
{print(.); .} %>%
{testthat::expect_true(all(.$iterations < opts$maxeval))}
```
The type one error rate and power constraints are evaluated by simulation.
```{r}
tbl_designs_9 %>%
transmute(
type,
toer = purrr::map(tbl_designs_9$optimal,
~sim_pr_reject(.[[1]], .0, datadist)$prob),
power = purrr::map(tbl_designs_9$optimal,
~sim_pr_reject(.[[1]], .2, datadist)$prob) ) %>%
unnest(., cols = c(toer, power)) %>%
{print(.); .} %>% {
testthat::expect_true(all(.$toer <= alpha * (1 + tol)))
testthat::expect_true(all(.$power >= min_power_2 * (1 - tol))) }
```
Due to increasing degrees of freedom, the expected sample sizes under the
alternative should be ordered as 'one-stage > group-sequential > two-stage'.
This is tested by simulation as well as by `evaluate()`.
```{r}
tbl_designs_9 %>%
mutate(
ess = map_dbl(optimal,
~evaluate(ess, .$design) ),
ess_sim = map_dbl(optimal,
~sim_n(.$design, .2, datadist)$n ) ) %>%
{print(.); .} %>% {
# sim/evaluate same under alternative?
testthat::expect_equal(.$ess, .$ess_sim,
tolerance = tol_n,
scale = 1)
# monotonicity with respect to degrees of freedom
testthat::expect_true(all(diff(.$ess) < 0))
testthat::expect_true(all(diff(.$ess_sim) < 0))}
```
Comparing with the inverse-normal based group-sequential design created
by `rpact`, the optimal group-sequential design should show
a lower expected sample size under the point alternative.
```{r}
tbl_designs_9 %>%
filter(type == "group-sequential") %>%
{ expect_lte(
evaluate(ess, {.[["optimal"]][[1]]$design}),
evaluate(ess, {.[["initial"]][[1]]})
) }
```
Since a point prior is regarded, the $n_2$ function of the optimal
two-stage design is expected to be monotonously decreasing:
```{r}
expect_true(
all(diff(
# get optimal two-stage design n2 pivots
tbl_designs_9 %>% filter(type == "two-stage") %>%
{.[["optimal"]][[1]]$design@n2_pivots}
) < 0) )
```
## Variant IV-3: Increase Type One Error rate {#variantIV_3}
### Objective
As in variants [IV.1](#variantIV_1) and [IV-2](#variantIV_2),
expected sample size under the point alternative is minimized.
### Constraints
While the power is still lower bounded by $90\%$ as in variant [II](#variantIV_2),
the maximal type one error rate is increased to $5\%$.
```{r}
alpha_2 <- .05
toer_cnstr_2 <- Power(datadist, H_0) <= alpha_2
```
### Initial Design
Again, a design computed by means of the package `rpact` to fulfill
the updated error rate constraints is applied as initial design for the
optimal group-sequential and generic two-stage designs.
```{r}
tbl_designs_5 <- tibble(
type = c("one-stage", "group-sequential", "two-stage"),
initial = list(
OneStageDesign(500, 2.0),
rpact_design(datadist, 0.2, 0.05, 0.9, TRUE, order),
TwoStageDesign(rpact_design(datadist, 0.2, 0.05, 0.9, TRUE, order))) )
```
### Optimization
```{r}
tbl_designs_5 <- tbl_designs_5 %>%
mutate(
optimal = purrr::map(initial, ~minimize(
ess,
subject_to(
toer_cnstr_2,
pow_cnstr_2
),
initial_design = .,
opts = opts)) )
```
### Test Cases
The convergence of the optimization algorithm is tested by checking if the
maximum number of iterations was not exceeded.
```{r}
tbl_designs_5 %>%
transmute(
type,
iterations = purrr::map_int(tbl_designs_5$optimal,
~.$nloptr_return$iterations) ) %>%
{print(.); .} %>%
{testthat::expect_true(all(.$iterations < opts$maxeval))}
```
By simulation, the constraints on the error rates (type one error and power)
are tested.
```{r}
tbl_designs_5 %>%
transmute(
type,
toer = purrr::map(tbl_designs_5$optimal,
~sim_pr_reject(.[[1]], .0, datadist)$prob),
power = purrr::map(tbl_designs_5$optimal,
~sim_pr_reject(.[[1]], .2, datadist)$prob) ) %>%
unnest(., cols = c(toer, power)) %>%
{print(.); .} %>% {
testthat::expect_true(all(.$toer <= alpha_2 * (1 + tol)))
testthat::expect_true(all(.$power >= min_power_2 * (1 - tol))) }
```
Due to increasing degrees of freedom, the expected sample sizes under the
alternative should be ordered as 'one-stage > group-sequential > two-stage'.
They are tested by simulation as well as by calling `evaluate()`.
```{r}
tbl_designs_5 %>%
mutate(
ess = map_dbl(optimal,
~evaluate(ess, .$design) ),
ess_sim = map_dbl(optimal,
~sim_n(.$design, .2, datadist)$n ) ) %>%
{print(.); .} %>% {
# sim/evaluate same under alternative?
testthat::expect_equal(.$ess, .$ess_sim,
tolerance = tol_n,
scale = 1)
# monotonicity with respect to degrees of freedom
testthat::expect_true(all(diff(.$ess) < 0)) }
```
The expected sample size under the alternative that was used as objective criterion
of the optimal group-sequential design should be lower than for the
group-sequential design by `rpact` that is based on the inverse normal
combination test.
```{r}
tbl_designs_5 %>%
filter(type == "group-sequential") %>%
{ expect_lte(
evaluate(ess, {.[["optimal"]][[1]]$design}),
evaluate(ess, {.[["initial"]][[1]]})
) }
```
Also in this variant, the $n_2$ function of the optimal two-stage design
is expected to be monotonously decreasing:
```{r}
expect_true(
all(diff(
# get optimal two-stage design n2 pivots
tbl_designs_5 %>% filter(type == "two-stage") %>%
{.[["optimal"]][[1]]$design@n2_pivots}
) < 0) )
```
## Plot Two-Stage Designs
The optimal two-stage designs stemming from the three different variants
are plotted together.
```{r, echo=FALSE}
x1 <- seq(-.5, 3, by = .01)
tibble(
constraints = c(
"TOER<=0.025, Power>=0.8",
"TOER<=0.025, Power>=0.9",
"TOER<=0.050, Power>=0.9" ),
design = list(
tbl_designs %>%
filter(type == "two-stage") %>%
pull(optimal) %>%
.[[1]] %>%
.$design,
tbl_designs_9 %>%
filter(type == "two-stage") %>%
pull(optimal) %>%
.[[1]] %>%
.$design,
tbl_designs_5 %>%
filter(type == "two-stage") %>%
pull(optimal) %>%
.[[1]] %>%
.$design ) ) %>%
group_by(constraints) %>%
do(
x1 = x1,
n = adoptr::n(.$design[[1]], x1),
c2 = c2(.$design[[1]], x1) ) %>%
unnest(., cols = c(x1, n, c2)) %>%
mutate(
section = ifelse(
is.finite(c2),
"continuation",
ifelse(c2 == -Inf, "efficacy", "futility") ) ) %>%
gather(variable, value, n, c2) %>%
ggplot(aes(x1, value, color = constraints)) +
geom_line(aes(group = interaction(section, constraints))) +
facet_wrap(~variable, scales = "free_y") +
labs(y = "", x = expression(x[1])) +
scale_color_discrete("") +
theme_bw() +
theme(
panel.grid = element_blank(),
legend.position = "bottom" )
```