Suggested code [Two-Stage / GS Designs]

posted by ElMaestro  – Denmark, 2017-08-21 16:13 (1356 d 15:33 ago) – Posting: # 17729
Views: 25,227

(edited by ElMaestro on 2017-08-21 16:37)

Hi Hötzi,

I imagine I was not able to explain what I meant??
I looked at the code available here.

Do this:

1. In the R code for the Potvin function, include this code:

Power.calc=function(Nps, GMR, CV, Is.St2=0)
  if (Is.St2==T) df=df-1
  ##cat("1-a=", 1-alpha, "df=",df,"\n")
  if (Is.St2==0) q=vecQT1[df]
    else         q=vecQT2[df]
  pw=pt( (nom1/den) -q, df) - pt( (nom2/den) +q, df)
  if (pw<0) pw=0.01

FindCritCV=function(Pwr.T, GMR, Nps, Is.St2=1, toler=0.000001)
  while (abs(
         Power.calc(Nps, GMR, CV1, Is.St2) -
         Power.calc(Nps, GMR, CV2, Is.St2))>toler)
   tmp=Pwr.T-Power.calc(Nps, GMR, CV3, Is.St2)

   if (tmp>0) CV2=CV3
      else    CV1=CV3
  return(0.5*(CV2+CV1) )

2. immediately before the line that says "if (setseed) set.seed(1234567)", include this code:
MAX=1000 ##Hötzi, specify the number of values you need,
         ##I don't know it from the top of my head.
for (i in 1:MAX)
    vecQT1[i]<<-qt(p=1-alpha[1], df=i)
    vecQT2[i]<<-qt(p=1-alpha[2], df=i)

for (Nps in 6:length(vecCritCVs))
  vecCritCVs[Nps]<<-FindCritCV(0.8, 0.95, Nps, 1, 1e-10)
  ##you can tweak this line with user setting for
  ##assumed GMR and target power as you please,
  ##using the values from the function call

3. Replace the code for SampleN.Stg2 with the code from my previous post:

» sampleN.Stg2.EM <- function(CV)
» {
»   #all other variable info is already accumulated thin the critical values, so:
»   Nps=1
»   while (vecCritCVs[Nps]<=CV) Nps=Nps+1
»   return(Nps*2) 
» }

(and make sure you call this function, possibly rename it as you deem appropriate)

4. Tweak and benchmark it. The relevant benchmark is the runtime for the entire Potvin call with 1.000.000 iterations at e.g. CV=0.3 and N1=36 total or something which takes tangible computation time. You will also need to modify the Power.calc function to accomodate other acceptance ranges.

5. Eliminate all other qt calls by replacing them with lookups into the vecQT1 or vecQT2 vectors.

Note: I did not test it, I only looked at the code online, so not everything here can be assumed to be working out of the box.

Pass or fail!

Complete thread:

 Admin contact
21,445 posts in 4,482 threads, 1,510 registered users;
online 15 (0 registered, 15 guests [including 2 identified bots]).
Forum time: Sunday 07:47 UTC (Europe/Vienna)

It is better to know some of the questions
than all of the answers.    James Thurber

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz