Calculate FDR, FPR, and Precision based on confusion matrix values.
Correctly predicted positives (hits).
Incorrectly predicted positives (Type I Error).
Correctly predicted negatives (rejections).
Incorrectly predicted negatives (Type II Error).
False Discovery Rate (FDR):–
Precision (PPV):–
False Positive Rate (FPR):–
Total Discoveries (TP + FP):–
Understanding False Discovery Rate
The False Discovery Rate (FDR) is a critical statistical metric used in multiple hypothesis testing and machine learning classification. It quantifies the expected proportion of "discoveries" (rejected null hypotheses or positive classifications) that are actually incorrect (false positives).
Unlike the False Positive Rate (which looks at false alarms relative to all negative cases), the FDR focuses specifically on the reliability of the positive results. It answers the question: "Given that the test result is positive, what is the probability that it is a false alarm?"
FDR Formula
The calculation is derived from the Confusion Matrix:
Alternatively, FDR can be expressed as 1 - Precision (where Precision is also known as Positive Predictive Value or PPV).
FDR vs. FPR: What's the Difference?
It is crucial not to confuse False Discovery Rate with False Positive Rate (FPR). The inputs required for calculation differ:
FDR (False Discovery Rate): Measures the "noise" within the accepted discoveries. Formula: FP / (FP + TP).
FPR (False Positive Rate): Measures the probability of falsely rejecting a null hypothesis. Formula: FP / (FP + TN).
Why is FDR Important?
1. Genomics and Bioinformatics:
When testing thousands of genes for differential expression, a standard p-value threshold of 0.05 might result in hundreds of false positives simply by chance. Controlling the FDR (e.g., using the Benjamini-Hochberg procedure) ensures that the list of candidate genes contains a manageable number of false leads.
2. Machine Learning:
In anomaly detection (like fraud detection), you want to minimize the FDR so that the alerts sent to investigators are mostly valid, preventing "alert fatigue."
Interpretation of Results
Low FDR (e.g., < 5%): Indicates high confidence in the positive results. Most of the declared discoveries are likely true.
High FDR (e.g., > 50%): Indicates that more than half of the "positive" results are actually noise. This often suggests that the threshold for significance or classification is too loose.
function calculateFDR() {
// 1. Get input values
var tp = document.getElementById('fdr_tp').value;
var fp = document.getElementById('fdr_fp').value;
var tn = document.getElementById('fdr_tn').value;
var fn = document.getElementById('fdr_fn').value;
// 2. Parse values and handle empty strings
tp = tp === "" ? 0 : parseFloat(tp);
fp = fp === "" ? 0 : parseFloat(fp);
tn = tn === "" ? 0 : parseFloat(tn);
fn = fn === "" ? 0 : parseFloat(fn);
// 3. Validation
if (isNaN(tp) || isNaN(fp) || isNaN(tn) || isNaN(fn)) {
alert("Please enter valid numeric values for all fields.");
return;
}
if (tp < 0 || fp < 0 || tn < 0 || fn < 0) {
alert("Values cannot be negative.");
return;
}
// 4. Calculate Total Discoveries (Positive Predictions)
var total_discoveries = tp + fp;
var total_negatives = tn + fp; // Actual Negatives
// 5. Calculate Metrics
var fdr = 0;
var ppv = 0;
var fpr = 0;
// FDR Calculation: FP / (FP + TP)
if (total_discoveries === 0) {
fdr = 0; // Avoid division by zero
ppv = 0;
} else {
fdr = fp / total_discoveries;
ppv = tp / total_discoveries; // Precision
}
// FPR Calculation: FP / (FP + TN)
if (total_negatives === 0) {
fpr = 0;
} else {
fpr = fp / total_negatives;
}
// 6. Format Display
// Convert to percentages with 2 decimal places
var fdr_display = (fdr * 100).toFixed(2) + "%";
var ppv_display = (ppv * 100).toFixed(2) + "%";
var fpr_display = (fpr * 100).toFixed(2) + "%";
// 7. Update DOM
document.getElementById('result_fdr').innerText = fdr_display;
document.getElementById('result_ppv').innerText = ppv_display;
document.getElementById('result_fpr').innerText = fpr_display;
document.getElementById('result_discoveries').innerText = total_discoveries;
// Show result box
document.getElementById('fdr_results_box').style.display = "block";
}