Bayes Theorem Calculator Formula
Understand the math behind the bayes theorem calculator. Each variable explained with a worked example.
Formulas Used
P(A|B) - Posterior
posterior = (p_b_given_a * p_a) / p_bPosterior (%)
posterior_pct = ((p_b_given_a * p_a) / p_b) * 100P(B) - Total Evidence
total_evidence = p_bVariables
| Variable | Description | Default |
|---|---|---|
p_a | P(A) - Prior | 0.01 |
p_b_given_a | P(B|A) - Likelihood | 0.9 |
p_b_given_not_a | P(B|not A) - False Positive Rate | 0.05 |
p_b | Derived value= p_b_given_a * p_a + p_b_given_not_a * (1 - p_a) | calculated |
How It Works
How to Apply Bayes' Theorem
Formula
P(A|B) = P(B|A) * P(A) / P(B)
where P(B) = P(B|A)*P(A) + P(B|not A)*P(not A)
Bayes' theorem updates a prior belief P(A) after observing evidence B. The likelihood P(B|A) measures how probable the evidence is if A is true. The denominator P(B) normalizes the result.
Worked Example
A disease affects 1% of the population. A test is 90% sensitive and has a 5% false positive rate. If someone tests positive, what is the probability they have the disease?
p_a = 0.01p_b_given_a = 0.9p_b_given_not_a = 0.05
- 01P(A) = 0.01 (prior: disease prevalence)
- 02P(B|A) = 0.9 (sensitivity)
- 03P(B|not A) = 0.05 (false positive rate)
- 04P(B) = 0.9 * 0.01 + 0.05 * 0.99 = 0.009 + 0.0495 = 0.0585
- 05P(A|B) = (0.9 * 0.01) / 0.0585 = 0.009 / 0.0585 ≈ 0.1538
- 06Despite a positive test, there is only about a 15.4% chance of having the disease.
Ready to run the numbers?
Open Bayes Theorem Calculator