# NOT RUN {
# using all the defaults and 24 subjects in stage 1, CV of 25%
power.tsd(n1=24, CV=0.25)
# computation time ~ 1 sec
#
# as above, but save results for further use
res <- power.tsd(n1=24, CV=0.25)
# }
# NOT RUN {
# representation of the discrete distribution of n(total)
# via plot method of object with class "table" which creates a
# 'needle' plot
plot(res$ntable/sum(res$ntable), ylab="Density",
xlab=expression("n"[total]), las=1,
main=expression("Distribution of n"[total]))
#
# If you prefer a histogram instead (IMHO, not the preferred plot):
# reconstruct the ntotal values from the ntable
ntot <- rep.int(as.integer(names(res$ntable)),
times=as.integer(res$ntable))
# annotated histogram
hist(ntot, freq=FALSE, breaks=res$nrange[2]-res$nrange[1],
xlab=expression("n"[total]), las=1,
main=expression("Histogram of n"[total]))
abline(v=c(res$nmean, res$nperc[["50%"]]), lty=c(1, 3))
legend("topright", box.lty=0, legend=c("mean", "median"),
lty=c(1, 3), cex=0.9)
# }
Run the code above in your browser using DataLab