Concept map / Coin toss

Share

The law of large numbers

Flip a coin many times and watch the share of heads settle near its true chance.

1Flip a coin and watch the share of heads

Flip a fair coin ten times and seven heads is nothing unusual. That is 70%, a long way from half. Flip it a thousand times and you will almost never be that far off. The pull toward half as the flips pile up is called the law of large numbers.

Each small circle below is one flip, orange for heads and blue for tails. The orange line is the share of heads so far, and the shaded band is where a run usually stays. Flip a few times, then start another run and compare the two.

HeadsTailsNo flips yet
0%25%50%75%100%Proportion of heads so far110100Number of flips (each step right is ten times more)
This runTrue chance of headsWhere a run usually stays

Press Flip 10 to start.

More controls

2Five heads in a row, then what?

A fair coin has just landed heads five times in a row.

What about the sixth flip?

3The count drifts while the share settles

This chart shows the same run as a count: heads minus the number you would expect, n × p. The count gap does not shrink. Its typical size grows with √n, to about 16 heads after 1,000 fair flips. The share of heads still settles, because that gap is divided by n, and n grows much faster than √n.

-110+11Heads above or below the expected number110100Number of flips (each step right is ten times more)

Flip the coin in section 1 to see the count gap.

typical gap between the proportion and p  =  p (1−p)n\text{typical gap between the proportion and } p \;=\; \sqrt{\frac{\htmlClass{term-pq}{p\,(1-p)}}{\htmlClass{term-a}{n}}}
typical gap between theproportion and p=p (1−p)n\begin{aligned} &\text{typical gap between the} \\ &\text{proportion and } p = \sqrt{\frac{\htmlClass{term-pq}{p\,(1-p)}}{\htmlClass{term-a}{n}}} \end{aligned}

Four times as many flips halves it. Point at the formula to light up the band in section 1.

A common misreading is that the law of large numbers evens out the count. It does not. After 10,000 fair flips, being 50 heads ahead or behind is ordinary, and that is half a percentage point of the share.

4Check yourself

The tasks use the buttons in section 1 and tick themselves when you meet them.

  • Flip at least 1,000 times in one run and end within 2 percentage points of the coin's chance of heads.Now: No flips yet
  • Make five runs of at least 100 flips each, pressing Start another run between them. See how far apart they start and how close they end.Now: 0 runs of 100 or more
  • Keep flipping one run until the typical gap in section 3 is down to 1 percentage point, and note how many flips that took.Now: No flips yet

5Flip 10,000 times in R

The snippet flips a fair coin 10,000 times and prints the share of heads, the count gap and the typical gap after 10, 100, 1,000 and 10,000 flips. The flips are random, so the first columns will not match your runs. The typical gap does not depend on luck: 0.016 after 1,000 flips and 0.01 after 2,500.

Track the share of heads over 10,000 flipsShow the code
# A fair coin, as on the page: p = 0.5
set.seed(1)
p <- 0.5
tosses <- rbinom(10000, size = 1, prob = p)

# Proportion of heads after 10, 100, 1,000 and 10,000 tosses
n <- c(10, 100, 1000, 10000)
heads <- cumsum(tosses)[n]
prop <- heads / n
# Heads above or below the expected number, n * p
gap <- heads - n * p
# Typical gap between the proportion and p
sd_prop <- sqrt(p * (1 - p) / n)
round(cbind(n, prop, gap, sd_prop), 3)

# The typical gap falls to 1 percentage point at 2,500 tosses
sqrt(p * (1 - p) / 2500)

Uses base R only.

What the coin shows