# R/prob_ddc.def2.R In carolinewei/apsurvival: Total sample size and its allocation for the MRCT

#### Documented in prob_ddc.def2

```#’ Calculate assurance probability by Definition 2 using asymptotic distributions derived.
#‘
#‘ @description This function uses derived distributions to calculate the unconditional
#' and conditional probabilities of claiming consistency of treatments effects in
#' an MRCT with a survival endpoint by Definition 2. It
#' is not used in the article and other functions.
#'
#' @param r0 True overall log hazard ratio
#' @param s Number of regions participating in the MRCT
#' @param E0 Event number of all regions with two groups combined
#' @param u A vector presents ratios of true regional log
#' hazard ratios to true overall log hazard ratio r=u*r0
#' @param f A Vector presents proportions of total event number
#' assigned to each region
#' @param bound The given parameter in Definition 2
#' @param alpha The risk of rejecting the null hypothesis H0:r0>=0
#' when it is really true
#'
#' @return A list
#' @export
#'
#' @examples
#' alpha=0.05
#' r0=log(0.7)
#' E0=Eventnum(r=r0, alpha=0.05, beta=0.2)
#' set.seed(123)
#' AP2 <- prob_ddc.def2(r0=r0, s=3, E0=E0, u=c(1,1,1), f=c(1/3,1/3,1/3),
#' bound=(1-0.7)/3, alpha=alpha)
#'
prob_ddc.def2 <- function(r0, s, E0, u, f, bound, alpha){

library(mvtnorm)
E = f*E0
r_reg = r0*u
r_glb = sum(r_reg*f)
delta_reg = 1-exp(r_reg)
delta_glb = 1-exp(r_glb)

mean2 = c(delta_reg,delta_glb)
v1 = 4*exp(r_glb)
v2 = exp(r_reg)/E0
v3 = 4*exp(2*r_reg)/E
corvar2 = matrix(0,(s+1),(s+1))
corvar2[1:s,1:s] = diag(v3)
corvar2[(s+1),1:s] = v1*t(v2)
corvar2[1:s,(s+1)] = v1*v2
corvar2[(s+1),(s+1)] = 4*exp(2*r_glb)/E0

lower_s = rep(bound,s)
mean2_s = mean2[1:s]
corvar2_s = corvar2[1:s,1:s]

prob2_un <- pmvnorm(lower_s,upper = Inf,mean = mean2_s,sigma =corvar2_s )

z_alpha = qnorm(1-alpha)
lower = c(lower_s,z_alpha*sqrt(corvar2[(s+1),(s+1)]))
prob2_cn <- pmvnorm(lower,upper = Inf,mean=mean2,sigma = corvar2)/(1-pnorm(z_alpha*sqrt(corvar2[(s+1),(s+1)]),mean=delta_glb,sd=sqrt( corvar2[(s+1),(s+1)] )))

return( list(prob.un=prob2_un,prob.cn=prob2_cn) )

}
```
carolinewei/apsurvival documentation built on Nov. 4, 2019, 8:44 a.m.