R-code shortening [Power / Sample Size]
Dear Helmut,
here comes my programming gem
for the sensitivity with respect to sample size: Replace all the code for the different designs by
here comes my programming gem

####################################
# min. n for minimum accept. power #
# workaround, since uniroot() does #
# not accept two vectors as limits #
####################################
Ns <- seq(n.est, 12, by=-1) # don't drop below 12 subjects
j <- 0
pwrN <- pwr.est
n.min <- NULL; pBEn <- NULL
# get # of sequences f.i. via this clumsy construct
seqs <- known.designs()[known.designs()$design==des,"steps"]
n <- vector("numeric", length=seqs)
ni <- 1:seqs
# may it be that j grows greater than length(Ns)?
# paranoia
nNs <- length(Ns)
while(pwrN >= pwr.min & j<nNs){
j <- j+1
# distribute total Ns to the sequence groups
# n[-seqs] is n[1:(seqs-1)]
n[-seqs] <- diff(floor(Ns[j]*ni/seqs))
n[seqs] <- Ns[j] -sum(n[-seqs])
# can use allways power2.TOST() if PowerTOST V1.1-13 is used
# else an if() construct is necessary switching to power.TOST()
# in case of des=="paired"
pwrN <- power2.TOST(CV=CV, n=n, theta0=GMR, design=des)
if(pwrN >= pwr.min) {
# stepwise growing vectors is R-Inferno Circle 2
# but here we dont know the dimension in advance. Right?
n.min <- c(n.min, sum(n))
pBEn <- c(pBEn, 100*pwrN)
} else {
break
}
}
# plot code follows
...
—
Regards,
Detlew
Regards,
Detlew
Complete thread:
- Deviating from assumptions Helmut 2014-08-08 15:44 [Power / Sample Size]
- Some Nitpicking d_labes 2014-08-12 09:12
- Some Nitpicking Helmut 2014-08-12 10:49
- R-code for all ABE designs Helmut 2014-08-12 17:21
- Sensitivity analysis for all ABE designs d_labes 2014-08-13 09:30
- Sensitivity analysis for all ABE designs Helmut 2014-08-13 14:49
- R-code shorteningd_labes 2014-08-13 16:32
- Suggestions / Sneak Preview Helmut 2014-08-13 16:42
- Suggestions / Sneak Preview d_labes 2014-08-15 09:01
- Suggestions / Sneak Preview Helmut 2014-08-15 12:02
- Mehl returned! d_labes 2014-08-15 11:27
- Mehl returned! Helmut 2014-08-15 11:42
- Suggestions / Sneak Preview d_labes 2014-08-15 09:01
- Suggestions / Sneak Preview Helmut 2014-08-13 16:42
- Sensitivity analysis for all ABE designs d_labes 2014-08-13 09:30
- Some Nitpicking d_labes 2014-08-12 09:12