You probably want to update your examples in the manual/ vignette about the custom sample size re-calculation functions: making it clear that allocationRatioPlanned is treated as a vector in the back end, not a scalar. Please see below example.
simpowerCPZ shows error message:
Error in fun(alternative = alternative, kMax = design$kMax, maxNumberOfIterations = maxNumberOfIterations, :
Evaluation error: the condition has length > 1.
simpowerCPZ2 uses allocationRatioPlanned[stage] instead and it runs fine.
library(rpact)
n1<-8 #interim sample size/arm
Nmin<-15 #min sample size/arm
Nmax<-23 #max sample size/arm
designc<-getDesignInverseNormal(sided = 1, alpha = 0.05, beta = 0.2,kMax=2,informationRates=c(n1/Nmin,1),
typeOfDesign = "noEarlyEfficacy", typeBetaSpending = "bsHSD",gammaB = -3)
myCPZSampleSizeCalculationFunction <- function(..., stage,
minNumberOfSubjectsPerStage,
maxNumberOfSubjectsPerStage,
conditionalPower,
conditionalCriticalValue,
allocationRatioPlanned,
thetaH1,
stDevH1) {
calculateStageSubjects <- function(cp) {
(1 + allocationRatioPlanned)^2/allocationRatioPlanned *
(max(0, conditionalCriticalValue + stats::qnorm(cp)))^2 /
(max(1e-12, thetaH1/stDevH1))^2
}
Calculate sample size required to reach maximum desired conditional power cp_max (provided as argument conditionalPower)stageSubjectsCPmax <- calculateStageSubjects(cp = conditionalPower)
Calculate sample size required to reach minimum desired conditional power cp_min (manually set for this example to 0.7)stageSubjectsCPmin <- calculateStageSubjects(cp = 0.7)
Define stageSubjectsstageSubjects <- ceiling(min(max(minNumberOfSubjectsPerStage[stage], stageSubjectsCPmax), maxNumberOfSubjectsPerStage[stage]))
Set stageSubjects to minimal sample size in case minimum conditional power cannot be reached with available sample sizeif (stageSubjectsCPmin > maxNumberOfSubjectsPerStage[stage]) {
stageSubjects <- minNumberOfSubjectsPerStage[stage]
}
return(stageSubjects)
}
myCPZSampleSizeCalculationFunction2 <- function(..., stage,
minNumberOfSubjectsPerStage,
maxNumberOfSubjectsPerStage,
conditionalPower,
conditionalCriticalValue,
allocationRatioPlanned,
thetaH1,
stDevH1) {
calculateStageSubjects <- function(cp) {
(1 + allocationRatioPlanned[stage])^2/allocationRatioPlanned[stage] *
(max(0, conditionalCriticalValue + stats::qnorm(cp)))^2 /
(max(1e-12, thetaH1/stDevH1))^2
}
Calculate sample size required to reach maximum desired conditional power cp_max (provided as argument conditionalPower)stageSubjectsCPmax <- calculateStageSubjects(cp = conditionalPower)
Calculate sample size required to reach minimum desired conditional power cp_min (manually set for this example to 0.7)stageSubjectsCPmin <- calculateStageSubjects(cp = 0.7)
Define stageSubjectsstageSubjects <- ceiling(min(max(minNumberOfSubjectsPerStage[stage], stageSubjectsCPmax), maxNumberOfSubjectsPerStage[stage]))
Set stageSubjects to minimal sample size in case minimum conditional power cannot be reached with available sample sizeif (stageSubjectsCPmin > maxNumberOfSubjectsPerStage[stage]) {
stageSubjects <- minNumberOfSubjectsPerStage[stage]
}
return(stageSubjects)
}
simpowerCPZ <- getSimulationMeans(designc,
alternative =0.65, stDev =0.7,
# cumulative overall sample size
plannedSubjects = 2 * c(n1, Nmin),
# stage-wise minimal overall sample size
minNumberOfSubjectsPerStage = 2 * c(n1, (Nmin - n1)),
# stage-wise maximal overall sample size
maxNumberOfSubjectsPerStage = 2 * c(n1, (Nmax - n1)),
conditionalPower = 0.8,
thetaH1 = 0.5, stDevH1=0.7,
maxNumberOfIterations = 1000,
seed = 12345,
calcSubjectsFunction = myCPZSampleSizeCalculationFunction)
simpowerCPZ2 <- getSimulationMeans(designc,
alternative =0.65, stDev =0.7,
# cumulative overall sample size
plannedSubjects = 2 * c(n1, Nmin),
# stage-wise minimal overall sample size
minNumberOfSubjectsPerStage = 2 * c(n1, (Nmin - n1)),
# stage-wise maximal overall sample size
maxNumberOfSubjectsPerStage = 2 * c(n1, (Nmax - n1)),
conditionalPower = 0.8,
thetaH1 = 0.5, stDevH1=0.7,
maxNumberOfIterations = 1000,
seed = 12345,
calcSubjectsFunction = myCPZSampleSizeCalculationFunction2)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4