1from statistics import *2x = [2,4,4,4,5,5,7,9]3mean(x), median(x)4pstdev(x), stdev(x)day 1day 2day 3day 4day 5day 6day 7day 8x−μx−μx−μx−μx−μx−μx−μx−μ(x−μ)²(x−μ)²(x−μ)²(x−μ)²(x−μ)²(x−μ)²(x−μ)²(x−μ)²draw 1draw 2draw 3draw 4
Value cells: the label on top, the value belowGold outline: the middle two values (the median)Calculator: the working value of the current sum or resultPython card: the statistics functions that do each stepThree rows share the same eight columns: the data (minutes late on 8 days), each value minus the mean μ = 5, and that deviation squared. The squares add to 32, so the variance is 32 ÷ 8 = 4 and the standard deviation is 2. Tokens hop along dashed trails: values into the calculator; a value minus 5 into its deviation cell; a deviation into its square; four random days into the sample at the front. The figure draws with replacement (a day can be picked twice), so the draws are independent: that is the case in which s² averages exactly σ² and the sample mean has standard deviation σ ÷ √n.

The centre

  1. Statistics starts with data. A bus was late on 8 days by 2, 4, 4, 4, 5, 5, 7 and 9 minutes. For now, treat these 8 days as the whole population: every value we care about.

The spread

Sampling

In code

Try it in the Python prompt

;; step 1/10 · Start with data
>>> x = [2, 4, 4, 4, 5, 5, 7, 9]
>>> len(x), min(x), max(x)
(8, 2, 9)

The variance is in squared units (minutes²), which is hard to picture. The standard deviation, its square root, is back in the units of the data, so it is the number people usually quote. Why n − 1: the sample values sit closer to their own mean x̄ than to the true mean μ, so squared distances from x̄ come out too small on average. Dividing by n − 1 instead of n exactly corrects this (Bessel’s correction).