Closed alevax closed 1 year ago
combine_nes <- function(D.nes, U.nes, COV.nes) { NES.pos <- (D.nes + U.nes) / sqrt(2 + 2COV.nes) NES.neg <- (D.nes - U.nes) / sqrt(2 - 2COV.nes)
p.pos <- pnorm(NES.pos, lower.tail = FALSE, log.p = TRUE) p.neg <- pnorm(NES.neg, lower.tail = TRUE, log.p = TRUE)
p.dif <- (p.pos < p.neg) min.p <- (p.pos p.dif + p.neg (!p.dif)) final.p <- min.p + log(2) + log1p(exp(min.p) / (-2))
pos.nes <- qnorm(final.p - log(2), lower.tail = FALSE, log.p = TRUE) neg.nes <- qnorm(final.p - log(2), lower.tail = TRUE, log.p = TRUE) NES.mat <- (pos.nes p.dif + neg.nes (!p.dif))
Resolved by commit 00b5f4c that took log_normalize code of R's qnorm in Python written by zl3263 and rewrote it to be a fast vectorized NumPy-based version
combine_nes <- function(D.nes, U.nes, COV.nes) { NES.pos <- (D.nes + U.nes) / sqrt(2 + 2COV.nes) NES.neg <- (D.nes - U.nes) / sqrt(2 - 2COV.nes)
calculate p values
p.pos <- pnorm(NES.pos, lower.tail = FALSE, log.p = TRUE) p.neg <- pnorm(NES.neg, lower.tail = TRUE, log.p = TRUE)
combine p values
p.dif <- (p.pos < p.neg) min.p <- (p.pos p.dif + p.neg (!p.dif)) final.p <- min.p + log(2) + log1p(exp(min.p) / (-2))
calculate final nes
pos.nes <- qnorm(final.p - log(2), lower.tail = FALSE, log.p = TRUE) neg.nes <- qnorm(final.p - log(2), lower.tail = TRUE, log.p = TRUE) NES.mat <- (pos.nes p.dif + neg.nes (!p.dif))