From 606104ebe4e2eafaffaab1782c31f1f8821e2340 Mon Sep 17 00:00:00 2001 From: Edward Wallace Date: Fri, 4 Oct 2019 16:02:10 +0100 Subject: [PATCH 1/2] document truncated p-val issue This describes the problem with truncated p-values causing an error in qvalue, as raised repeatedly in https://github.com/StoreyLab/qvalue/issues/9 and https://support.bioconductor.org/p/105623/ Hopefully, describing the problem in the help file will make it easier for users to diagnose and fix. --- R/qvalue.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/qvalue.R b/R/qvalue.R index c258a18..7249b2f 100755 --- a/R/qvalue.R +++ b/R/qvalue.R @@ -13,7 +13,9 @@ #' will be utilized in the internal calls made in \code{\link{qvalue}}. See \url{http://genomine.org/papers/Storey_FDR_2011.pdf} #' for a brief introduction to FDRs and q-values. #' -#' @param p A vector of p-values (only necessary input). +#' @param p A vector of p-values (only necessary input). Note that qvalue expects that these values are uniformly distributed +#' on [0,1), and under default parameter values will throw an error. If your p-value distribution is truncated, qvalue will +#' run with the BH procedure by setting pi0 = 1. #' @param fdr.level A level at which to control the FDR. Must be in (0,1]. Optional; if this is #' selected, a vector of TRUE and FALSE is returned that specifies #' whether each q-value is less than fdr.level or not. From 5dc3561657871ba1e9334880d6d39c45394f7d99 Mon Sep 17 00:00:00 2001 From: Edward Wallace Date: Fri, 4 Oct 2019 16:04:39 +0100 Subject: [PATCH 2/2] Test for truncated p-values. --- R/qvalue.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/qvalue.R b/R/qvalue.R index 7249b2f..331cc32 100755 --- a/R/qvalue.R +++ b/R/qvalue.R @@ -96,6 +96,9 @@ qvalue <- function(p, fdr.level = NULL, pfdr = FALSE, lfdr.out = TRUE, pi0 = NUL } else if (!is.null(fdr.level) && (fdr.level <= 0 || fdr.level > 1)) { stop("'fdr.level' must be in (0, 1].") } + if ( max(p) < 0.5 && is.null(pi0) ) { + stop("p-values are truncated and pi0 not set. Try running BH procedure by setting pi0 = 1") + } # Calculate pi0 estimate if (is.null(pi0)) {