Module 9 · Dependence, Regression, and Model Foundations Lesson 85 of 120

Correlation, Causation, Confounding, and Spurious Relationships

A pooled recovery-rate comparison that reverses within difficulty groups.

2:35 clip4:33:23–4:35:58 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Does this grouped example prove a causal benefit from switching every case to 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.

085-correlation-causation-confounding-and-spurious-relationships.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 085 of 120
 * Correlation, Causation, Confounding, and Spurious Relationships
 * Module 09: Dependence, Regression, and Model Foundations
 *
 * Scenario: A pooled recovery-rate comparison that reverses within difficulty groups
 * Rule:     association ≠ effect of intervention
 *
 * Try it:   Does this grouped example prove a causal benefit from switching every case to B?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/dependence-regression-and-model-foundations/correlation-causation-confounding-and-spurious-relationships/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson085() {
  const a={easyRecovered:90,easy:100,hardRecovered:1,hard:10};
  const b={easyRecovered:19,easy:20,hardRecovered:20,hard:100};
  const result={pooledA:(a.easyRecovered+a.hardRecovered)/(a.easy+a.hard),
    pooledB:(b.easyRecovered+b.hardRecovered)/(b.easy+b.hard),
    easy:[a.easyRecovered/a.easy,b.easyRecovered/b.easy],
    hard:[a.hardRecovered/a.hard,b.hardRecovered/b.hard]};
  return result;
}

export const checkedResult = {"pooledA":0.8272727272727273,"pooledB":0.325,"easy":[0.9,0.95],"hard":[0.1,0.2]};

// Run this file directly: npx tsx lessons/09-dependence-regression-and-model-foundations/085-correlation-causation-confounding-and-spurious-relationships.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson085(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "pooledA": 0.8272727272727273,
  "pooledB": 0.325,
  "easy": [
    0.9,
    0.95
  ],
  "hard": [
    0.1,
    0.2
  ]
}

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

Lesson notes

The rule

association ≠ effect of intervention