Module 3 · Data, Variables, Samples, and Measurement Lesson 22 of 120

Numeric, Categorical, Ordinal, and Binary Variables

A risk grade is ordered, but not a measured distance.

2:27 clip1:11:17–1:13:44 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Can we average customer IDs to describe a typical customer?

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.

022-numeric-categorical-ordinal-and-binary-variables.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 022 of 120
 * Numeric, Categorical, Ordinal, and Binary Variables
 * Module 03: Data, Variables, Samples, and Measurement
 *
 * Scenario: A risk grade is ordered, but not a measured distance
 * Rule:     numeric · categorical · ordinal · binary
 *
 * Try it:   Can we average customer IDs to describe a typical customer?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/data-variables-samples-and-measurement/numeric-categorical-ordinal-and-binary-variables/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson022() {
  type Payment = {amount: number; channel: string;
    riskGrade: "low" | "medium" | "high"; flagged: boolean};
  const p: Payment = {amount: 50, channel: "card",
    riskGrade: "medium", flagged: false};
  const result = {amount: p.amount, grade: p.riskGrade};
  return result;
}

export const checkedResult = {"amount":50,"grade":"medium"};

// Run this file directly: npx tsx lessons/03-data-variables-samples-and-measurement/022-numeric-categorical-ordinal-and-binary-variables.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson022(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "amount": 50,
  "grade": "medium"
}

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

Lesson notes

The rule

numeric · categorical · ordinal · binary