#' @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]
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.