FDRCalc: False Discovery Rate (FDR) and True Positive Rate (TPR) from...

View source: R/gareg_subset.R

FDRCalcR Documentation

False Discovery Rate (FDR) and True Positive Rate (TPR) from index labels

Description

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).

Usage

FDRCalc(truelabel, predlabel, N)

Arguments

truelabel

Integer vector of ground-truth positive indices (values in 1..N).

predlabel

Integer vector of predicted positive indices (values in 1..N).

N

Integer scalar; size of the full index universe (total number of candidates).

Details

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.

Value

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.

Edge cases

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.

Examples

# 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)


GAReg documentation built on March 29, 2026, 5:08 p.m.