Suggested code [Two-Stage / GS Designs]
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:
2. immediately before the line that says "if (setseed) set.seed(1234567)", include this code:
3. Replace the code for SampleN.Stg2 with the code from my previous post:
❝ Nps=1
❝ while (vecCritCVs[Nps]<=CV) Nps=Nps+1
❝ return(Nps*2)
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.
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)
{
s=sqrt(log(1+CV*CV))
nom1=log(1.25/GMR)
nom2=-log(1.25*GMR)
den=s*sqrt(2/(2*Nps))
df=Nps*2-2
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
return(pw)
}
FindCritCV=function(Pwr.T, GMR, Nps, Is.St2=1, toler=0.000001)
{
CV1=0.0123
CV2=8.7654
while (abs(
Power.calc(Nps, GMR, CV1, Is.St2) -
Power.calc(Nps, GMR, CV2, Is.St2))>toler)
{
CV3=0.5*(CV1+CV2)
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.
vecQT1<<-c(1:MAX)
vecQT2<<-c(1:MAX)
for (i in 1:MAX)
{
vecQT1[i]<<-qt(p=1-alpha[1], df=i)
vecQT2[i]<<-qt(p=1-alpha[2], df=i)
}
vecCritCVs<<-rep(0,MAX)
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)
❝ {
❝ Nps=1
❝ while (vecCritCVs[Nps]<=CV) Nps=Nps+1
❝ return(Nps*2)
❝ }
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!
ElMaestro
Pass or fail!
ElMaestro
Complete thread:
- Initial sample size guess for the Potvin methods ElMaestro 2017-08-19 15:04 [Two-Stage / GS Designs]
- Initial sample size guess for the Potvin methods Helmut 2017-08-19 16:06
- Initial sample size guess for the Potvin methods ElMaestro 2017-08-19 16:14
- Initial sample size guess for the Potvin methods Helmut 2017-08-19 17:12
- Initial sample size guess for the Potvin methods ElMaestro 2017-08-19 17:17
- Confuse-a-Cat Helmut 2017-08-19 17:33
- Confuse-a-Cat ElMaestro 2017-08-19 17:56
- Confuse-a-Cat Helmut 2017-08-19 17:33
- Initial sample size guess for the Potvin methods ElMaestro 2017-08-19 17:17
- loop ↔ vectorized ↔ direct Helmut 2017-08-20 14:40
- loop ↔ vectorized ↔ direct ElMaestro 2017-08-20 15:22
- loop ↔ vectorized ↔ direct Helmut 2017-08-20 16:23
- loop ↔ vectorized ↔ direct ElMaestro 2017-08-20 17:22
- loop ↔ vectorized ↔ direct Helmut 2017-08-20 16:23
- loop ↔ vectorized ↔ direct ElMaestro 2017-08-20 15:22
- Initial sample size guess for the Potvin methods Helmut 2017-08-19 17:12
- Initial sample size guess for the Potvin methods ElMaestro 2017-08-19 16:14
- The n ext crackpot iteration ElMaestro 2017-08-19 20:04
- The n ext crackpot iteration Helmut 2017-08-20 02:20
- The ultimate crackpot iteration! ElMaestro 2017-08-20 14:35
- The ultimate crackpot iteration! Helmut 2017-08-20 15:11
- The ultimate crackpot iteration! ElMaestro 2017-08-20 15:28
- The ultimate crackpot iteration! Helmut 2017-08-20 16:06
- The ultimate crackpot iteration! ElMaestro 2017-08-20 16:15
- The ultimate crackpot iteration! Helmut 2017-08-20 18:58
- The ultimate crackpot iteration! ElMaestro 2017-08-20 19:32
- Suggested codeElMaestro 2017-08-21 18:13
- Nitpicker! Helmut 2017-08-22 13:33
- Nitpicker! ElMaestro 2017-08-22 17:27
- Nitpicker! Helmut 2017-08-22 17:49
- Nitpicker! ElMaestro 2017-08-22 17:59
- Nitpicker! Helmut 2017-08-22 19:15
- Benchmark code ElMaestro 2017-08-22 22:29
- Benchmark code Helmut 2017-08-23 01:48
- Benchmark code ElMaestro 2017-08-22 22:29
- Nitpicker! Helmut 2017-08-22 19:15
- Nitpicker! ElMaestro 2017-08-22 17:59
- Nitpicker! Helmut 2017-08-22 17:49
- Nitpicker! ElMaestro 2017-08-22 17:27
- Nitpicker! Helmut 2017-08-22 13:33
- Suggested codeElMaestro 2017-08-21 18:13
- The ultimate crackpot iteration! ElMaestro 2017-08-20 19:32
- The ultimate crackpot iteration! Helmut 2017-08-20 18:58
- The ultimate crackpot iteration! ElMaestro 2017-08-20 16:15
- The ultimate crackpot iteration! Helmut 2017-08-20 16:06
- The ultimate crackpot iteration! ElMaestro 2017-08-20 15:28
- The ultimate crackpot iteration! Helmut 2017-08-20 15:11
- Initial sample size guess for the Potvin methods Helmut 2017-08-19 16:06