fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Bayes' Theorem and Base Rates

Install and import#

bash
npm install fintech-algorithms
ts
import { bayesTheoremAndBaseRates } from "fintech-algorithms/financial-mathematics-statistics-and-data-foundations/probability-and-random-variables/bayes-theorem-and-base-rates";

Signature#

bayesTheoremAndBaseRates(input)

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

input
{
  "pA": 0.6,
  "pB": 0.5,
  "pAB": 0.3,
  "outcomes": ["up", "flat", "down"],
  "event": ["up", "flat"],
  "prior": 0.01,
  "sensitivity": 0.9,
  "falsePositiveRate": 0.05,
  "randomValues": [0, 1, 2],
  "probabilities": [0.2, 0.5, 0.3],
  "randomVariableKind": "discrete",
  "joint": [
    {
      "x": 0,
      "y": 0,
      "p": 0.3
    },
    {
      "x": 0,
      "y": 1,
      "p": 0.2
    },
    {
      "x": 1,
      "y": 0,
      "p": 0.1
    }
  ],
  "conditionY": 1
}

Call#

bayesTheoremAndBaseRates(input)

Returns#

object with 2 fields: posterior, evidenceProbability

{
  "posterior": 0.15384615384615385,
  "evidenceProbability": 0.0585
}

Diagrams#

Bayes' Theorem and Base Rates — article hero
Bayes' Theorem and Base Rates — calculation ledger
Bayes' Theorem and Base Rates — concept anatomy
Bayes' Theorem and Base Rates — failure boundary
Bayes' Theorem and Base Rates — method map
Bayes' Theorem and Base Rates — scenario contrast

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Probability and Random Variables family#