# 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).

- Calculator id: `bayes-theorem` · Category: Statistics & Probability (`statistics`) · Tool name: `calculate_bayes_posterior_probability`
- Canonical page: https://tttkmbb.com/statistics/bayes-theorem · This document: https://tttkmbb.com/statistics/bayes-theorem.md · JSON definition: https://tttkmbb.com/statistics/bayes-theorem.json

## Purpose

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).

**Use when:** 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).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `probability_a` | number |  | required | Prior probability of the hypothesis A, as a fraction between 0 and 1. (> 0) |
| `probability_b_given_a` | number |  | required | Probability of observing the evidence B when A is true (e.g. sensitivity as a fraction). (min 0, max 1) |
| `probability_b_given_not_a` | number |  | required | Probability of observing B when A is false (e.g. false-positive rate = 1 − specificity). (min 0, max 1) |

## Output

| Field | 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). |

## 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)`

## Data Sources

- Wikipedia – Bayes' theorem — https://en.wikipedia.org/wiki/Bayes%27_theorem (reference, retrieved 2026-09-24)
- Wolfram MathWorld – Bayes' Theorem — https://mathworld.wolfram.com/BayesTheorem.html (reference, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/bayes-theorem?probability_a=…&probability_b_given_a=…&probability_b_given_not_a=…`
- `POST https://tttkmbb.com/api/v1/calculate/bayes-theorem` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/bayes-theorem · OpenAPI operationId `calculate_bayes_posterior_probability` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "bayes-theorem", "inputs": {…}}`

## Example

- Drug test: 0.5 % prevalence, 99 % sensitivity, 1 % false positives (Wikipedia): inputs `{"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: inputs `{"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
```

## Limitations

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). All values are computed from the formula above; no measurement or live data is involved.

## 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

- [Diagnostic Test Calculator](https://tttkmbb.com/statistics/diagnostic-test.md) — The same update expressed as sensitivity, specificity and predictive values.
- [Probability of Two Events Calculator](https://tttkmbb.com/statistics/probability-of-events.md) — Combine probabilities of independent or exclusive events.
