-
Notifications
You must be signed in to change notification settings - Fork 9
/
Design-class.R
1203 lines (1097 loc) · 32.4 KB
/
Design-class.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
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#' @include Design-validity.R
#' @include Model-class.R
#' @include Rules-class.R
#' @include Data-class.R
#' @include helpers.R
#' @include CrmPackClass-class.R
NULL
# RuleDesign ----
## class ----
#' `RuleDesign`
#'
#' @description `r lifecycle::badge("stable")`
#'
#' [`RuleDesign`] is the class for rule-based designs. The difference between
#' this class and the [`Design`] class is that [`RuleDesign`] does not contain
#' `model`, `stopping` and `increments` slots.
#'
#' @slot nextBest (`NextBest`)\cr how to find the next best dose.
#' @slot cohort_size (`CohortSize`)\cr rules for the cohort sizes.
#' @slot data (`Data`)\cr specifies dose grid, any previous data, etc.
#' @slot startingDose (`number`)\cr the starting dose, it must lie on the dose
#' grid in `data`.
#'
#' @aliases RuleDesign
#' @export
#'
.RuleDesign <- setClass(
Class = "RuleDesign",
slots = c(
nextBest = "NextBest",
cohort_size = "CohortSize",
data = "Data",
startingDose = "numeric"
),
prototype = prototype(
nextBest = .NextBestThreePlusThree(),
cohort_size = CohortSizeConst(3),
data = Data(doseGrid = 1:3),
startingDose = 1
),
contains = "CrmPackClass",
validity = v_rule_design
)
## constructor ----
#' @rdname RuleDesign-class
#'
#' @param nextBest (`NextBest`)\cr see slot definition.
#' @param cohort_size (`CohortSize`)\cr see slot definition.
#' @param data (`Data`)\cr see slot definition.
#' @param startingDose (`number`)\cr see slot definition.
#'
#' @export
#' @example examples/Design-class-RuleDesign.R
#'
RuleDesign <- function(nextBest,
cohort_size,
data,
startingDose) {
new(
"RuleDesign",
nextBest = nextBest,
cohort_size = cohort_size,
data = data,
startingDose = as.numeric(startingDose)
)
}
#' @rdname RuleDesign-class
#' @note Typically, end users will not use the `.DefaultRuleDesign()` function.
#' @export
.DefaultRuleDesign <- function() {
RuleDesign(
nextBest = NextBestThreePlusThree(),
cohort_size = CohortSizeConst(size = 3L),
data = Data(doseGrid = c(5, 10, 15, 25, 35, 50, 80)),
startingDose = 5
)
}
## ThreePlusThreeDesign ----
#' @describeIn RuleDesign-class creates a new 3+3 design object from a dose grid.
#'
#' @param doseGrid (`numeric`)\cr the dose grid to be used (sorted).
#'
#' @export
#' @example examples/Design-class-ThreePlusThreeDesign.R
#'
ThreePlusThreeDesign <- function(doseGrid) {
empty_data <- Data(doseGrid = doseGrid)
# Using a constant cohort size of 3 we obtain exactly the 3+3 design.
RuleDesign(
nextBest = NextBestThreePlusThree(),
data = empty_data,
cohort_size = CohortSizeConst(size = 3L),
startingDose = doseGrid[1]
)
}
# Design ----
## class ----
#' `Design`
#'
#' @description `r lifecycle::badge("stable")`
#'
#' [`Design`] is the class for rule-based designs. The difference between
#' this class and its parent [`RuleDesign`] class is that [`Design`] class
#' contains additional `model`, `stopping` and `increments` slots.
#'
#' @slot model (`GeneralModel`)\cr the model to be used.
#' @slot stopping (`Stopping`)\cr stopping rule(s) for the trial.
#' @slot increments (`Increments`)\cr how to control increments between dose levels.
#' @slot pl_cohort_size (`CohortSize`)\cr rules for the cohort sizes for placebo,
#' if any planned (defaults to constant 0 placebo patients).
#'
#' @aliases Design
#' @export
#'
.Design <- setClass(
Class = "Design",
slots = c(
model = "GeneralModel",
stopping = "Stopping",
increments = "Increments",
pl_cohort_size = "CohortSize"
),
prototype = prototype(
model = .LogisticNormal(),
nextBest = .NextBestNCRM(),
stopping = .StoppingMinPatients(),
increments = .IncrementsRelative(),
pl_cohort_size = CohortSizeConst(0L)
),
contains = "RuleDesign"
)
## constructor ----
#' @rdname Design-class
#'
#' @param model (`GeneralModel`)\cr see slot definition.
#' @param stopping (`Stopping`)\cr see slot definition.
#' @param increments (`Increments`)\cr see slot definition.
#' @param pl_cohort_size (`CohortSize`)\cr see slot definition.
#' @inheritDotParams RuleDesign
#'
#' @export
#' @example examples/Design-class-Design.R
#'
#'
Design <- function(model,
stopping,
increments,
pl_cohort_size = CohortSizeConst(0L),
...) {
start <- RuleDesign(...)
new(
"Design",
start,
model = model,
stopping = stopping,
increments = increments,
pl_cohort_size = pl_cohort_size
)
}
## default constructor ----
#' @rdname Design-class
#' @note Typically, end users will not use the `.DefaultDesign()` function.
#' @export
.DefaultDesign <- function() {
my_size1 <- CohortSizeRange(
intervals = c(0, 30),
cohort_size = c(1, 3)
)
my_size2 <- CohortSizeDLT(
intervals = c(0, 1),
cohort_size = c(1, 3)
)
my_size <- maxSize(my_size1, my_size2)
my_stopping1 <- StoppingMinCohorts(nCohorts = 3)
my_stopping2 <- StoppingTargetProb(
target = c(0.2, 0.35),
prob = 0.5
)
my_stopping3 <- StoppingMinPatients(nPatients = 20)
my_stopping <- (my_stopping1 & my_stopping2) | my_stopping3
# Initialize the design.
design <- Design(
model = LogisticLogNormal(
mean = c(-0.85, 1),
cov = matrix(c(1, -0.5, -0.5, 1), nrow = 2),
ref_dose = 56
),
nextBest = NextBestNCRM(
target = c(0.2, 0.35),
overdose = c(0.35, 1),
max_overdose_prob = 0.25
),
stopping = my_stopping,
increments = IncrementsRelative(
intervals = c(0, 20),
increments = c(1, 0.33)
),
cohort_size = my_size,
data = Data(doseGrid = c(1, 3, 5, 10, 15, 20, 25, 40, 50, 80, 100)),
startingDose = 3
)
}
# DualDesign ----
## class ----
#' `DualDesign`
#'
#' @description `r lifecycle::badge("stable")`
#'
#' [`DualDesign`] is the class for the dual-endpoint CRM design. This class has
#' special requirements for the `model` and `data` slots in comparison to the
#' parent class [`Design`].
#'
#' @note the `nextBest` slot can be of any class, this allows for easy comparison
#' with recommendation methods that don't use the biomarker information.
#'
#' @slot model (`DualEndpoint`)\cr the model to be used.
#' @slot data (`DataDual`)\cr specifies dose grid, any previous data, etc.
#'
#' @aliases DualDesign
#' @export
#'
.DualDesign <- setClass(
Class = "DualDesign",
slots = c(
model = "DualEndpoint",
data = "DataDual"
),
prototype = prototype(
model = .DualEndpoint(),
nextBest = .NextBestDualEndpoint(),
data = DataDual(doseGrid = 1:2),
startingDose = 1
),
contains = "Design"
)
## constructor ----
#' @rdname DualDesign-class
#'
#' @param model (`DualEndpoint`)\cr see slot definition.
#' @param data (`DataDual`)\cr see slot definition.
#' @inheritDotParams Design
#'
#' @export
#' @example examples/Design-class-DualDesign.R
#'
DualDesign <- function(model,
data,
...) {
start <- Design(model = model, data = data, ...)
new(
"DualDesign",
start,
model = model,
data = data
)
}
## default constructor ----
#' @rdname DualDesign-class
#' @note Typically, end users will not use the `.DefaultDualDesign()` function.
#' @export
.DefaultDualDesign <- function() {
my_model <- DualEndpointRW(
mean = c(0, 1),
cov = matrix(c(1, 0, 0, 1), nrow = 2),
sigma2betaW = 0.01,
sigma2W = c(a = 0.1, b = 0.1),
rho = c(a = 1, b = 1),
rw1 = TRUE
)
# Choose the rule for selecting the next dose.
my_next_best <- NextBestDualEndpoint(
target = c(0.9, 1),
overdose = c(0.35, 1),
max_overdose_prob = 0.25
)
# Choose the rule for the cohort-size.
my_size1 <- CohortSizeRange(
intervals = c(0, 30),
cohort_size = c(1, 3)
)
my_size2 <- CohortSizeDLT(
intervals = c(0, 1),
cohort_size = c(1, 3)
)
my_size <- maxSize(my_size1, my_size2)
# Choose the rule for stopping.
my_stopping1 <- StoppingTargetBiomarker(
target = c(0.9, 1),
prob = 0.5
)
my_stopping <- my_stopping1 | StoppingMinPatients(40)
# Choose the rule for dose increments.
my_increments <- IncrementsRelative(
intervals = c(0, 20),
increments = c(1, 0.33)
)
# Initialize the design.
DualDesign(
model = my_model,
data = DataDual(doseGrid = c(1, 3, 5, 10, 15, 20, 25, 40, 50, 80, 100)),
nextBest = my_next_best,
stopping = my_stopping,
increments = my_increments,
cohort_size = my_size,
startingDose = 3
)
}
# TDsamplesDesign ----
## class ----
#' `TDsamplesDesign`
#'
#' @description `r lifecycle::badge("stable")`
#'
#' [`TDsamplesDesign`] is the class of design based only on DLT responses using
#' [`ModelTox`] class model (i.e. [`LogisticIndepBeta`]) as well as MCMC samples
#' obtained for this model.
#'
#' @slot model (`ModelTox`)\cr the pseudo DLT model to be used.
#' @slot stopping (`Stopping`)\cr stopping rule(s) for the trial.
#' @slot increments (`Increments`)\cr how to control increments between dose levels.
#' @slot pl_cohort_size (`CohortSize`)\cr rules for the cohort sizes for placebo,
#' if any planned (defaults to constant 0 placebo patients).
#'
#' @aliases TDsamplesDesign
#' @export
#'
.TDsamplesDesign <- setClass(
Class = "TDsamplesDesign",
slots = c(
model = "ModelTox",
stopping = "Stopping",
increments = "Increments",
pl_cohort_size = "CohortSize"
),
prototype = prototype(
model = .LogisticIndepBeta(),
nextBest = .NextBestTDsamples(),
stopping = .StoppingMinPatients(),
increments = .IncrementsRelative(),
pl_cohort_size = CohortSizeConst(0L)
),
contains = "RuleDesign"
)
## constructor ----
#' @rdname TDsamplesDesign-class
#'
#' @param model (`ModelTox`)\cr see slot definition.
#' @param stopping (`Stopping`)\cr see slot definition.
#' @param increments (`Increments`)\cr see slot definition.
#' @param pl_cohort_size (`CohortSize`)\cr see slot definition.
#' @inheritDotParams RuleDesign
#'
#' @export
#' @example examples/Design-class-TDsamplesDesign.R
#'
TDsamplesDesign <- function(model,
stopping,
increments,
pl_cohort_size = CohortSizeConst(0L),
...) {
start <- RuleDesign(...)
new(
"TDsamplesDesign",
start,
model = model,
stopping = stopping,
increments = increments,
pl_cohort_size = pl_cohort_size
)
}
## default constructor ----
#' @rdname TDsamplesDesign-class
#' @note Typically, end users will not use the `.DefaultTDsamplesDesign()` function.
#' @export
.DefaultTDsamplesDesign <- function() {
empty_data <- Data(doseGrid = seq(25, 300, 25))
my_model <- LogisticIndepBeta(
binDLE = c(1.05, 1.8),
DLEweights = c(3, 3),
DLEdose = c(25, 300),
data = empty_data
)
TDsamplesDesign(
model = my_model,
stopping = StoppingMinPatients(nPatients = 36),
increments = IncrementsRelative(
intervals = range(empty_data@doseGrid),
increments = c(2, 2)
),
nextBest = NextBestTDsamples(
prob_target_drt = 0.35,
prob_target_eot = 0.3,
derive = function(samples) {
as.numeric(quantile(samples, probs = 0.3))
}
),
cohort_size = CohortSizeConst(size = 3),
data = empty_data,
startingDose = 25
)
}
# TDDesign ----
## class ----
#' `TDDesign`
#'
#' @description `r lifecycle::badge("stable")`
#'
#' [`TDDesign`] is the class of design based only on DLT responses using
#' [`ModelTox`] class model (i.e. [`LogisticIndepBeta`]) without MCMC samples.
#'
#' @slot model (`ModelTox`)\cr the pseudo DLT model to be used.
#' @slot stopping (`Stopping`)\cr stopping rule(s) for the trial.
#' @slot increments (`Increments`)\cr how to control increments between dose levels.
#' @slot pl_cohort_size (`CohortSize`)\cr rules for the cohort sizes for placebo,
#' if any planned (defaults to constant 0 placebo patients).
#'
#' @aliases TDDesign
#' @export
#'
.TDDesign <- setClass(
Class = "TDDesign",
slots = c(
model = "ModelTox",
stopping = "Stopping",
increments = "Increments",
pl_cohort_size = "CohortSize"
),
prototype = prototype(
model = .LogisticIndepBeta(),
nextBest = .NextBestTD(),
stopping = .StoppingMinPatients(),
increments = .IncrementsRelative(),
pl_cohort_size = CohortSizeConst(0L)
),
contains = "RuleDesign"
)
## constructor ----
#' @rdname TDDesign-class
#'
#' @param model (`ModelTox`)\cr see slot definition.
#' @param stopping (`Stopping`)\cr see slot definition.
#' @param increments (`Increments`)\cr see slot definition.
#' @param pl_cohort_size (`CohortSize`)\cr see slot definition.
#' @inheritDotParams RuleDesign
#'
#' @export
#' @example examples/Design-class-TDDesign.R
#'
TDDesign <- function(model,
stopping,
increments,
pl_cohort_size = CohortSizeConst(0L),
...) {
start <- RuleDesign(...)
new(
"TDDesign",
start,
model = model,
stopping = stopping,
increments = increments,
pl_cohort_size = pl_cohort_size
)
}
## default constructor ----
#' @rdname TDDesign-class
#' @note Typically, end users will not use the `.DefaultTDDesign()` function.
#' @export
.DefaultTDDesign <- function() {
empty_data <- Data(doseGrid = seq(25, 300, 25))
my_model <- LogisticIndepBeta(
binDLE = c(1.05, 1.8),
DLEweights = c(3, 3),
DLEdose = c(25, 300),
data = empty_data
)
TDDesign(
model = my_model,
stopping = StoppingMinPatients(nPatients = 36),
increments = IncrementsRelative(
intervals = range(empty_data@doseGrid),
increments = c(2, 2)
),
nextBest = NextBestTD(
prob_target_drt = 0.35,
prob_target_eot = 0.3
),
cohort_size = CohortSizeConst(size = 3),
data = empty_data,
startingDose = 25
)
}
# DualResponsesSamplesDesign ----
## class ----
#' `DualResponsesSamplesDesign`
#'
#' @description `r lifecycle::badge("stable")`
#'
#' This is a class of design based on DLE responses using the [`LogisticIndepBeta`] model
# and efficacy responses using [`ModelEff`] model class
#' with DLE and efficacy samples. It contain all slots in
#' [`RuleDesign`] and [`TDsamplesDesign`] class objects.
#
#' @slot data (`DataDual`)\cr the data set.
#' @slot eff_model (`ModelEff`)\cr the pseudo efficacy model to be used.
#'
#' @aliases DualResponsesSamplesDesign
#' @export
#'
.DualResponsesSamplesDesign <-
setClass(
Class = "DualResponsesSamplesDesign",
slots = c(
eff_model = "ModelEff",
data = "DataDual"
),
prototype = prototype(
nextBest = .NextBestMaxGainSamples(),
data = DataDual(doseGrid = 1:2),
startingDose = 1,
model = .LogisticIndepBeta()
),
contains = "TDsamplesDesign"
)
## constructor ----
#' @rdname DualResponsesSamplesDesign-class
#'
#' @param data (`DataDual`)\cr see slot definition.
#' @param eff_model (`ModelEff`)\cr see slot definition.
#' @inheritDotParams TDsamplesDesign
#'
#' @example examples/Design-class-DualResponsesSamplesDesign.R
#' @export
#'
DualResponsesSamplesDesign <- function(eff_model,
data,
...) {
start <- TDsamplesDesign(data = data, ...)
.DualResponsesSamplesDesign(
start,
eff_model = eff_model,
data = data
)
}
## default constructor ----
#' @rdname DualResponsesSamplesDesign-class
#' @note Typically, end users will not use the `.DefaultDualResponsesSamplesDesign()` function.
#' @export
.DefaultDualResponsesSamplesDesign <- function() {
empty_data <- DataDual(doseGrid = seq(25, 300, 25))
tox_model <- LogisticIndepBeta(
binDLE = c(1.05, 1.8),
DLEweights = c(3, 3),
DLEdose = c(25, 300),
data = empty_data
)
options <- McmcOptions(burnin = 100, step = 2, samples = 200)
tox_samples <- mcmc(empty_data, tox_model, options)
eff_model <- Effloglog(
eff = c(1.223, 2.513),
eff_dose = c(25, 300),
nu = c(a = 1, b = 0.025),
data = empty_data
)
eff_samples <- mcmc(empty_data, eff_model, options)
my_next_best <- NextBestMaxGainSamples(
prob_target_drt = 0.35,
prob_target_eot = 0.3,
derive = function(samples) {
as.numeric(quantile(samples, prob = 0.3))
},
mg_derive = function(mg_samples) {
as.numeric(quantile(mg_samples, prob = 0.5))
}
)
DualResponsesSamplesDesign(
nextBest = my_next_best,
cohort_size = CohortSizeConst(size = 3),
startingDose = 25,
model = tox_model,
eff_model = eff_model,
data = empty_data,
stopping = StoppingMinPatients(nPatients = 36),
increments = IncrementsRelative(
intervals = c(25, 300),
increments = c(2, 2)
)
)
}
# DualResponsesDesign.R ----
## class ----
#' `DualResponsesDesign.R`
#'
#' @description `r lifecycle::badge("stable")`
#'
#' This is a class of design based on DLE responses using the [`LogisticIndepBeta`] model
# and efficacy responses using the [`ModelEff`] model class
#' without DLE and efficacy samples. It contains all slots from the
#' [`RuleDesign`] and [`TDsamplesDesign`] classes.
#
#' @slot data (`DataDual`)\cr the data set.
#' @slot eff_model (`ModelEff`)\cr the pseudo efficacy model to be used.
#'
#' @aliases DualResponsesDesign
#' @export
#'
.DualResponsesDesign <-
setClass(
Class = "DualResponsesDesign",
slots = c(
eff_model = "ModelEff",
data = "DataDual"
),
prototype = prototype(
nextBest = .NextBestMaxGain(),
data = DataDual(doseGrid = 1:2),
startingDose = 1,
model = .LogisticIndepBeta()
),
contains = "TDDesign"
)
## constructor ----
#' @rdname DualResponsesDesign-class
#'
#' @param data (`DataDual`)\cr see slot definition.
#' @param eff_model (`ModelEff`)\cr see slot definition.
#' @inheritDotParams TDDesign
#'
#' @example examples/Design-class-DualResponsesDesign.R
#' @export
#'
DualResponsesDesign <- function(eff_model,
data,
...) {
start <- TDDesign(data = data, ...)
.DualResponsesDesign(
start,
eff_model = eff_model,
data = data
)
}
## default constructor ----
#' @rdname DualResponsesDesign-class
#' @note Typically, end users will not use the `.DefaultDualResponsesDesign()` function.
#' @export
.DefaultDualResponsesDesign <- function() {
empty_data <- DataDual(doseGrid = seq(25, 300, 25))
DualResponsesDesign(
nextBest = NextBestMaxGain(
prob_target_drt = 0.35,
prob_target_eot = 0.3
),
cohort_size = CohortSizeConst(size = 3),
startingDose = 25,
model = LogisticIndepBeta(
binDLE = c(1.05, 1.8),
DLEweights = c(3, 3),
DLEdose = c(25, 300),
data = empty_data
),
eff_model = Effloglog(
eff = c(1.223, 2.513),
eff_dose = c(25, 300),
nu = c(a = 1, b = 0.025),
data = empty_data
),
data = empty_data,
stopping = StoppingMinPatients(nPatients = 36),
increments = IncrementsRelative(
intervals = c(25, 300),
increments = c(2, 2)
)
)
}
# DADesign ----
## class ----
#' `DADesign`
#'
#' @description `r lifecycle::badge("stable")`
#'
#' This class has special requirements for the `model` and `data`
#' slots in comparison to the parent class [`Design`]:
#'
#' @slot model (`GeneralModel`)\cr the model to use, see in particular [`DALogisticLogNormal`] and
#' [`TITELogisticLogNormal`] which make use of the time-to-DLT data.
#' @slot data (`DataDA`)\cr what is the dose grid, any previous data, etc.
#' @slot safetyWindow (`SafetyWindow`)\cr the safety window to apply between cohorts.
#'
#' @details
#' The `safetyWindow` slot should be an instance of the `SafetyWindow` class.
#' It can be customized to specify the duration of the safety window for your trial.
#' The safety window represents the time period required to observe toxicity data
#' from the ongoing cohort before opening the next cohort.
#' Note that even after opening the next cohort,
#' further toxicity data will be collected and analyzed to make dose escalation decisions.
#'
#'
#' To specify a constant safety window, use the `SafetyWindowConst` constructor. For example:
#'
#' \code{mysafetywindow <- SafetyWindowConst(c(6, 2), 10, 20)}
#'
#' @seealso [`SafetyWindowConst`] for creating a constant safety window.
#'
#' @aliases DADesign
#' @export
#'
.DADesign <-
setClass(
Class = "DADesign",
slots = c(
model = "GeneralModel",
data = "DataDA",
safetyWindow = "SafetyWindow"
),
prototype = prototype(
model = .DALogisticLogNormal(),
nextBest = .NextBestNCRM(),
data = DataDA(doseGrid = 1:2),
safetyWindow = .SafetyWindowConst()
),
contains = "Design"
)
## constructor ----
#' @rdname DADesign-class
#'
#' @param model (`GeneralModel`)\cr see slot definition.
#' @param data (`DataDA`)\cr see slot definition.
#' @param safetyWindow (`SafetyWindow`)\cr see slot definition.
#' @inheritDotParams Design
#'
#' @example examples/Design-class-DADesign.R
#' @export
#'
DADesign <- function(model, data,
safetyWindow,
...) {
start <- Design(
data = data,
model = model,
...
)
.DADesign(start,
safetyWindow = safetyWindow
)
}
## default constructor ----
#' @rdname DADesign-class
#' @note Typically, end users will not use the `.DefaultDADesign()` function.
#' @export
.DefaultDADesign <- function() {
emptydata <- DataDA(
doseGrid = c(0.1, 0.5, 1, 1.5, 3, 6, seq(from = 10, to = 80, by = 2)),
Tmax = 60
)
npiece_ <- 10
t_max_ <- 60
lambda_prior <- function(k) {
npiece_ / (t_max_ * (npiece_ - k + 0.5))
}
model <- DALogisticLogNormal(
mean = c(-0.85, 1),
cov = matrix(c(1, -0.5, -0.5, 1), nrow = 2),
ref_dose = 56,
npiece = npiece_,
l = as.numeric(t(apply(as.matrix(c(1:npiece_), 1, npiece_), 2, lambda_prior))),
c_par = 2
)
mySize1 <- CohortSizeRange(
intervals = c(0, 30),
cohort_size = c(1, 3)
)
mySize2 <- CohortSizeDLT(
intervals = c(0, 1),
cohort_size = c(1, 3)
)
mySize <- maxSize(mySize1, mySize2)
myStopping1 <- StoppingTargetProb(
target = c(0.2, 0.35),
prob = 0.5
)
myStopping2 <- StoppingMinPatients(nPatients = 50)
myStopping <- (myStopping1 | myStopping2)
DADesign(
model = model,
increments = IncrementsRelative(
intervals = c(0, 20),
increments = c(1, 0.33)
),
nextBest = NextBestNCRM(
target = c(0.2, 0.35),
overdose = c(0.35, 1),
max_overdose_prob = 0.25
),
stopping = myStopping,
cohort_size = mySize,
data = emptydata,
safetyWindow = SafetyWindowConst(c(6, 2), 7, 7),
startingDose = 3
)
}
# DesignGrouped ----
## class ----
#' `DesignGrouped`
#'
#' @description `r lifecycle::badge("experimental")`
#'
#' [`DesignGrouped`] combines two [`Design`] objects: one for the mono and one
#' for the combo arm of a joint dose escalation design.
#'
#' @slot model (`LogisticLogNormalGrouped`)\cr the model to be used, currently only one
#' class is allowed.
#' @slot mono (`Design`)\cr defines the dose escalation rules for the mono arm, see
#' details.
#' @slot combo (`Design`)\cr defines the dose escalation rules for the combo arm, see
#' details.
#' @slot first_cohort_mono_only (`flag`)\cr whether first test one mono agent cohort, and then
#' once its DLT data has been collected, we proceed from the second cohort onwards with
#' concurrent mono and combo cohorts.
#' @slot same_dose_for_all (`flag`)\cr whether the lower dose of the separately determined mono and combo
#' doses should be used as the next dose for both mono and combo in all cohorts.
#' @slot same_dose_for_start (`flag`)\cr indicates whether, when mono and combo are
#' used in the same cohort for the first time, the same dose should be used for both.
#' Note that this is different from `same_dose_for_all` which will always force
#' them to be the same. If `same_dose_for_all = TRUE`, this is therefore ignored. See Details.
#'
#' @details
#'
#' - Note that the model slots inside the `mono` and `combo` parameters
#' are ignored (because we don't fit separate regression models for the mono and
#' combo arms). Instead, the `model` parameter is used to fit a joint regression
#' model for the mono and combo arms together.
#' - `same_dose_for_start = TRUE` is useful as an option when we want to use `same_dose_for_all = FALSE`
#' combined with `first_cohort_mono_only = TRUE`.
#' This will allow to randomize patients to the mono and combo arms at the same dose
#' as long as the selected dose for the cohorts stay the same. This can therefore
#' further mitigate bias as long as possible between the mono and combo arms.
#'
#' @aliases DesignGrouped
#' @export
#'
.DesignGrouped <- setClass(
Class = "DesignGrouped",
slots = c(
model = "LogisticLogNormalGrouped",
mono = "Design",
combo = "Design",
first_cohort_mono_only = "logical",
same_dose_for_all = "logical",
same_dose_for_start = "logical"
),
prototype = prototype(
model = .DefaultLogisticLogNormalGrouped(),
mono = .Design(),
combo = .Design(),
first_cohort_mono_only = TRUE,
same_dose_for_all = TRUE,
same_dose_for_start = FALSE
),
validity = v_design_grouped,
contains = "CrmPackClass"
)
## constructor ----
#' @rdname DesignGrouped-class
#'
#' @param model (`LogisticLogNormalGrouped`)\cr see slot definition.
#' @param mono (`Design`)\cr see slot definition.
#' @param combo (`Design`)\cr see slot definition.
#' @param first_cohort_mono_only (`flag`)\cr see slot definition.
#' @param same_dose_for_all (`flag`)\cr see slot definition.
#' @param same_dose_for_start (`flag`)\cr see slot definition.
#' @param stop_mono_with_combo (`flag`)\cr whether the mono arm should be stopped when the combo
#' arm is stopped (this makes sense when the only real trial objective is the recommended combo dose).
#' @param ... not used.
#'
#' @export
#' @example examples/Design-class-DesignGrouped.R
#'
DesignGrouped <- function(model,
mono,
combo = mono,
first_cohort_mono_only = TRUE,
same_dose_for_all = !same_dose_for_start,
same_dose_for_start = FALSE,
stop_mono_with_combo = FALSE,
...) {
assert_flag(stop_mono_with_combo)
assert_class(mono, "Design")
force(combo)
if (stop_mono_with_combo) {
mono@stopping <- mono@stopping |
StoppingExternal(report_label = "Stop Mono with Combo")
}
.DesignGrouped(
model = model,
mono = mono,
combo = combo,
first_cohort_mono_only = first_cohort_mono_only,
same_dose_for_all = same_dose_for_all,
same_dose_for_start = same_dose_for_start
)
}
## default constructor ----
#' @rdname DesignGrouped-class
#' @note Typically, end-users will not use the `.DefaultDesignGrouped()` function.
#' @export
.DefaultDesignGrouped <- .DesignGrouped
# RuleDesignOrdinal ----
## class ----