Module 6 · Probability and Random Variables Lesson 59 of 120

Joint, Marginal, and Conditional Distributions

Seeing default risk inside customer segments.

2:29 clip3:05:25–3:07:54 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

What is the denominator for default conditional on segment B?

Choose one answer

Code lab

Run it yourself

The lesson source in 7 languages. Edit it, run TypeScript and Python right here, and compare with the expected output.

059-joint-marginal-and-conditional-distributions.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 059 of 120
 * Joint, Marginal, and Conditional Distributions
 * Module 06: Probability and Random Variables
 *
 * Scenario: Seeing default risk inside customer segments
 * Rule:     marginal = sum joint cells; conditional = joint / group mass
 *
 * Try it:   What is the denominator for default conditional on segment B?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/probability-and-random-variables/joint-marginal-and-conditional-distributions/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson059() {
  const joint=[[.63,.07],[.24,.06]]; // segment rows; repay/default columns
  if (Math.abs(joint.flat().reduce((s,v)=>s+v,0) - 1) > 1e-12)
    throw new Error("Joint probabilities must sum to 1");
  const defaults=joint[0][1]+joint[1][1];
  const segmentB=joint[1][0]+joint[1][1];
  const result={defaults,segmentB,defaultGivenB:joint[1][1]/segmentB};
  return result;
}

export const checkedResult = {"defaults":0.13,"segmentB":0.3,"defaultGivenB":0.2};

// Run this file directly: npx tsx lessons/06-probability-and-random-variables/059-joint-marginal-and-conditional-distributions.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson059(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "defaults": 0.13,
  "segmentB": 0.3,
  "defaultGivenB": 0.2
}

Prefer your own machine? Every file is in the course repository · open it in Codespaces.

Lesson notes

The rule

marginal = sum joint cells; conditional = joint / group mass