Skip to content

Commit 438b4c9

Browse files
committed
MODIFIED FOR CRAN
1 parent 501a00f commit 438b4c9

25 files changed

Lines changed: 572 additions & 870 deletions

.DS_Store

0 Bytes
Binary file not shown.

.Rhistory

Lines changed: 450 additions & 450 deletions
Large diffs are not rendered by default.

DESCRIPTION

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: BayesianPlatformDesignTimeTrend
2-
Title: Simulate and analyse Bayesian Platform Trial with time trend
2+
Title: Simulate and Analyse Bayesian Platform Trial with Time Trend
33
Version: 1.0.0
44
Author: Ziyan Wang [aut, cre]
55
Maintainer: Ziyan Wang <zw7g20@soton.ac.uk>
@@ -8,18 +8,18 @@ Authors@R:
88
family = "Wang",
99
role = c("aut", "cre"),
1010
email = "zw7g20@soton.ac.uk")
11-
Description: Simulating the multi-arm multi-stage or platform trial with Bayesian approach using the 'rstan' package, which provides the R interface for to the Stan.
12-
The randomisation approach in this package are fix ratio and Bayesian adaptive randomisation.
13-
In addition, the time trend problem of platform trial can be studied in this package.
14-
There is a demo for multi-arm multi-stage trial with two different null scenario and a demo for Bayesian trial cutoff screening.
11+
Description: Simulating the multi-arm multi-stage or platform trial with Bayesian approach using the 'rstan' package, which provides the R interface for the Stan.
12+
This package supports fixed ratio and Bayesian adaptive randomization approaches for randomization.
13+
Additionally, it allows for the study of time trend problems in platform trials.
14+
There are demos available for a multi-arm multi-stage trial with two different null scenarios, as well as for Bayesian trial cutoff screening.
1515
The Bayesian adaptive randomisation approaches are described in:
1616
Trippa et al. (2012) <doi:10.1200/JCO.2011.39.8420> and
17-
Wathen et al. (2017) <doi:10.1177/1740774517692302>
18-
The randomisation algorithm is described in
19-
Zhao W <doi:10.1016/j.cct.2015.06.008>
17+
Wathen et al. (2017) <doi:10.1177/1740774517692302>.
18+
The randomisation algorithm is described in:
19+
Zhao W <doi:10.1016/j.cct.2015.06.008>.
2020
The analysis methods of time trend effect in platform trial are described in:
2121
Saville et al. (2022) <doi:10.1177/17407745221112013> and
22-
Bofill Roig et al. (2022) <doi:10.1186/s12874-022-01683-w>
22+
Bofill Roig et al. (2022) <doi:10.1186/s12874-022-01683-w>.
2323
URL: https://github.com/ZXW834/PlatFormDesignTime
2424
Encoding: UTF-8
2525
Roxygen: list(markdown = TRUE)
@@ -41,8 +41,7 @@ Imports:
4141
foreach (>= 1.5.1),
4242
iterators (>= 1.0.13),
4343
reshape (>= 0.8.8),
44-
BiocManager (>= 1.30.19),
45-
rjags
44+
BiocManager (>= 1.30.19)
4645
LinkingTo:
4746
BH (>= 1.66.0),
4847
Rcpp (>= 0.12.0),

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
YEAR: 2023
2-
COPYRIGHT HOLDER: PlatFormDesign authors
2+
COPYRIGHT HOLDER: BayesianPlatformDesignTimeTrend authors

NAMESPACE

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export(Boundaryconstruction)
66
export(FWER_disconjunctivepowerfunc)
77
export(Initializetrialparameter)
88
export(Meanfunc)
9-
export(Mixeffect_analysis)
10-
export(Mixeffect_modelling)
119
export(Nfunc)
1210
export(OutputStats.initialising)
1311
export(Randomisation.inf)
@@ -57,6 +55,5 @@ importFrom(stats,pbeta)
5755
importFrom(stats,pnorm)
5856
importFrom(stats,predict)
5957
importFrom(stats,rbinom)
60-
importFrom(stats,update)
6158
importFrom(stats,var)
6259
useDynLib(BayesianPlatformDesignTimeTrend, .registration = TRUE)

