Created
May 4, 2022 15:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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