-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSYBR_optimal_thresholds.R
33 lines (27 loc) · 1.07 KB
/
SYBR_optimal_thresholds.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
##################################################################################################
### Script uses the SYBR model to calculate optimal class assignment thresholds
### for a range of false negative to false positive cost ratios
##################################################################################################
library(caret)
load("SYBR_trained_model.RData")
thresh <-
thresholder(trainmodel_sybr, threshold = seq(0, 1, by = 0.01))
colnames(thresh)[5] <- "PPV"
colnames(thresh)[6] <- "NPV"
thresh$PPV[is.nan(thresh$PPV)] <- 1
thresh$FNrate <- 1 - thresh$NPV
thresh$FPrate <- 1 - thresh$PPV
cost <- function(FNrate, FPrate, ratio) {
print(FNrate * ratio + FPrate * 1)
}
min_cost <- function(FNrate, FPrate, ratio) {
print(which(cost(thresh$FNrate, thresh$FPrate, ratio) ==
min(
cost(thresh$FNrate, thresh$FPrate, ratio)
)) / 100)
}
opt_threshold <- c()
for (i in 1:100) {
opt_threshold[i] <- min_cost(thresh$FNrate, thresh$FPrate, i)
}
save(opt_threshold, file = "SYBR_optimal_thresholds_OG.RData")