From efca61ec3d84f2b276e3d508546fa263676e6a1d Mon Sep 17 00:00:00 2001 From: suzannejin Date: Tue, 10 Sep 2024 16:54:21 +0200 Subject: [PATCH 1/4] change tails argument to have 'right' and 'both' --- R/3-shared-getAdjacency.R | 48 ++++++++-------- R/3-shared-getCutoff.R | 4 +- R/3-shared-getResults.R | 34 +++++------- R/3-shared-updateCutoffs.R | 55 +++++++++++-------- .../testthat/test-SHARED-getAdjacency-propr.R | 16 ++++-- tests/testthat/test-SHARED-getCutoff-propr.R | 2 +- tests/testthat/test-SHARED-getResults-propr.R | 4 +- .../test-SHARED-updateCutoffs-propr.R | 20 +++++-- 8 files changed, 102 insertions(+), 81 deletions(-) diff --git a/R/3-shared-getAdjacency.R b/R/3-shared-getAdjacency.R index edd01a6..7d3dbbb 100644 --- a/R/3-shared-getAdjacency.R +++ b/R/3-shared-getAdjacency.R @@ -1,18 +1,25 @@ -#' Get Adjacency Matrix as indicated by permutation tests +#' Get Adjacency Matrix as indicated by permutation tests. +#' +#' This function gets the significant pairs according to the permutation tests. Then it fills +#' the adjacency matrix with 1 if pair is significant, otherwise 0. The significance is determined +#' by the cutoff value for which the false discovery rate (FDR) is less or equal than the given +#' value 'fdr'. The significant pairs are those that have a value greater/less or equal than the +#' cutoff, depending on the metric. #' -#' This function gets the significant pairs, according to the permutation tests. -#' Then it fills the adjacency matrix with 1 if pair is significant, otherwise 0. #' @param object A \code{propd} or \code{propr} object. #' @param fdr A float value for the false discovery rate. Default is 0.05. #' @param window_size An integer. Default is 1. When it is greater than 1, the FDR #' values would be smoothed out by a moving average of the given window size. -#' @param tails 1 for one-sided on the right, and 2 for two-sided. When NULL, use default -#' test for the given metric. This is only relevant for \code{propr} objects. +#' @param tails 'right' or 'both'. 'right' is for one-sided on the right. 'both' is to +#' combine one-sided on the right (positive values) and left (negative values). This is only +#' relevant for \code{propr} objects, as \code{propd} objects are always one-sided and only +#' have positive values. #' @return An adjacency matrix. #' #' @export -getAdjacencyFDR <- function(object, fdr = 0.05, window_size = 1, tails = NULL) { - +getAdjacencyFDR <- + function(object, fdr = 0.05, window_size = 1, tails = c('right', 'both')) { + if (inherits(object, "propr")){ adj <- getAdjacencyFDR.propr(object, fdr=fdr, window_size=window_size, tails=tails) @@ -60,23 +67,18 @@ getAdjacencyFDR.propd <- #' pairs from a \code{propd} object. #' @export getAdjacencyFDR.propr <- - function(object, fdr = 0.05, window_size = 1, tails = NULL) { + function(object, fdr = 0.05, window_size = 1, tails = c('right', 'both')) { - if (is.null(tails)) { - tails <- ifelse(object@has_meaningful_negative_values, 2, 1) - } - if (tails != 1 & tails != 2) { - stop("Please provide a valid value for tails: 1 or 2.") - } - if (tails == 1 & object@has_meaningful_negative_values) { - warning("Significant pairs are chosen based on one-sided FDR test.") - } - if (tails == 2 & !object@direct) { - stop("Two-sided FDR is not available for this metric.") + # handle tails argument + tails <- match.arg(tails) + if (tails == 'both' & !object@direct) { + warning("Running tails='right' instead") + tails <- 'right' # set to right, when non negative values can be expected for a given metric. } - # correct fdr when two-sided - if (tails == 2) fdr <- fdr / 2 + # correct fdr when considering both tails + # so that the total fdr is the given value + if (tails == 'both') fdr <- fdr / 2 # create empty matrix adj <- matrix(0, nrow = ncol(object@matrix), ncol = ncol(object@matrix)) @@ -90,12 +92,12 @@ getAdjacencyFDR.propr <- if (object@direct) { adj[object@matrix >= 0 & object@matrix >= cutoff] <- 1 } else { - adj[object@matrix <= cutoff] <- 1 + adj[object@matrix <= cutoff] <- 1 # don't have negative values } } # for negative tail - if (tails == 2){ + if (tails == 'both'){ cutoff <- getCutoffFDR(object, fdr=fdr, window_size=window_size, positive=F) if (cutoff) adj[object@matrix < 0 & object@matrix <= cutoff] <- 1 } diff --git a/R/3-shared-getCutoff.R b/R/3-shared-getCutoff.R index c8cd691..cd3dffd 100644 --- a/R/3-shared-getCutoff.R +++ b/R/3-shared-getCutoff.R @@ -61,7 +61,7 @@ getCutoffFDR.propr <- function(object, fdr = 0.05, window_size = 1, positive = T # get index of FDR values below the threshold index <- (df$FDR <= fdr) & (is.finite(df$FDR)) if (!any(index)) { - warning("No significant cutoff found for the given FDR, when positive = ", positive) + warning("No significant cutoff found for the given FDR, when positive tail = ", positive) return(FALSE) } @@ -130,7 +130,7 @@ getCutoffFstat <- function(object, pval = 0.05, fdr_adjusted = FALSE) { if (fdr_adjusted) { message("Alert: Returning an empiric cutoff based on the $FDR slot.") - index <- (object@results$FDR < pval) & (is.finite(object@results$FDR)) + index <- (object@results$FDR <= pval) & (is.finite(object@results$FDR)) if (any(index)) { cutoff <- max(object@results$theta[index]) } else{ diff --git a/R/3-shared-getResults.R b/R/3-shared-getResults.R index 24cf451..508258d 100644 --- a/R/3-shared-getResults.R +++ b/R/3-shared-getResults.R @@ -19,16 +19,17 @@ getResults <- #' Get Significant Results from Object based on the permutation tests. #' -#' This function provides a unified wrapper to retrieve results -#' from a \code{propr} or \code{propd} object keeping only the -#' statistically significant pairs. +#' This function retrieves results from a \code{propr} or \code{propd} object keeping only the +#' statistically significant pairs. The significance is determined by the cutoff value for which +#' the false discovery rate (FDR) is less or equal than the given value 'fdr'. The significant +#' pairs are those that have a value greater/less or equal than the cutoff, depending on the metric. #' #' @inheritParams getAdjacencyFDR #' @return A \code{data.frame} of results. #' #' @export getSignificantResultsFDR <- - function(object, fdr = 0.05, window_size = 1, tails = NULL) { + function(object, fdr = 0.05, window_size = 1, tails = c('right', 'both')) { if (inherits(object, "propr")) { results <- getSignificantResultsFDR.propr(object, fdr=fdr, window_size=window_size, tails=tails) @@ -68,19 +69,13 @@ getSignificantResultsFDR.propd <- #' only the statistically significant pairs. #' @export getSignificantResultsFDR.propr <- - function(object, fdr = 0.05, window_size = 1, tails = NULL) { + function(object, fdr = 0.05, window_size = 1, tails = c('right', 'both')) { - if (is.null(tails)) { - tails <- ifelse(object@has_meaningful_negative_values, 2, 1) - } - if (tails != 1 & tails != 2) { - stop("Please provide a valid value for tails: 1 or 2.") - } - if (tails == 1 & object@has_meaningful_negative_values) { - warning("Significant pairs are chosen based on one-sided FDR test.") - } - if (tails == 2 & !object@direct) { - stop("Two-sided FDR is not available for this metric.") + # handle tails argument + tails <- match.arg(tails) + if (tails == 'both' & !object@direct) { + warning("Running tails='right' instead") + tails <- 'right' # set to right, when non negative values can be expected for a given metric. } # function to subset the results data frame based on the cutoff @@ -93,8 +88,9 @@ getSignificantResultsFDR.propr <- } } - # correct fdr when two-sided - if (tails == 2) fdr <- fdr / 2 + # correct fdr when considering both tails + # so that the total fdr is the given value + if (tails == 'both') fdr <- fdr / 2 # define results data frame df <- getResults(object) @@ -107,7 +103,7 @@ getSignificantResultsFDR.propr <- results <- rbind(results, subsetBeyondCutoff(part, cutoff)) # get the significant negative values - if (tails == 2) { + if (tails == 'both') { cutoff <- getCutoffFDR(object, fdr=fdr, window_size=window_size, positive=F) part <- df[which(df$propr < 0),] results <- rbind(results, subsetBeyondCutoff(part, cutoff)) diff --git a/R/3-shared-updateCutoffs.R b/R/3-shared-updateCutoffs.R index e6520f4..3845ea2 100644 --- a/R/3-shared-updateCutoffs.R +++ b/R/3-shared-updateCutoffs.R @@ -1,50 +1,58 @@ #' Update FDR by Permutation #' -#' This function updates FDR for a set of cutoffs. -#' -#' This function wraps \code{updateCutoffs.propr} and -#' \code{updateCutoffs.propd}. +#' This function updates the FDR for each cutoff. By default, the set of cutoffs are determined +#' based on the quantile of the data, so that the cutoffs are evenly spaced across the data. +#' The FDR is calculated as the ratio between the number of permuted values beyond the cutoff +#' and the number of true values beyond the the cutoff. +#' When tails is set to 'right', the FDR is calculated only on the positive side of the data. +#' When tails is set to 'both', the FDR is calculated on both sides of the data. #' #' @param object A \code{propr} or \code{propd} object. -#' @param number_of_cutoffs An integer. The number of cutoffs to test. -#' Given this number, the cutoffs will be determined based on the quantile of the data. -#' In this way, the cutoffs will be evenly spaced across the data. -#' @param custom_cutoffs A numeric vector. When provided, this vector is used -#' as the FDR cutoffs to test, and number_of_cutoffs is ignored. -#' @param tails 1 for one-sided on the right, and 2 for two-sided. When two-sided, -#' the FDR is calculated for both positive and negative values. When NULL, use default -#' option for the given metric. This is only relevant for \code{propr} objects. +#' @param number_of_cutoffs An integer. The number of cutoffs to test. Given this number, +#' the cutoffs will be determined based on the quantile of the data. In this way, the +#' cutoffs will be evenly spaced across the data. +#' @param custom_cutoffs A numeric vector. When provided, this vector is used as the set of +#' cutoffs to test, and 'number_of_cutoffs' is ignored. +#' @param tails 'right' or 'both'. 'right' is for one-sided on the right. 'both' is to +#' combine one-sided on the right (positive values) and left (negative values). This +#' is only relevant for \code{propr} objects, as \code{propd} objects are always one-sided +#' and only have positive values. #' @param ncores An integer. The number of parallel cores to use. #' @return A \code{propr} or \code{propd} object with the FDR slot updated. +#' #' @export updateCutoffs <- function(object, number_of_cutoffs = 100, custom_cutoffs = NULL, - tails = NULL, + tails = c('right','both'), ncores = 1) { + tails <- match.arg(tails) - if (!is.null(tails)){ - if (tails != 1 & tails != 2) stop("Tails only accept values 1 or 2, if not NULL.") - } - - get_cutoffs <- function(values, number_of_cutoffs, custom_cutoffs, tails=1) { + # function to get the set of cutoffs + get_cutoffs <- function(values, number_of_cutoffs, custom_cutoffs, tails='right') { if (!is.null(custom_cutoffs)) return(custom_cutoffs) - if (tails == 1) values <- values[values >= 0] + if (tails == 'right') { + values <- values[values >= 0] + if (length(values) == 0) stop("No positive values found.") + } return(as.numeric(quantile(values, probs = seq(0, 1, length.out = number_of_cutoffs)))) } + # update FDR values for propr object if (inherits(object, "propr")) { - if (is.null(tails)) tails <- ifelse(object@has_meaningful_negative_values, 2, 1) - if (tails == 1 & object@has_meaningful_negative_values) warning("One-sided FDR test is performed.") - if (tails == 2 & !object@direct) stop("Two-sided FDR is not available for this metric.") + if (tails == 'both' & !object@direct) { + warning("Running tails='right' instead") + tails <- 'right' # set to right, when non negative values can be expected for a given metric. + } values <- object@results$propr cutoffs <- get_cutoffs(values, number_of_cutoffs, custom_cutoffs, tails) updateCutoffs.propr(object, cutoffs, ncores) + # update FDR values for propd object } else if (inherits(object, "propd")) { values <- object@results$theta - cutoffs <- get_cutoffs(values, number_of_cutoffs, custom_cutoffs, tails=1) + cutoffs <- get_cutoffs(values, number_of_cutoffs, custom_cutoffs, tails='right') updateCutoffs.propd(object, cutoffs, ncores) } else{ @@ -64,7 +72,6 @@ updateCutoffs <- #' @export updateCutoffs.propr <- function(object, cutoffs, ncores) { - if (identical(object@permutes, list(NULL))) { stop("Permutation testing is disabled.") } diff --git a/tests/testthat/test-SHARED-getAdjacency-propr.R b/tests/testthat/test-SHARED-getAdjacency-propr.R index 4bd2d7d..cbed867 100644 --- a/tests/testthat/test-SHARED-getAdjacency-propr.R +++ b/tests/testthat/test-SHARED-getAdjacency-propr.R @@ -16,10 +16,10 @@ test_that("getAdjacencyFDR returns the expected values for pcor.bshrink - clr", # get propr object pr <- propr(X, metric = "pcor.bshrink", ivar='clr', p=10) - pr <- updateCutoffs(pr, number_of_cutoffs=100) + pr <- updateCutoffs(pr, number_of_cutoffs=100, tails='both') # get adjacency matrix - adj <- getAdjacencyFDR(pr) + adj <- getAdjacencyFDR(pr, tails='both') # get expected adjacency matrix adj_expected <- matrix(0, nrow = ncol(X), ncol = ncol(X)) @@ -36,10 +36,10 @@ test_that("getAdjacencyFDR returns the expected values for pcor.bshrink - alr", # get propr object pr <- propr(X, metric = "pcor.bshrink", ivar='alr', p=10) - pr <- updateCutoffs(pr, number_of_cutoffs=100) + pr <- updateCutoffs(pr, number_of_cutoffs=100, tails='both') # get adjacency matrix - adj <- getAdjacencyFDR(pr) + adj <- getAdjacencyFDR(pr, tails='both') # get expected adjacency matrix adj_expected <- matrix(0, nrow = ncol(X), ncol = ncol(X)) @@ -139,6 +139,14 @@ test_that("getAdjacencyFDR and getSignificantResultsFDR return coherent results" # get propr object pr <- propr(X, metric=metric, p=10) + + # expect error for pcor.shrink, since it does not produce positive values in this case + if (metric == 'pcor.shrink'){ + expect_error(updateCutoffs(pr)) + next + } + + # update FDR values pr <- updateCutoffs(pr, number_of_cutoffs=100) # get adjacency matrix diff --git a/tests/testthat/test-SHARED-getCutoff-propr.R b/tests/testthat/test-SHARED-getCutoff-propr.R index 03a348c..b2188cd 100644 --- a/tests/testthat/test-SHARED-getCutoff-propr.R +++ b/tests/testthat/test-SHARED-getCutoff-propr.R @@ -16,7 +16,7 @@ test_that("test that getCutoff gets the correct cutoff", { # get propr object and update cutoffs set.seed(0) pr <- propr(X, metric = "pcor.bshrink", p=10) - pr <- updateCutoffs(pr, number_of_cutoffs=10) + pr <- updateCutoffs(pr, number_of_cutoffs=10, tails='both') # check cutoff is correct for positive values cutoff <- getCutoffFDR(pr, fdr = 0.05, window_size = 1, positive = TRUE) diff --git a/tests/testthat/test-SHARED-getResults-propr.R b/tests/testthat/test-SHARED-getResults-propr.R index f4b5992..019b813 100644 --- a/tests/testthat/test-SHARED-getResults-propr.R +++ b/tests/testthat/test-SHARED-getResults-propr.R @@ -38,7 +38,7 @@ test_that("test that getSignificantResultsFDR works as expected", { # get propr object pr <- propr(X, metric = "pcor.bshrink", p=10) - pr <- updateCutoffs(pr, number_of_cutoffs=10) + pr <- updateCutoffs(pr, number_of_cutoffs=10, tails='both') # get expected results cutoff_positive <- getCutoffFDR(pr, fdr = 0.05, window_size = 1, positive = TRUE) @@ -47,7 +47,7 @@ test_that("test that getSignificantResultsFDR works as expected", { expected_negative <- pr@results$propr[which(pr@results$propr <= cutoff_negative)] # get significant results - results <- getSignificantResultsFDR(pr, fdr = 0.05) + results <- getSignificantResultsFDR(pr, fdr = 0.05, tails='both') # check that the values are correct expect_equal(results$propr[results$propr>=0], expected_positive) diff --git a/tests/testthat/test-SHARED-updateCutoffs-propr.R b/tests/testthat/test-SHARED-updateCutoffs-propr.R index f6155b1..0232895 100644 --- a/tests/testthat/test-SHARED-updateCutoffs-propr.R +++ b/tests/testthat/test-SHARED-updateCutoffs-propr.R @@ -13,22 +13,30 @@ X <- data.frame(a, b, c, d, e) test_that("updateCutoffs.propr properly set up cutoffs", { - # get propr object and update cutoffs + # get propr object pr <- propr(X, metric = "pcor.bshrink", p=10) - pr <- updateCutoffs(pr, number_of_cutoffs=10) # get cutoffs - cutoffs <- as.numeric( quantile(pr@matrix[lower.tri(pr@matrix)], probs = seq(0, 1, length.out = 10)) ) + values <- pr@matrix[lower.tri(pr@matrix)] + cutoffs_right <- as.numeric( quantile(values[values >= 0], probs = seq(0, 1, length.out = 10)) ) + cutoffs_both <- as.numeric( quantile(values, probs = seq(0, 1, length.out = 10)) ) # check that cutoffs are properly defined - expect_equal(pr@fdr$cutoff, cutoffs) + expect_equal( + updateCutoffs(pr, number_of_cutoffs=10)@fdr$cutoff, + cutoffs_right + ) + expect_equal( + updateCutoffs(pr, number_of_cutoffs=10, tails="both")@fdr$cutoff, + cutoffs_both + ) }) test_that("updateCutoffs.propr properly calculates truecounts", { # get propr object and update cutoffs pr <- propr(X, metric = "pcor.bshrink", p=10) - pr <- updateCutoffs(pr, number_of_cutoffs=10) + pr <- updateCutoffs(pr, number_of_cutoffs=10, tails='both') # get truecounts truecounts1 <- sapply( @@ -52,7 +60,7 @@ test_that("updateCutoffs.propr properly calculates randcounts", { # get propr object and update cutoffs set.seed(0) pr <- propr(X, metric = "pcor.bshrink", p=10) - pr <- updateCutoffs(pr, number_of_cutoffs=10) + pr <- updateCutoffs(pr, number_of_cutoffs=10, tails='both') # get permuted values randcounts <- rep(0, 10) From 0a5efc445b45f604719037c8f3bd7041f9b4d584 Mon Sep 17 00:00:00 2001 From: suzannejin Date: Tue, 10 Sep 2024 16:58:38 +0200 Subject: [PATCH 2/4] update documentation --- man/getAdjacencyFDR.Rd | 29 ++++++++++++++++++++++------- man/getSignificantResultsFDR.Rd | 22 +++++++++++++++------- man/updateCutoffs.Rd | 30 ++++++++++++++++-------------- 3 files changed, 53 insertions(+), 28 deletions(-) diff --git a/man/getAdjacencyFDR.Rd b/man/getAdjacencyFDR.Rd index 8ecbf01..ff3773f 100644 --- a/man/getAdjacencyFDR.Rd +++ b/man/getAdjacencyFDR.Rd @@ -4,13 +4,23 @@ \alias{getAdjacencyFDR} \alias{getAdjacencyFDR.propd} \alias{getAdjacencyFDR.propr} -\title{Get Adjacency Matrix as indicated by permutation tests} +\title{Get Adjacency Matrix as indicated by permutation tests.} \usage{ -getAdjacencyFDR(object, fdr = 0.05, window_size = 1, tails = NULL) +getAdjacencyFDR( + object, + fdr = 0.05, + window_size = 1, + tails = c("right", "both") +) getAdjacencyFDR.propd(object, fdr = 0.05, window_size = 1) -getAdjacencyFDR.propr(object, fdr = 0.05, window_size = 1, tails = NULL) +getAdjacencyFDR.propr( + object, + fdr = 0.05, + window_size = 1, + tails = c("right", "both") +) } \arguments{ \item{object}{A \code{propd} or \code{propr} object.} @@ -20,15 +30,20 @@ getAdjacencyFDR.propr(object, fdr = 0.05, window_size = 1, tails = NULL) \item{window_size}{An integer. Default is 1. When it is greater than 1, the FDR values would be smoothed out by a moving average of the given window size.} -\item{tails}{1 for one-sided on the right, and 2 for two-sided. When NULL, use default -test for the given metric. This is only relevant for \code{propr} objects.} +\item{tails}{'right' or 'both'. 'right' is for one-sided on the right. 'both' is to +combine one-sided on the right (positive values) and left (negative values). This is only +relevant for \code{propr} objects, as \code{propd} objects are always one-sided and only +have positive values.} } \value{ An adjacency matrix. } \description{ -This function gets the significant pairs, according to the permutation tests. -Then it fills the adjacency matrix with 1 if pair is significant, otherwise 0. +This function gets the significant pairs according to the permutation tests. Then it fills +the adjacency matrix with 1 if pair is significant, otherwise 0. The significance is determined +by the cutoff value for which the false discovery rate (FDR) is less or equal than the given +value 'fdr'. The significant pairs are those that have a value greater/less or equal than the +cutoff, depending on the metric. } \section{Methods}{ diff --git a/man/getSignificantResultsFDR.Rd b/man/getSignificantResultsFDR.Rd index 27c7183..459bd97 100644 --- a/man/getSignificantResultsFDR.Rd +++ b/man/getSignificantResultsFDR.Rd @@ -6,7 +6,12 @@ \alias{getSignificantResultsFDR.propr} \title{Get Significant Results from Object based on the permutation tests.} \usage{ -getSignificantResultsFDR(object, fdr = 0.05, window_size = 1, tails = NULL) +getSignificantResultsFDR( + object, + fdr = 0.05, + window_size = 1, + tails = c("right", "both") +) getSignificantResultsFDR.propd(object, fdr = 0.05, window_size = 1) @@ -14,7 +19,7 @@ getSignificantResultsFDR.propr( object, fdr = 0.05, window_size = 1, - tails = NULL + tails = c("right", "both") ) } \arguments{ @@ -25,16 +30,19 @@ getSignificantResultsFDR.propr( \item{window_size}{An integer. Default is 1. When it is greater than 1, the FDR values would be smoothed out by a moving average of the given window size.} -\item{tails}{1 for one-sided on the right, and 2 for two-sided. When NULL, use default -test for the given metric. This is only relevant for \code{propr} objects.} +\item{tails}{'right' or 'both'. 'right' is for one-sided on the right. 'both' is to +combine one-sided on the right (positive values) and left (negative values). This is only +relevant for \code{propr} objects, as \code{propd} objects are always one-sided and only +have positive values.} } \value{ A \code{data.frame} of results. } \description{ -This function provides a unified wrapper to retrieve results - from a \code{propr} or \code{propd} object keeping only the - statistically significant pairs. +This function retrieves results from a \code{propr} or \code{propd} object keeping only the +statistically significant pairs. The significance is determined by the cutoff value for which +the false discovery rate (FDR) is less or equal than the given value 'fdr'. The significant +pairs are those that have a value greater/less or equal than the cutoff, depending on the metric. } \section{Methods}{ diff --git a/man/updateCutoffs.Rd b/man/updateCutoffs.Rd index 13b119b..b524e08 100644 --- a/man/updateCutoffs.Rd +++ b/man/updateCutoffs.Rd @@ -10,7 +10,7 @@ updateCutoffs( object, number_of_cutoffs = 100, custom_cutoffs = NULL, - tails = NULL, + tails = c("right", "both"), ncores = 1 ) @@ -21,16 +21,17 @@ updateCutoffs.propd(object, cutoffs, ncores) \arguments{ \item{object}{A \code{propr} or \code{propd} object.} -\item{number_of_cutoffs}{An integer. The number of cutoffs to test. -Given this number, the cutoffs will be determined based on the quantile of the data. -In this way, the cutoffs will be evenly spaced across the data.} +\item{number_of_cutoffs}{An integer. The number of cutoffs to test. Given this number, +the cutoffs will be determined based on the quantile of the data. In this way, the +cutoffs will be evenly spaced across the data.} -\item{custom_cutoffs}{A numeric vector. When provided, this vector is used -as the FDR cutoffs to test, and number_of_cutoffs is ignored.} +\item{custom_cutoffs}{A numeric vector. When provided, this vector is used as the set of +cutoffs to test, and 'number_of_cutoffs' is ignored.} -\item{tails}{1 for one-sided on the right, and 2 for two-sided. When two-sided, -the FDR is calculated for both positive and negative values. When NULL, use default -option for the given metric. This is only relevant for \code{propr} objects.} +\item{tails}{'right' or 'both'. 'right' is for one-sided on the right. 'both' is to +combine one-sided on the right (positive values) and left (negative values). This +is only relevant for \code{propr} objects, as \code{propd} objects are always one-sided +and only have positive values.} \item{ncores}{An integer. The number of parallel cores to use.} } @@ -38,11 +39,12 @@ option for the given metric. This is only relevant for \code{propr} objects.} A \code{propr} or \code{propd} object with the FDR slot updated. } \description{ -This function updates FDR for a set of cutoffs. -} -\details{ -This function wraps \code{updateCutoffs.propr} and - \code{updateCutoffs.propd}. +This function updates the FDR for each cutoff. By default, the set of cutoffs are determined +based on the quantile of the data, so that the cutoffs are evenly spaced across the data. +The FDR is calculated as the ratio between the number of permuted values beyond the cutoff +and the number of true values beyond the the cutoff. +When tails is set to 'right', the FDR is calculated only on the positive side of the data. +When tails is set to 'both', the FDR is calculated on both sides of the data. } \section{Methods}{ From 1c0366305f44a5ded0bb54dcbcf65d217f4bd6df Mon Sep 17 00:00:00 2001 From: suzannejin Date: Tue, 10 Sep 2024 17:00:44 +0200 Subject: [PATCH 3/4] update readme --- README.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.Rmd b/README.Rmd index 67637c6..61871cb 100755 --- a/README.Rmd +++ b/README.Rmd @@ -54,7 +54,7 @@ pr <- updateCutoffs( pr, number_of_cutoffs = 100, # number of cutoffs to estimate FDR custom_cutoffs = NULL, # or specify custom cutoffs - tails = 1, # 1 or 2-tailed test + tails = 'right', # consider only the positive values ('right') or both sides ('both') ncores = 4 # parallelize here ) ``` @@ -81,7 +81,7 @@ pr <- updateCutoffs( pr, number_of_cutoffs = 100, # number of cutoffs to estimate FDR custom_cutoffs = NULL, # or specify custom cutoffs - tails = 1, # 1 or 2-tailed test + tails = 'right', # consider only the positive values ('right') or both sides ('both') ncores = 4 # parallelize here ) ``` From c001a93bb244a9c40403dc5d48df824c40646885 Mon Sep 17 00:00:00 2001 From: Suzanne Jin Date: Tue, 10 Sep 2024 17:01:36 +0200 Subject: [PATCH 4/4] add readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b8d28a..85d4614 100755 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ pr <- updateCutoffs( pr, number_of_cutoffs = 100, # number of cutoffs to estimate FDR custom_cutoffs = NULL, # or specify custom cutoffs - tails = 1, # 1 or 2-tailed test + tails = 'right', # consider only the positive values ('right') or both sides ('both') ncores = 4 # parallelize here ) ``` @@ -131,7 +131,7 @@ pr <- updateCutoffs( pr, number_of_cutoffs = 100, # number of cutoffs to estimate FDR custom_cutoffs = NULL, # or specify custom cutoffs - tails = 1, # 1 or 2-tailed test + tails = 'right', # consider only the positive values ('right') or both sides ('both') ncores = 4 # parallelize here ) ```