Module 8 · Sampling, Estimation, and Statistical Inference Lesson 72 of 120

Sampling Distributions

Separating variation in customers from variation in an estimate.

2:29 clip3:52:06–3:54:35 in the full courseWatch on YouTube

Transcript

19 sentences · select one to jump there

Check your understanding

Which distribution contains 0,1,1,2 in this example?

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.

072-sampling-distributions.ts
Start from GitHub
/**
 * Fintech Math Bootcamp · Lesson 072 of 120
 * Sampling Distributions
 * Module 08: Sampling, Estimation, and Statistical Inference
 *
 * Scenario: Separating variation in customers from variation in an estimate
 * Rule:     sampling distribution = distribution of a statistic across samples
 *
 * Try it:   Which distribution contains 0,1,1,2 in this example?
 *
 * Lesson article: https://thefintechbuilder.com/financial-mathematics-statistics-and-data-foundations/sampling-estimation-and-statistical-inference/sampling-distributions/
 * Free course:    https://courses.thefintechbuilder.com
 * Synthetic teaching example, not financial advice or a production library.
 */

export function lesson072() {
  const population=[0,2];
  const sampleMeans=population.flatMap(a=>population.map(b=>(a+b)/2));
  const mean=sampleMeans.reduce((s,x)=>s+x,0)/sampleMeans.length;
  const variance=sampleMeans.reduce((s,x)=>s+(x-mean)**2,0)/sampleMeans.length;
  const result={sampleMeans,mean,variance};
  return result;
}

export const checkedResult = {"sampleMeans":[0,1,1,2],"mean":1,"variance":0.5};

// Run this file directly: npx tsx lessons/08-sampling-estimation-and-statistical-inference/072-sampling-distributions.ts
if (process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/\\/g, "/").split("/").pop()!)) {
  console.log(JSON.stringify(lesson072(), null, 2));
}

Your output

Press Run to execute the code in your browser.

Expected output

{
  "sampleMeans": [
    0,
    1,
    1,
    2
  ],
  "mean": 1,
  "variance": 0.5
}

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

Lesson notes

The rule

sampling distribution = distribution of a statistic across samples