R/Demo_CutoffScreening.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ demo_Cutoffscreening = function(ntrials = 1000,
3131
response.probs = c(0.4, 0.4),
3232
ns = c(30, 60, 90, 120, 150),
3333
max.ar = 0.75,
34-
rand.type = "Urn",
34+
rand.algo = "Urn",
3535
max.deviation = 3,
3636
model.inf = list(
3737
model = "tlr",
@@ -67,6 +67,7 @@ demo_Cutoffscreening = function(ntrials = 1000,
6767
),
6868
cl = 2) {
6969
old <- options()# code line i
70+
on.exit(options(old))
7071
#Set start grid of screening
7172
startgrid <-
7273
data.frame(tpIE = rep(NA, length(grid.inf$start)), cutoff = grid.inf$start)
@@ -94,7 +95,7 @@ demo_Cutoffscreening = function(ntrials = 1000,
9495
response.probs = input.info$response.probs,
9596
ns = input.info$ns,
9697
max.ar = input.info$max.ar,
97-
rand.type = input.info$rand.type,
98+
rand.algo = input.info$rand.algo,
9899
max.deviation = input.info$max.deviation,
99100
model.inf = input.info$model.inf,
100101
Stopbound.inf = Stopbound.inf,
@@ -138,7 +139,7 @@ demo_Cutoffscreening = function(ntrials = 1000,
138139
response.probs = input.info$response.probs,
139140
ns = input.info$ns,
140141
max.ar = input.info$max.ar,
141-
rand.type = input.info$rand.type,
142+
rand.algo = input.info$rand.algo,
142143
max.deviation = input.info$max.deviation,
143144
model.inf = input.info$model.inf,
144145
Stopbound.inf = Stopbound.inf,
@@ -178,7 +179,6 @@ demo_Cutoffscreening = function(ntrials = 1000,
178179
predict(quadratic.model,
179180
list(cutoff = cutoffgrid, cutoff2 = cutoffgrid ^ 2))
180181
doParallel::stopImplicitCluster()
181-
on.exit(options(old))
182182
return(
183183
list(
184184
detailsforgrid = dataloginformd,

R/Demo_multiplescenariotrialsimulation.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ demo_multscenario = function(ntrials = 1000,
6666
response.probs = scenario[i,],
6767
ns = ns[[z]],
6868
max.ar = 0.75,
69-
rand.type = "Urn",
69+
rand.algo = "Urn",
7070
max.deviation = 3,
7171
model.inf = list(
7272
model = "tlr",

R/MainFunction.R

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' @param response.probs A vector of true response probability for each arm. Default response.probs = c(0.4, 0.4).
55
#' @param ns A vector of accumulated number of patient at each stage. Default is ns = c(30, 60, 90, 120, 150).
66
#' @param max.ar The upper boundary for randomisation ratio for each arm. Default is 0.75 for a two arm trial.
7-
#' @param rand.type The method of applying patient allocation with a given randomisation probability vector. Default is "Urn".
7+
#' @param rand.algo The method of applying patient allocation with a given randomisation probability vector. Default is "Urn".
88
#' @param max.deviation The tuning parameter for Urn randomisation method. Default is 3.
99
#' @param Stopbound.inf The list of stop boundary information for more see \code{\link{Stopboundinf}}
1010
#' @param Random.inf The list of Adaptive randomisation information for more see \code{\link{Randomisation.inf}}
@@ -19,7 +19,7 @@
1919
#' simulatetrial(response.probs = c(0.4, 0.4),
2020
#' ns = c(30, 60, 90, 120, 150),
2121
#' max.ar = 0.75,
22-
#' rand.type = "Urn",
22+
#' rand.algo = "Urn",
2323
#' max.deviation = 3,
2424
#' model.inf = list(
2525
#' model = "tlr",
@@ -60,7 +60,7 @@ simulatetrial <- function(ii,
6060
response.probs = c(0.4, 0.4),
6161
ns = c(30, 60, 90, 120, 150),
6262
max.ar = 0.75,
63-
rand.type = "Urn",
63+
rand.algo = "Urn",
6464
max.deviation = 3,
6565
model.inf = list(
6666
model = "tlr",
@@ -139,10 +139,10 @@ simulatetrial <- function(ii,
139139

140140
# Patient randomisation based on given randomization ratio
141141
# Parameter checking
142-
if (rand.type %in% c("Coin", "Urn")) {
142+
if (rand.algo %in% c("Coin", "Urn")) {
143143
random.output = AdaptiveRandomisation(
144144
Fixratio,
145-
rand.type,
145+
rand.algo,
146146
K,
147147
n.new,
148148
randomprob,
@@ -491,66 +491,6 @@ simulatetrial <- function(ii,
491491
treatmentindex = treatmentindex[is.na(match(treatmentindex, treatmentdrop))]
492492
}
493493
}
494-
else if (model.inf$tlr.inf$variable.inf == "Mixeffect.jag") {
495-
jagmodel<-" model {
496-
for(i in 1:armleft){
497-
for(j in 1:stage){
498-
Y[i,j] ~ dbin(p[i,j],N[i,j])
499-
logit(p[i,j]) = beta0 + alpha[stage-(j-1)] + beta1[i]
500-
}
501-
}
502-
alpha[1] = 0
503-
alpha[2] ~ dnorm(0, tau2)
504-
for(k in 3:stage ) {
505-
alpha[k] ~ dnorm(2*alpha[k-1] - alpha[k-2],tau2)
506-
}
507-
beta1[1] <- 0
508-
for(i in 2:armleft){
509-
beta1[i] ~ dnorm(0,0.31)
510-
}
511-
tau2 ~ dgamma(0.1, 0.01)
512-
beta0 ~ dnorm(0, 0.31)
513-
}"
514-
postsamp.list = Mixeffect_modelling(ytemp=ytemp, treatmentindex=treatmentindex, group=group, ntemp=ntemp, armleft=armleft, jagmodel=jagmodel)
515-
analysis = Mixeffect_analysis(postsamp.list=postsamp.list, group=group, treatmentindex=treatmentindex, ns = ns, K = K)
516-
stats1 = analysis$stats1
517-
statsbeta0 = analysis$statsbeta0
518-
stats4 = analysis$stats4
519-
stats5 = analysis$stats5
520-
stats6 = analysis$stats6
521-
stats7 = analysis$stats7
522-
sampoutcome = analysis$sampoutcome
523-
sampefftotal = analysis$sampefftotal
524-
post.prob.btcontrol = analysis$post.prob.btcontrol
525-
#-Calculating posterior probability of each arm (including control) to be the best arm-
526-
# post.prob.best: The posterior probability of each arm (including control) to be the best arm
527-
# This is required for Thall's randomisation approach
528-
for (q in 1:armleft) {
529-
post.prob.best.mat[group, zlevel[q]] = (sum(max.col(sampefftotal) == q)) /
530-
2500
531-
}
532-
post.prob.best = post.prob.best.mat[group,]
533-
#Normalizing in case any value equals zero
534-
post.prob.best = post.prob.best + 1e-7
535-
post.prob.best = post.prob.best / sum(post.prob.best)
536-
#----Justify if type I error was made for each arm----
537-
# post.prob.btcontrol>cutoffeff[group]: Efficacy boundary is hit at this stage
538-
# post.prob.btcontrol<cutoffful[group]: Fultility boundary is hit at this stage
539-
Justify = post.prob.btcontrol > cutoffeff[group] |
540-
post.prob.btcontrol < cutoffful[group]
541-
#Identify which active arm should be dropped at current stage
542-
treatmentdrop = treatmentindex[post.prob.btcontrol > cutoffeff[group] |
543-
post.prob.btcontrol < cutoffful[group]]
544-
stats3 = rep(NA, K - 1)
545-
names(stats3) = seq(1, K - 1)
546-
stats3[treatmentindex] = Justify
547-
if (sum(Justify) > 0) {
548-
armleft = armleft - sum(Justify)
549-
#Debugged for K arm by Ziyan Wang on 12:00 26/07/2022 for three arm. Used to be treatmentindex = treatmentindex[-treatmentdrop]
550-
#Debugged for K arm by Ziyan Wang on 18:58 26/07/2022 for more than 3 arm. Used to be treatmentindex = treatmentindex[!(treatmentindex==treatmentdrop)]
551-
treatmentindex = treatmentindex[is.na(match(treatmentindex, treatmentdrop))]
552-
}
553-
}
554494

555495
#-Adjust the posterior randomisation ratio-
556496
randomprob = ARmethod(

R/Simulation_AdaptiveRandomisationmethodRatioCalc.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ ARmethod = function(Fixratio,
5252
max.ar,
5353
armleft,
5454
treatmentindex) {
55+
# Validate inputs
56+
if (!is.logical(Fixratio)) stop("Error: Fixratio should be a logical value (TRUE/FALSE)")
57+
if (!is.character(BARmethod)) stop("Error: BARmethod should be a character value")
58+
if (!is.numeric(group) || group <= 0) stop("Error: group should be a positive numeric value")
59+
if (!is.numeric(max.ar) || max.ar <= 0 || max.ar >= 1) stop("Error: max.ar should be a numeric value between 0 and 1")
60+
if (K < 2) stop("Error: K should be an integer value greater than or equal to 2")
61+
5562
#---------------------Trippa's approach---------------------
5663
if (Fixratio == F & BARmethod == "Trippa") {
5764
##Tuning the paprameter using method mentioned in Trippa's paper (2014)

R/Simulation_JAGSMixeffectmodelanalysis.R

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)