A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rpact-com/rpact/issues/19 below:

should clarify allocationRatioPlanned should be treated as vector instead of scalar · Issue #19 · rpact-com/rpact · GitHub

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)

custom SSR function

myCPZSampleSizeCalculationFunction <- function(..., stage,
minNumberOfSubjectsPerStage,
maxNumberOfSubjectsPerStage,
conditionalPower,
conditionalCriticalValue,
allocationRatioPlanned,
thetaH1,
stDevH1) {

function adapted from example in ?getSimulationMeans note conditionalCriticalValue gives the critical value on the mean/proportion level of current stage data alone instead of the overall cumulative critical Values on the z-scale (uk) at current stage it already took care of 1. the weights based inverse normal method 2. observed data from previous stages and gives critical values with the design

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 stageSubjects

stageSubjects <- 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 size

if (stageSubjectsCPmin > maxNumberOfSubjectsPerStage[stage]) {
stageSubjects <- minNumberOfSubjectsPerStage[stage]
}

return sample size

return(stageSubjects)
}

custom SSR function

myCPZSampleSizeCalculationFunction2 <- function(..., stage,
minNumberOfSubjectsPerStage,
maxNumberOfSubjectsPerStage,
conditionalPower,
conditionalCriticalValue,
allocationRatioPlanned,
thetaH1,
stDevH1) {

function adapted from example in ?getSimulationMeans note conditionalCriticalValue gives the critical value on the mean/proportion level of current stage data alone instead of the overall cumulative critical Values on the z-scale (uk) at current stage it already took care of 1. the weights based inverse normal method 2. observed data from previous stages and gives critical values with the design

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 stageSubjects

stageSubjects <- 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 size

if (stageSubjectsCPmin > maxNumberOfSubjectsPerStage[stage]) {
stageSubjects <- minNumberOfSubjectsPerStage[stage]
}

return sample size

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