#’ Calculate event number and total sample size
#'
#' @description The function Eventnum calculates event number based on the
#' logrank test statisitic. The function Samplesize calculates total sample size
#' based on the assumption of fixed study duration design.
#'
#' @param r0 Log hazard ratio
#' @param alpha The risk of rejecting the null hypothesis H0:r0>=0
#' when it is really true
#' @param beta The risk of failing to reject the null
#' hypothesis H0:r0>=0 when it is really false
#' @param E Event number of two groups combined
#' @param lamda The event hazard rate for placebo
#' @param lamda_cen The discontinuation hazard rate
#' @param L The whole study duration of fixed study duration
#' design
#'
#' @return A single value of each function.
#' @export
#'
#' @examples
#' Eventnum(r=log(0.7), alpha=0.05, beta=0.2)
#' Samplesize(r=log(0.7), alpha=0.05, beta=0.2, E=50, lamda=1, lamda_cen=1, L=2)
#'
Eventnum <- function(r, alpha=0.05, beta=0.2){
E = ceiling( 4*(qnorm(alpha,0,1)+qnorm(beta,0,1))^2/(r)^2 )
return(E)
}
Samplesize <- function(r, alpha=0.05, beta=0.2, E, lamda, lamda_cen, L){
lamda1 = lamda*exp(r)
H0 = lamda/(lamda+lamda_cen)*(1-exp(-L*(lamda+lamda_cen)))
H1 = lamda1/(lamda1+lamda_cen)*(1-exp(-L*(lamda1+lamda_cen)))
N = round(2*E/(H0+H1))
if (N %% 2 == 1) N = N+1
return(N)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.