Home › Statistics & Probability › Bayes' Theorem Calculator
Bayes' Theorem Calculator
Applies Bayes' theorem to a prior probability P(A) and the likelihoods P(B|A) and P(B|not A) to obtain the posterior P(A|B), the marginal P(B), the complementary posteriors and the likelihood ratio (Bayes factor).
When to use
You know how likely an evidence B is under a hypothesis A and under its negation and want the updated probability of A after observing B (test results, spam filtering, diagnosis, fault detection).
Do not use when: The inputs are sensitivity, specificity and prevalence in percent and you want predictive values per 1000 people (use diagnostic-test), or the events are simply independent (use probability-of-events).
Formula
P(A|B) = P(B|A)·P(A) / P(B), with P(B) = P(B|A)·P(A) + P(B|¬A)·(1 − P(A)); P(A|¬B) = (1 − P(B|A))·P(A) / (1 − P(B)); odds form: posterior odds = prior odds × P(B|A)/P(B|¬A)
Inputs
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
probability_a | number | yes | Prior probability of the hypothesis A, as a fraction between 0 and 1. Range: > 0 | |
probability_b_given_a | number | yes | Probability of observing the evidence B when A is true (e.g. sensitivity as a fraction). Range: ≥ 0, ≤ 1 | |
probability_b_given_not_a | number | yes | Probability of observing B when A is false (e.g. false-positive rate = 1 − specificity). Range: ≥ 0, ≤ 1 |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
probability_a_given_b | number | Probability of A after observing B. | |
probability_b | number | Marginal probability of the evidence: P(B|A)·P(A) + P(B|¬A)·(1 − P(A)). | |
probability_not_a_given_b | number | 1 − P(A|B). | |
probability_a_given_not_b | number | Probability of A when B is not observed (omitted when P(B) = 1). | |
likelihood_ratio | number | P(B|A) / P(B|¬A): how much B favours A (omitted when P(B|¬A) = 0). | |
prior_odds | number | P(A) / (1 − P(A)). | |
posterior_odds | number | prior_odds × likelihood_ratio = P(A|B) / P(¬A|B) (omitted when P(A|B) = 1). |
Example
Drug test: 0.5 % prevalence, 99 % sensitivity, 1 % false positives (Wikipedia): {"probability_a":0.005,"probability_b_given_a":0.99,"probability_b_given_not_a":0.01} → {"probability_a_given_b":0.332215,"probability_b":0.0149,"probability_not_a_given_b":0.667785,"probability_a_given_not_b":0.000051,"likelihood_ratio":99,"prior_odds":0.005025,"posterior_odds":0.497487}
P(A) = 0.3, P(B|A) = 0.8, P(B|not A) = 0.2: {"probability_a":0.3,"probability_b_given_a":0.8,"probability_b_given_not_a":0.2} → {"probability_a_given_b":0.631579,"probability_b":0.38,"probability_a_given_not_b":0.096774,"likelihood_ratio":4,"prior_odds":0.428571,"posterior_odds":1.714286}
GET https://tttkmbb.com/api/v1/calculate/bayes-theorem?probability_a=0.005&probability_b_given_a=0.99&probability_b_given_not_a=0.01
Machine access
- API:
GET https://tttkmbb.com/api/v1/calculate/bayes-theorem(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/bayes-theorem · Markdown: https://tttkmbb.com/statistics/bayes-theorem.md · JSON definition: https://tttkmbb.com/statistics/bayes-theorem.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="bayes-theorem" - OpenAPI operationId:
calculate_bayes_posterior_probability - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
- Wikipedia – Bayes' theorem (reference)
- Wolfram MathWorld – Bayes' Theorem (reference)
FAQ
Why is the posterior so low with a 99 % accurate test?
When A is rare, the many false positives among the non-A majority outnumber the true positives: with 0.5 % prevalence about two thirds of positive results are false. This is the base-rate effect.
Can I enter percentages?
No, all inputs are probabilities between 0 and 1 (0.05 for 5 %). The diagnostic-test calculator accepts percentages.
Related calculators
- Diagnostic Test Calculator — The same update expressed as sensitivity, specificity and predictive values.
- Probability of Two Events Calculator — Combine probabilities of independent or exclusive events.