| FDRCalc | R Documentation |
Computes the False Discovery Rate (FDR) and True Positive Rate (TPR, a.k.a. recall)
by comparing a set of true labels to a set of predicted labels.
Labels are treated as positive integer indices in \{1, \dots, N\}. Duplicates
are ignored (unique indices are used).
FDRCalc(truelabel, predlabel, N)
truelabel |
Integer vector of ground-truth positive indices (values in |
predlabel |
Integer vector of predicted positive indices (values in |
N |
Integer scalar; size of the full index universe (total number of candidates). |
Let truelabel and predlabel be sets of indices. The function
derives the confusion-matrix counts:
tp = |truelabel \cap predlabel|
fp = |predlabel \setminus truelabel|
fn = |truelabel \setminus predlabel|
tn = N - tp - fp - fn
and returns
FDR = fp / (fp + tp), \qquad TPR = tp / (tp + fn).
Inputs are coerced to integer and uniqued. A warning is emitted if any label
is < 1, and an error is thrown if any label exceeds N. If tn < 0,
a warning is issued indicating that N may not reflect the full universe.
A named list with components:
fdr False Discovery Rate, fp/(fp+tp) (NaN if fp+tp == 0).
tpr True Positive Rate (recall), tp/(tp+fn) (NaN if tp+fn == 0).
fp, fn, tp, tn Confusion-matrix counts.
If predlabel is empty, fdr is NaN and tpr is 0 (unless
truelabel is also empty, in which case both fdr and tpr are NaN).
If truelabel is empty and predlabel non-empty, tpr is NaN
and fdr is 1.
# Simple example
N <- 10
true <- c(2, 4, 7)
pred <- c(4, 5, 7, 7) # duplicates are ignored
FDRCalc(true, pred, N)
# Empty predictions
FDRCalc(true, integer(0), N)
# All correct predictions
FDRCalc(true, true, N)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.