R/Discord_Go.R

Defines functions Discord_Go

Documented in Discord_Go

#' Title
#'
#' @param go the minimum interim go value
#' @param n the interim sample size
#' @param fgo the final minimum go criteria
#' @param N the final sample size
#' @param prob the true sucess rate
#' @param Weights the probability of each outcome from go:n. If NA, assumes the binomial distribution.
#'
#' @return the probability of a non-concordant go decision given that a go has been oberved at the interim. 
#' The probability of Go depnds on the exact value oberved at the interim, which is unknown. 
#' To solve this, we use a weighting factor which represents the probability of each individual outcome, however
#' this may not be particularly informative.
#' @export
#' @import tidyr
#' @import dplyr
#' @import stats
#'
#' @examples
Discord_Go <- function(go,n,fgo,N,prob,Weights=NA){
  if(n==N | is.infinite(go)){
    return(0)
  }
  
  if(any(is.na(Weights))){
    Weights = dbinom(go:n,n,prob)
    Weights = Weights/sum(Weights)
    warning('NAs in Weights. Weights calculated.')
  }else{
    if(length(Weights)!=n-go+1){
      stop('Weights must be NA or have length n-go+1')
    }
  }
  
  Prob = Weights *(1-pbinom(fgo-go:n-1,N-n,prob))
  
  return(1-sum(Prob))
}
lylyf1987/GNGpkg documentation built on May 19, 2020, 12:07 a.m.