#' calcSampleSizeForRCT
#'
#' @param alpha the significance level
#' @param gamma the power that you want
#' @param piT the estimated incidences of the disease in the disease
#' @param piC the estimated incidences of the disease in the control
#' @param p lost follow-up ratio
#'
#' @return string
#' @export
#'
#' @examples
#' calcSampleSizeForRCT(alpha=0.05, gamma=0.80, piT=0.15, piC=0.2)
#' #tatol sample should be doubled
calcSampleSizeForRCT <- function(alpha, gamma, piT, piC, p = 0) {
# if we estimate that 10% of the people are likely to be lost to follow-up, then p=0.1
qalpha <- qnorm(p = 1 - (alpha / 2))
qgamma <- qnorm(p = gamma)
pi0 <- (piT + piC) / 2
numerator <- 2 * ((qalpha + qgamma)^2) * pi0 * (1 - pi0)
denominator <- (piT - piC)^2
n <- numerator / denominator
n <- ceiling(n) # round up to the nearest integer
# adjust for likely losses to folow-up
n <- n / (1 - p)
n <- ceiling(n) # round up to the nearest integer
print(paste("Sample size for each trial group = ", n))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.