Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calcSubjectsFunction: should clarify allocationRatioPlanned should be treated as vector instead of scalar #19

Closed
pmahling opened this issue Feb 9, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@pmahling
Copy link

pmahling commented Feb 9, 2024

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)

@gwassmer
Copy link
Collaborator

Thanks a lot for this suggestion. You are completely rigth, we will add a remark in the help for allocationRatioPlanned and change the help example. We are happy to hearing more comments!

fpahlke added a commit that referenced this issue Feb 22, 2024
+ codecov added
+ Issues [#19](#19) and [#21](#21) fixed
@fpahlke
Copy link
Member

fpahlke commented Feb 23, 2024

We update our examples in the manual/vignette.

@fpahlke fpahlke closed this as completed Feb 23, 2024
fpahlke added a commit that referenced this issue Feb 23, 2024
fpahlke added a commit that referenced this issue Feb 27, 2024
@fpahlke fpahlke added the documentation Improvements or additions to documentation label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants