|
@@ -58,3 +58,50 @@ psi10 <- function(x, s) {
|
|
|
v1 + 0.5 * v2
|
|
|
}
|
|
|
|
|
|
+#' Calculate AUC
|
|
|
+#' @param roc as returned by simple.roc
|
|
|
+#'
|
|
|
+#' @return AUC (numeric)
|
|
|
+#'
|
|
|
+#' @export
|
|
|
+simple.getAUC <- function(roc) {
|
|
|
+ V0 = roc[!roc$labels, 'V']
|
|
|
+ mean(V0)
|
|
|
+}
|
|
|
+
|
|
|
+#' Calculate metrics associated with ROC
|
|
|
+#'
|
|
|
+#' @param ROC roc as returned by simple.roc
|
|
|
+#'
|
|
|
+#' @return a list with elemnts: : FPR, TPR, threshold, FPR CI95:min , FPR CI95: max, TPR CI95:min, TPR CI95:max
|
|
|
+#' all evaluated at optimum point (Youden index)
|
|
|
+#'
|
|
|
+#' @export
|
|
|
+
|
|
|
+simple.compute_roc_metrics <- function(ROC) {
|
|
|
+
|
|
|
+#determine optimal point on ROC curve using Youden index
|
|
|
+#ROC is the output of simple.roc
|
|
|
+#output is a list : tpr, tpr CI95:min , tpr CI95: max, fpr, fpr CI95:min, fpr CI95:max, value of score,
|
|
|
+#all evaluated at optimum point,
|
|
|
+
|
|
|
+ n=base::sum(ROC$labels)
|
|
|
+ m=base::sum(!ROC$labels)
|
|
|
+ nt=base::length(ROC$TPR)
|
|
|
+ dist<-base::abs(ROC$TPR-ROC$FPR)
|
|
|
+ imax<-base::which.max(dist)
|
|
|
+ hTPR<-stats::prop.test(x=ROC$TPR[imax]*n,n=n,conf.level=0.95,correct=FALSE)
|
|
|
+ hFPR<-stats::prop.test(x=ROC$FPR[imax]*m,n=m,conf.level=0.95,correct=FALSE)
|
|
|
+
|
|
|
+
|
|
|
+ return(base::list(
|
|
|
+ FPR = ROC$FPR[imax],
|
|
|
+ TPR = ROC$TPR[imax],
|
|
|
+ threshold = ROC$scores[imax],
|
|
|
+ lFPR = hFPR$conf.int[1],
|
|
|
+ hFPR = hFPR$conf.int[2],
|
|
|
+ lTPR = hTPR$conf.int[1],
|
|
|
+ hTPR = hTPR$conf.int[2]
|
|
|
+ ))
|
|
|
+}
|
|
|
+
|