R/bh_fdr.R

Defines functions bh_fdr

Documented in bh_fdr

#' @title False Discovery Threshold
#'
#' @description Determines the critical p-value for statistical significance using the Benjamini-Hochberg false-discovery rate (FDR) procedure.
#'
#' NOTE: Significance is defined as P <= threshold, not <.
#'
#' @param pvals Vector of p-values.
#' @param fdr False-discovery rate.
#'
#' @return Vector of p-values, sorted.
#'
#' @export

bh_fdr <- function(pvals, fdr = 0.05) {
  lp <- length(pvals)
  p.threshold <- fdr * (1:lp) / lp
  p.sorted <- sort(pvals)
  pass.threshold <- p.sorted <= p.threshold
  pass.threshold.index <- max((1:lp)[pass.threshold])
  p.sorted[pass.threshold.index]
}
mattwarkentin/genetools documentation built on Nov. 4, 2019, 6:19 p.m.