The percentage of the total population that actually has the condition (prior probability).
Probability the test is positive given the condition is present.
Probability the test is negative given the condition is absent.
Analysis Result
0%
Probability that the condition is true given a positive result
True Positives (Hit):–
False Positives (Alarm):–
Total Positive Tests:–
function calculateBayesianProbability() {
// 1. Get input values
var baseRateVal = document.getElementById('baseRateInput').value;
var sensitivityVal = document.getElementById('sensitivityInput').value;
var specificityVal = document.getElementById('specificityInput').value;
// 2. Validate inputs
if (baseRateVal === "" || sensitivityVal === "" || specificityVal === "") {
alert("Please fill in all fields.");
return;
}
var baseRate = parseFloat(baseRateVal) / 100;
var sensitivity = parseFloat(sensitivityVal) / 100;
var specificity = parseFloat(specificityVal) / 100;
if (baseRate 1 || sensitivity 1 || specificity 1) {
alert("Values must be between 0 and 100.");
return;
}
// 3. Perform Bayesian Calculation
// P(A) = Base Rate
// P(B|A) = Sensitivity
// P(B|not A) = False Positive Rate = 1 – Specificity
// P(not A) = 1 – Base Rate
var falsePositiveRate = 1 – specificity;
// Numerator: P(B|A) * P(A) -> Probability of having condition AND testing positive
var truePositiveProb = sensitivity * baseRate;
// Denominator part 2: P(B|not A) * P(not A) -> Probability of NOT having condition BUT testing positive
var falsePositiveProb = falsePositiveRate * (1 – baseRate);
// Total probability of a positive test P(B)
var totalPositiveProb = truePositiveProb + falsePositiveProb;
// Posterior Probability: P(A|B)
var posteriorResult = 0;
if (totalPositiveProb > 0) {
posteriorResult = truePositiveProb / totalPositiveProb;
}
// 4. Update UI
var resultDiv = document.getElementById('brResult');
resultDiv.style.display = 'block';
// Format percentages
var finalPercent = (posteriorResult * 100).toFixed(2) + "%";
document.getElementById('finalProbability').innerHTML = finalPercent;
// Visualization Logic (Normalized to 10,000 people)
var population = 10000;
var numWithCondition = Math.round(population * baseRate);
var numWithoutCondition = population – numWithCondition;
var numTruePositives = Math.round(numWithCondition * sensitivity);
var numFalsePositives = Math.round(numWithoutCondition * falsePositiveRate);
var numTotalPositives = numTruePositives + numFalsePositives;
document.getElementById('truePositivesDisplay').innerHTML = numTruePositives.toLocaleString();
document.getElementById('falsePositivesDisplay').innerHTML = numFalsePositives.toLocaleString();
document.getElementById('totalPositivesDisplay').innerHTML = numTotalPositives.toLocaleString();
var explanation = "Visual Breakdown: Imagine a population of " + population.toLocaleString() + " people.";
explanation += "• " + numWithCondition.toLocaleString() + " people actually have the condition.";
explanation += "• " + numWithoutCondition.toLocaleString() + " people do not.";
explanation += "The test flags " + numTotalPositives.toLocaleString() + " people as positive. ";
explanation += "However, only " + numTruePositives.toLocaleString() + " of them actually have the condition, while " + numFalsePositives.toLocaleString() + " are false alarms. ";
explanation += "This is why the probability is " + finalPercent + ", even though the test seems accurate.";
document.getElementById('textExplanation').innerHTML = explanation;
}
Understanding Base Rate Psychology and Bayesian Inference
The "Base Rate Fallacy" or "Base Rate Neglect" is a cognitive bias where people tend to ignore the general prevalence of an event (the base rate) in favor of specific information (such as a test result). This calculator helps you apply Bayesian reasoning to determine the actual probability of an event given a specific indicator.
Why Your Brain Calculates Probabilities Wrong
When presented with a medical test that is 99% accurate, most people assume that a positive result means they are 99% likely to have the disease. This is often mathematically incorrect because it ignores the Base Rate—how rare the disease is in the general population.
If a disease affects only 1 in 10,000 people, even a reasonably accurate test can generate more false positives than true positives. The Base Rate Calculator above corrects for this intuition gap using Bayes' Theorem.
Definitions of Terms
Base Rate (Prior Probability): The percentage of the population that actually possesses the characteristic or condition before any testing.
Sensitivity (True Positive Rate): How often the test correctly identifies a positive case. If 100 sick people are tested, and 90 test positive, sensitivity is 90%.
Specificity (True Negative Rate): How often the test correctly identifies a negative case. If 100 healthy people are tested, and 90 test negative, specificity is 90%.
False Positive Rate: The likelihood of a "false alarm." It is calculated as 100% – Specificity.
The Formula: Bayes' Theorem
To calculate the true probability (Posterior) given a positive test result, we use the following formula:
P(A|B) = [ P(B|A) × P(A) ] / [ P(B) ]
Where:
P(A|B): Probability you have the condition given a positive test.
P(B|A): Sensitivity (True Positive Rate).
P(A): Base Rate (Prevalence).
P(B): Total probability of a positive test (True Positives + False Positives).
Real World Example: The Cab Problem
A classic psychology problem involves a city where 85% of cabs are Green and 15% are Blue (Base Rate). A witness identifies a cab involved in a hit-and-run as Blue. The witness is tested and found to be correct 80% of the time (Sensitivity/Specificity).
Most people guess the probability that the cab was Blue is 80%. However, plugging these numbers into the calculator (Base Rate: 15%, Sensitivity: 80%, Specificity: 80%) reveals the true probability is only 41%. The witness is more likely to be wrong than right because Green cabs are so much more common.
How to Use This Calculator
Enter the Base Rate: What is the known prevalence of the condition? (e.g., for a rare disease, this might be 0.1%).
Enter Sensitivity: How good is the test at finding the condition? (e.g., 95%).
Enter Specificity: How good is the test at ruling out healthy people? (e.g., 90%).
Click Calculate: The tool will display the "Posterior Probability," which is the real likelihood of the condition being present.