Skip to content

Instantly share code, notes, and snippets.

@Zepeng-Mu
Created May 4, 2022 15:34
Show Gist options
  • Save Zepeng-Mu/ccc9a42859a2f5edfa5e9e4e34d74946 to your computer and use it in GitHub Desktop.
Save Zepeng-Mu/ccc9a42859a2f5edfa5e9e4e34d74946 to your computer and use it in GitHub Desktop.
Calculate FDR using test statistics and null statistics, similar to `empPvals()` from qvalue package
getFDR <- function(Stat, Stat0) {
m <- length(Stat)
n <- length(Stat0)
v <- c(rep(T, m), rep(F, n))
v <- v[order(c(Stat, Stat0), decreasing = T)]
vSumT <- (m - cumsum(v == T)[v == T] + 1) / m
vSumF <- (n - cumsum(v == F)[v == T]) / n
fdr <- cummin(pmin(1, vSumF / vSumT))
fdr <- fdr[rank(-Stat)]
return(fdr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment