Module 5 · Dispersion, Shape, and Robust Statistics Lesson 44 of 120

Median Absolute Deviation

Robust central spread without confusing two MADs.

2:32 clip2:20:00–2:22:32 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Is 1.4826 a universal correction for every distribution?

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.

044-median-absolute-deviation.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 044 of 120
 * Median Absolute Deviation
 * Module 05: Dispersion, Shape, and Robust Statistics
 *
 * Scenario: Robust central spread without confusing two MADs
 * Rule:     raw MAD = median(|x − median(x)|)
 *
 * Try it:   Is 1.4826 a universal correction for every distribution?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/dispersion-shape-and-robust-statistics/median-absolute-deviation/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson044() {
  const x = [1,2,2,4,9];
  const med = (a: number[]) => { const s=[...a].sort((p,q)=>p-q), m=Math.floor(s.length/2);
    return s.length % 2 ? s[m] : (s[m-1]+s[m])/2; };
  const center = med(x);
  const raw = med(x.map(v=>Math.abs(v-center)));
  const result = {raw, normalScaled: 1.4826*raw};
  return result;
}

export const checkedResult = {"raw":1,"normalScaled":1.4826};

// Run this file directly: npx tsx lessons/05-dispersion-shape-and-robust-statistics/044-median-absolute-deviation.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson044(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "raw": 1,
  "normalScaled": 1.4826
}

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

Lesson notes

The rule

raw MAD = median(|x − median(x)|)