Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Chia-Wei Hsu authored and cran-robot committed Jun 27, 2024
0 parents commit 9528a43
Show file tree
Hide file tree
Showing 18 changed files with 1,029 additions and 0 deletions.
20 changes: 20 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Package: frequentistSSDBinary
Type: Package
Title: Screened Selection Design with Binary Endpoints
Version: 0.1.0
Authors@R: c(person("Chia-Wei", "Hsu", role = c("aut", "cre"),
email = "Chia-Wei.Hsu@stjude.org"),
person("Zongheng", "Cai", role = "aut"),
person("Haitao", "Pan", role = "aut"))
Maintainer: Chia-Wei Hsu <Chia-Wei.Hsu@stjude.org>
Description: A study based on the screened selection design (SSD) is an exploratory phase II randomized trial with two or more arms but without concurrent control. The primary aim of the SSD trial is to pick a desirable treatment arm (e.g., in terms of the response rate) to recommend to the subsequent randomized phase IIb (with the concurrent control) or phase III. The proposed designs can “partially” control or provide the empirical type I error/false positive rate by an optimal algorithm (implemented by the optimal_2arm_binary() or optimal_3arm_binary() function) for each arm. All the design needed components (sample size, operating characteristics) are supported.
License: GPL-2
Encoding: UTF-8
Depends: mvtnorm, clinfun, ph2mult
NeedsCompilation: no
Packaged: 2024-06-26 03:27:31 UTC; chsu1
Author: Chia-Wei Hsu [aut, cre],
Zongheng Cai [aut],
Haitao Pan [aut]
Repository: CRAN
Date/Publication: 2024-06-26 13:00:06 UTC
17 changes: 17 additions & 0 deletions MD5
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
c62f28da72e6ca111fff9c53216bc9eb *DESCRIPTION
a18a470f0c0ec4fd42b9eefb5e4e2cca *NAMESPACE
a5414add1ba51479192d4de122f57834 *R/SSD.2arms_notext.R
1f4c3279393114f5f0f48c20c0ce918b *R/SSD.3arms_notext.R
96228454fea3882ab153aa9995091f77 *R/get_oc_2arm_binary.R
a4e694f635733a48a1c01387cbb049dd *R/get_oc_3arm_binary.R
9a9d7a808d6554e18fc32d470bcaf1b5 *R/initial_sample.R
804bd3eaf33ed182eff4b263e4c3c40f *R/optimal_2arm_binary.R
8bb81ece38421ab84e9d813b1271f8a2 *R/optimal_3arm_binary.R
f227a41a17f6c215266d123dfac9c629 *R/sample_size_2arm_binary.R
57032dde461604fd063228fff758b9a8 *R/sample_size_3arm_binary.R
79864831d321ae2896f42ae3e1c74bf5 *man/get_oc_2arm_binary.Rd
6492f3caf82c33147640d97a9bb86e52 *man/get_oc_3arm_binary.Rd
6a39b906b60a25bd7ef272fd3e1ec6a4 *man/optimal_2arm_binary.Rd
d5057f51a5047944aff79bab3c0ffe84 *man/optimal_3arm_binary.Rd
1899f915681d2ad5ab0766cc67c77497 *man/sample_size_2arm_binary.Rd
2d136fff5c8143cd8f5b07cf601efcf4 *man/sample_size_3arm_binary.Rd
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
importFrom("stats", "qnorm", "rbinom", "rmultinom", "runif")
importFrom("mvtnorm", "qmvnorm", "pmvnorm")
importFrom("clinfun", "ph2simon")
importFrom("ph2mult", "binom.power")
export(get_oc_2arm_binary)
export(get_oc_3arm_binary)
export(optimal_2arm_binary)
export(optimal_3arm_binary)
export(sample_size_2arm_binary)
export(sample_size_3arm_binary)
161 changes: 161 additions & 0 deletions R/SSD.2arms_notext.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
SSD.2arms_notext <- function(r1, r, n1, n, p0, p1=NULL, p, nsim, diff=0.05, seed=0802) {

set.seed(seed)

if (n > 1000)
stop ("sample size, n cannot exceed 1000")

if (nsim <= 1) {
stop(" nsim less than 2! ")
}

if (r < r1 ) {
stop("r must be >= r1")
}

if (n <= n1) {
stop("condition for n > n1 must be satisfied for a 2 stage design")
}

n2 <- n- n1

p1<-ifelse(is.null(p1), p[1], p1)

outcome2<-No.success<-n.Subj<-matrix(999, ncol=2, nrow=nsim)

for(i in 1:nsim) {

for (a in 1:2) {

Stage1<-rbinom(1, n1, p[a])

outcome1<-ifelse(Stage1>r1, rbinom(1, n2, p[a]), NA)

No.success[i,a]<-sum(outcome1, Stage1, na.rm=TRUE)

outcome2[i,a]<-ifelse(outcome1+Stage1>r, 1, 0)

n.Subj[i,a] <- ifelse(Stage1>r1, n, n1)

}

}


Outcome<-apply(outcome2, 1, sum, na.rm=T)


Outcome[is.na(Outcome)]<-0

Prob.neg <-length(Outcome[Outcome==0])/nsim
Prob.pos <-length(Outcome[Outcome==2])/nsim
Prob.negpos <-length(Outcome[Outcome==1])/nsim

Prob.ArmA<-sum(outcome2[,1], na.rm=TRUE)/nsim
Prob.ArmB<-sum(outcome2[,2], na.rm=TRUE)/nsim

mean.Subj<-apply(n.Subj,2,mean, na.rm=T)

### After 1st segment
Prob.select.ArmA<-sum(outcome2[,1][outcome2[,2]==0 | is.na(outcome2[,2])],na.rm=TRUE)/nsim
Prob.select.ArmB<-sum(outcome2[,2][outcome2[,1]==0 | is.na(outcome2[,1])],na.rm=TRUE)/nsim
Prob.NoArm<-Prob.neg

### Selecting an Arm when both arms are positive (2nd Segment)

No.success.BothArms.select<-No.success[Outcome==2,]

SSD.SelectArm<-function(x, diff)
{
NoArm<-ArmA<-ArmB<-NA
if(x[2]/n==1&x[1]/n!=1){
ArmB=1
ArmA=0
}
if(x[2]/n!=1&x[1]/n==1){
ArmB=0
ArmA=1
}
if(x[2]/n==1&x[1]/n==1){
if(diff==0){
ArmA<-ifelse(runif(1,0,1)<0.5,0,1)
ArmB<-1-ArmA
}
if(diff!=0){
NoArm=1
}
}
if(x[2]/n!=1&x[1]/n!=1){
test_a=sqrt(n)*(x[1]/n-p0)/sqrt((x[1]/n)*(1-x[1]/n))
test_b=sqrt(n)*(x[2]/n-p0)/sqrt((x[2]/n)*(1-x[2]/n))
ArmB<-ifelse(test_b-test_a > diff,1,0)
ArmA<-ifelse(test_b-test_a < -diff,1,0)
## for ties
if(diff==0 & test_b-test_a == 0) {
ArmA<-ifelse(runif(1,0,1)<0.5,0,1)
ArmB<-1-ArmA
}

## for SSD_mod with no selection for ties or if diff <= e.g.0.05
if(diff!=0) {
NoArm<-ifelse(test_b-test_a <= diff & test_a-test_b <= diff,1,0)
}
}
return(list(ArmA, ArmB, NoArm))
}


### Original SSD

if( length(No.success[Outcome==2,]) > 1 ) {
SSD.SelectArm.2ndSeg<-matrix(unlist(
apply(No.success[Outcome==2,],1,SSD.SelectArm, diff=0) ###for each Two-stage successfull row, apply the selection criteria
),ncol=3,byrow=T)} else {SSD.SelectArm.2ndSeg <- matrix(NA,ncol=3) }

ProbArmA.2ndSeg<-sum(SSD.SelectArm.2ndSeg[,1],na.rm=TRUE)/nsim
ProbArmB.2ndSeg<-sum(SSD.SelectArm.2ndSeg[,2],na.rm=TRUE)/nsim
ProbNoArm.2ndSeg<-sum(SSD.SelectArm.2ndSeg[,3],na.rm=TRUE)/nsim

Overall.ArmA<-Prob.select.ArmA + ProbArmA.2ndSeg
Overall.ArmB<-Prob.select.ArmB + ProbArmB.2ndSeg
Overall.NoArm<-Prob.NoArm + ProbNoArm.2ndSeg


### Modified SSD ####

if( length(No.success[Outcome==2,]) > 1 ) {
SSD.SelectArm.2ndSeg<-matrix(unlist(
apply(No.success[Outcome==2,],1,SSD.SelectArm, diff)
),ncol=3,byrow=T)} else {SSD.SelectArm.2ndSeg <- matrix(NA,ncol=3) }

ProbArmA.2ndSeg.MOD<-sum(SSD.SelectArm.2ndSeg[,1],na.rm=TRUE)/nsim
ProbArmB.2ndSeg.MOD<-sum(SSD.SelectArm.2ndSeg[,2],na.rm=TRUE)/nsim
ProbNoArm.2ndSeg.MOD<-sum(SSD.SelectArm.2ndSeg[,3],na.rm=TRUE)/nsim

Overall.ArmA.MOD<-Prob.select.ArmA + ProbArmA.2ndSeg.MOD
Overall.ArmB.MOD<-Prob.select.ArmB + ProbArmB.2ndSeg.MOD
Overall.NoArm.MOD<-Prob.NoArm + ProbNoArm.2ndSeg.MOD

if(diff==0){
soln<-data.frame("n"=n,
"SSD Arm A"=Overall.ArmA, "SSD Arm B"= Overall.ArmB, "SSD No Arm"=Overall.NoArm,
"diff"=diff,
"Mean N Arm A"=mean.Subj[1],"Mean N Arm B"=mean.Subj[2])


}
if(diff!=0){
soln<-data.frame("n"=n,
"Modified SSD Arm A"=Overall.ArmA.MOD, "Modified SSD Arm B"=Overall.ArmB.MOD,
"Modified SSD No Arm"=Overall.NoArm.MOD, "diff"=diff,
"Mean N Arm A"=mean.Subj[1],"Mean N Arm B"=mean.Subj[2])


}



soln

}

Loading

0 comments on commit 9528a43

Please sign in to comment.