R/rocStats.R

Defines functions rocStats

Documented in rocStats

rocStats <-
function(outputs, groundTruthLabels, decreasing = TRUE) {

## ROCSTATS Make ROC curve data.
## FORMAT
## DESC Computes the points on an ROC curve by varying a threshold on the
## sorted outputs of the method in question.
## ARG outputs : The outputs of the evaluated method (eg. likelihoods).
## ARG groundTruthLabels: Binary vector than contains the ground truth.
## ARG decreasing : (LOGICAL) Outputs are sorted by decreazing or increazing order.
## RETURN stats : List that containts the necessary statistics to generate
## the ROC curve and other curves such as precision-recall.
##
## USAGE : rocStats(outputs, groundTruthLabels, descreasing=TRUE)
##
## COPYRIGHT : Alfredo Kalaitzis, 2010, 2011
##
## GPREGE

index <- sort(outputs, decreasing=decreasing, index.return=TRUE)$ix
sLabels <- groundTruthLabels[index] ## Sorted ground truth labels.
P <- sum(sLabels) ## Total positives.
N <- sum(!sLabels) ## Total negatives.

TP <- cumsum(sLabels) ## Want this to increase fast as we progress through the ranks.
FP <- cumsum(!sLabels) ## Want this to stay as low as possible as we progress through the ranks.
TN <- N-FP
FN <- P-TP

stats <- list()
stats$FDR = FP/(FP+TP)
stats$FNR = FN/(FN+TP)
stats$Precision = TP/(TP+FP)
stats$Recall = TP/(TP+FN)
stats$TPR = stats$Recall
stats$FPR = FP/(FP+TN)
stats$TP = TP
stats$FP = FP

return(stats)
}

Try the gprege package in your browser

Any scripts or data that you put into this service are public.

gprege documentation built on Nov. 8, 2020, 7:48 p.m.