Last active
February 9, 2018 10:05
-
-
Save n8thangreen/c27751991bc14d33dcb5868a729eb798 to your computer and use it in GitHub Desktop.
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
library(Rfast) | |
library(utils) | |
prob_test_outcome_combination <- function(prob, | |
n_choose) { | |
p_comb <- combn(x = prob, m = n_choose) | |
n_comb <- combn(x = 1 - prob, m = length(prob) - n_choose) | |
p_probs <- colprods(p_comb) | |
n_probs <- colprods(n_comb) | |
return(p_probs %*% rev(n_probs)) | |
} | |
net_sensspec <- function(pos_threshold, | |
sens, | |
spec) { | |
if (length(sens) != length(spec)) | |
stop("Length of sens and spec must be the same.") | |
N <- length(sens) | |
net_sens <- net_spec <- 0 | |
for (j in seq(0, N)) { | |
if (j >= pos_threshold) { | |
net_sens <- net_sens + prob_test_outcome_combination(sens, j) | |
} | |
if (j > N - pos_threshold) { | |
net_spec <- net_spec + prob_test_outcome_combination(spec, j) | |
} | |
} | |
list(net_sens = net_sens, | |
net_spec = net_spec) | |
} | |
net_sensspec(pos_threshold = 2, | |
sens = c(0.1,0.2,0.3,0.4), | |
spec = c(0.1,0.2,0.3,0.4)) | |
net_sensspec(pos_threshold = 2, | |
sens = c(0.1,0.2,0.3), | |
spec = c(0.1,0.2,0.3)) | |
net_sensspec(pos_threshold = 2, | |
sens = c(0.1,0.2), | |
spec = c(0.1,0.2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment