.sdt-calculator-container {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #fff;
color: #333;
}
.calc-box {
background-color: #f9f9f9;
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 30px;
margin-bottom: 40px;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.calc-row {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 20px;
}
.calc-col {
flex: 1;
min-width: 200px;
}
.calc-label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #2c3e50;
}
.calc-input {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
transition: border-color 0.3s;
}
.calc-input:focus {
border-color: #3498db;
outline: none;
}
.calc-btn {
background-color: #2c3e50;
color: white;
border: none;
padding: 15px 30px;
font-size: 16px;
font-weight: bold;
border-radius: 4px;
cursor: pointer;
width: 100%;
transition: background-color 0.2s;
}
.calc-btn:hover {
background-color: #34495e;
}
.result-box {
margin-top: 25px;
padding: 20px;
background-color: #e8f6f3;
border: 1px solid #d4efdf;
border-radius: 4px;
display: none;
}
.result-header {
font-size: 18px;
font-weight: bold;
color: #16a085;
margin-bottom: 15px;
text-align: center;
border-bottom: 1px solid #d4efdf;
padding-bottom: 10px;
}
.result-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 15px;
}
.result-item {
background: white;
padding: 10px;
border-radius: 4px;
text-align: center;
}
.result-label {
font-size: 13px;
color: #7f8c8d;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.result-value {
font-size: 24px;
font-weight: 700;
color: #2c3e50;
}
.article-content h2 {
margin-top: 40px;
color: #2c3e50;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
}
.article-content h3 {
margin-top: 25px;
color: #34495e;
}
.article-content p, .article-content li {
line-height: 1.6;
color: #555;
font-size: 16px;
}
.formula-box {
background: #eee;
padding: 15px;
border-left: 4px solid #3498db;
font-family: monospace;
margin: 20px 0;
}
@media (max-width: 600px) {
.result-grid {
grid-template-columns: 1fr;
}
}
function calculateSDT() {
var hits = document.getElementById('hitsInput').value;
var misses = document.getElementById('missesInput').value;
var falseAlarms = document.getElementById('faInput').value;
var correctRejections = document.getElementById('crInput').value;
// Basic Validation
if (hits === "" || misses === "" || falseAlarms === "" || correctRejections === "") {
alert("Please fill in all fields (enter 0 if applicable).");
return;
}
var h = parseFloat(hits);
var m = parseFloat(misses);
var fa = parseFloat(falseAlarms);
var cr = parseFloat(correctRejections);
if (isNaN(h) || isNaN(m) || isNaN(fa) || isNaN(cr)) {
alert("Please enter valid numbers.");
return;
}
// Totals
var totalSignal = h + m;
var totalNoise = fa + cr;
var totalEvents = totalSignal + totalNoise;
// Hit Rate Calculation (Recall/Sensitivity)
var hitRate = 0;
if (totalSignal > 0) {
hitRate = h / totalSignal;
} else {
hitRate = 0; // Handle edge case where there are no signal trials
}
// False Alarm Rate Calculation
var falseAlarmRate = 0;
if (totalNoise > 0) {
falseAlarmRate = fa / totalNoise;
} else {
falseAlarmRate = 0;
}
// Accuracy Calculation
var accuracy = 0;
if (totalEvents > 0) {
accuracy = (h + cr) / totalEvents;
}
// Precision Calculation (Positive Predictive Value)
var precision = 0;
var totalPositives = h + fa;
if (totalPositives > 0) {
precision = h / totalPositives;
}
// Display Results
document.getElementById('resHitRate').innerHTML = (hitRate * 100).toFixed(2) + "%";
document.getElementById('resFAR').innerHTML = (falseAlarmRate * 100).toFixed(2) + "%";
document.getElementById('resAccuracy').innerHTML = (accuracy * 100).toFixed(2) + "%";
document.getElementById('resPrecision').innerHTML = (precision * 100).toFixed(2) + "%";
// Show result box
document.getElementById('resultBox').style.display = "block";
}
How to Calculate Hit Rate and False Alarm Rate
Understanding the performance of a detection system—whether it represents a medical diagnostic test, a machine learning classifier, or a radar operator—requires more than just looking at raw accuracy. The most critical metrics in Signal Detection Theory (SDT) are the Hit Rate and the False Alarm Rate.
These two metrics help separate a system's ability to discriminate signals from noise versus its tendency to simply guess "yes" or "no." This guide explains the definitions, formulas, and interpretations of these essential statistical figures.
The Confusion Matrix
To calculate these rates, you first need to categorize your data into a confusion matrix (a 2×2 table) consisting of:
- Hits (H): The signal was present, and the system correctly detected it.
- Misses (M): The signal was present, but the system failed to detect it.
- False Alarms (FA): The signal was absent (noise only), but the system incorrectly reported a signal.
- Correct Rejections (CR): The signal was absent, and the system correctly reported "no signal."
1. Calculating Hit Rate (HR)
The Hit Rate, also known as Sensitivity, Recall, or the True Positive Rate, measures the proportion of actual signals that were correctly identified.
Hit Rate = Hits / (Hits + Misses)
A Hit Rate of 100% means the system never misses a signal. A low Hit Rate indicates the system is conservative or insensitive, often resulting in Type II errors (Misses).
2. Calculating False Alarm Rate (FAR)
The False Alarm Rate, also known as the False Positive Rate, measures the proportion of noise events that were incorrectly identified as signals.
False Alarm Rate = False Alarms / (False Alarms + Correct Rejections)
A False Alarm Rate of 0% means the system never cries wolf. A high FAR indicates the system is "trigger happy," resulting in many Type I errors.
Relationship Between HR and FAR
In most systems, there is a trade-off between the Hit Rate and the False Alarm Rate. By lowering the threshold for detection, you can increase the Hit Rate (catching more signals), but you usually increase the False Alarm Rate (generating more noise errors) simultaneously. This relationship is often visualized using a Receiver Operating Characteristic (ROC) curve.
Why Accuracy isn't Enough
Accuracy is calculated as (Hits + Correct Rejections) / Total Trials. However, if signal events are very rare (e.g., a disease occurring in 1% of the population), a system that simply guesses "Absent" every time will have 99% accuracy but a 0% Hit Rate. This is why calculating HR and FAR separately provides a much truer picture of system performance.