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

Deviation, Absolute Deviation, and Squared Deviation

Explaining inconsistent settlement time.

2:37 clip2:12:37–2:15:14 in the full courseWatch on YouTube

Transcript

21 sentences · select one to jump there

Check your understanding

Are squared deviations still measured in hours?

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.

041-deviation-absolute-deviation-and-squared-deviation.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 041 of 120
 * Deviation, Absolute Deviation, and Squared Deviation
 * Module 05: Dispersion, Shape, and Robust Statistics
 *
 * Scenario: Explaining inconsistent settlement time
 * Rule:     deviation = x − center; magnitude = |deviation|; square = deviation²
 *
 * Try it:   Are squared deviations still measured in hours?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/dispersion-shape-and-robust-statistics/deviation-absolute-deviation-and-squared-deviation/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson041() {
  const hours = [1,2,2,4,9], center = 3.6;
  const deviations = hours.map(x => x-center);
  const result = {deviations,
    absolute: deviations.map(Math.abs),
    squared: deviations.map(d => d*d)};
  return result;
}

export const checkedResult = {"deviations":[-2.6,-1.6,-1.6,0.3999999999999999,5.4],"absolute":[2.6,1.6,1.6,0.3999999999999999,5.4],"squared":[6.760000000000001,2.5600000000000005,2.5600000000000005,0.15999999999999992,29.160000000000004]};

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

Your output

Press Run to execute the code in your browser.

Expected output

{
  "deviations": [
    -2.6,
    -1.6,
    -1.6,
    0.3999999999999999,
    5.4
  ],
  "absolute": [
    2.6,
    1.6,
    1.6,
    0.3999999999999999,
    5.4
  ],
  "squared": [
    6.760000000000001,
    2.5600000000000005,
    2.5600000000000005,
    0.15999999999999992,
    29.160000000000004
  ]
}

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

Lesson notes

The rule

deviation = x − center; magnitude = |deviation|; square = deviation²