R/fisher_method.R

Defines functions fisher_method

Documented in fisher_method

#' Fisher method
#'
#' @param pval Vector of pvalues
#' @param threshold Lowerbound threshold of p-values
#' @param method Method ('default' or 'reversed')
#'
#' @return Fisher method results
#' @export

fisher_method <- function(pval,
                          threshold = 0,
                          method = 'default')
{  
  if ( method == 'default' ) {
    fish <- -2 * sum(log(pval))    
  } else if ( method == 'reversed' ) {
    fish <- -2 * sum(log(1 - ((pval[pval > threshold] - threshold) / (1 - threshold))))
  } else {
    stop('Invalid method. Please see ?ddfab::fisher_method')
  }

  df_fish <- sum(pval > threshold) * 2
  p_fish <- pchisq(q = fish, df = df_fish, lower.tail = FALSE)
  
  return(cbind(fish, df_fish, p_fish))
}
chartgerink/ddfab documentation built on Jan. 9, 2022, 8:22 a.m.