R/Discord_Grey.R

Defines functions Discord_Grey

Documented in Discord_Grey

#' Title
#'
#' @param low the lower limit which the interim is still grey
#' @param up the upper limit for which the interim is grey
#' @param n sample size at interim
#' @param fgo final go threshold
#' @param fnogo final no go threshold
#' @param N final sample size
#' @param prob true probability
#' @param Weights probability for each possible interim grey value.
#'
#' @return the probability of a non-concordant grey decision given that a consider has been oberved at the interim. 
#' The probability of consider 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_Grey <- function(low,up,n,fgo,fnogo,N,prob,Weights=NA){
  if(n==N){
    return(0)
  }
  if(is.infinite(low)){
    low <- 0
  }
  if(is.infinite(up)){
    up <- n
  }
  
  if(any(is.na(Weights))){
    Weights = dbinom(low:up,n,prob)
    Weights = Weights/sum(Weights)
    warning('NAs present in Weights. Weights calculated.')
  }else{
    if(length(Weights)!=up-low+1){
      stop('Weights must be NA or have length up-low+1')
    }
  }
  # browser()
  
  Prob = Weights *(pbinom(fnogo-low:up,N-n,prob)+1-pbinom(fgo-low:up-1,N-n,prob))
  
  return(sum(Prob))
}
lylyf1987/GNGpkg documentation built on May 19, 2020, 12:07 a.m.