R/Intr_func.R

Defines functions Intr_func

Documented in Intr_func

#' Calculates the probability of first outcomes outsdie of grey
#'
#' @param M vector of section sample sizes. If you have an interim at 10, 15 and 20 samples M should be c(10,5,5)
#' @param R matrix of decision points, rows represent interim analysis, first col is No Go, second col is Go
#' @param ORR The assumed true ORR.
#'
#' @return Generates a matrix of probabilities representing each possible outcome at interim analysis.
#' The probabiltiy is the probability of reaching that outcome given that all previous interims were between the decision values provided in R.
#' @export
#' @import tidyr
#' @import dplyr
#' @import stats
#'
#' @examples
Intr_func <- function(M,R,ORR){
  Sizes <- unique(M)
  N <- sum(M)
  probs <- lapply(Sizes,function(n) dbinom(0:n,n,ORR))

  MAT <- matrix(0,nrow=N+1,ncol=length(M))

  MAT[1:(M[1]+1),1] <- probs[[which(Sizes==M[1])]]

  for(i in 1:(ncol(MAT)-1)){
    for(j in (R[i,1]+1):(R[i,2]+1)){
      MAT[j:(j+M[i+1]),i+1] <- MAT[j:(j+M[i+1]),i+1] +MAT[j,i]*probs[[which(Sizes==M[i+1])]]
    }
  }

  return(MAT)
}
lylyf1987/GNGpkg documentation built on May 19, 2020, 12:07 a.m.