Balls drop through ten rows of pegs, bouncing left or right at each one. Watch where a thousand of them pile up.
A thousand balls, one pattern
Ten rows of pegs; at each one a ball goes right with chance p (seed 2100).
At each peg a ball goes right with chance ½. Twenty balls drop one by one, each adding a twentieth to its bar; the dots mark the long-run shares.
Describe this picture
A board with ten rows of pegs above eleven bins numbered 0 to 10. Each ball bounces right at each peg with chance , and left otherwise, and lands in the bin that counts its bounces to the right. The bars show the share of balls in each bin, and a dot on each bar marks the exact share in the long run. The clip drops 1000 seeded balls (seed 2100) at : the first 20 one by one, so you can follow their paths, each adding a twentieth to its bar, then the other 980 poured in. After 20 balls the bars are ragged, and the middle bin holds 0.300 of them; after 1000 they sit close to the dots, highest in the middle bin at 0.265. Readouts give the number of balls, the tilt , and bin 5’s share and long-run share. After the clip a slider, “Tilt, p”, sets the chance of a bounce to the right from 0.1 to 0.9 in steps of 0.05, and the bars move to the pile the same 1000 balls make at that tilt.
A number for each outcome
Follow one ball. At each of the ten pegs it goes left or right, so its trip is a list such as right, left, left, right, and so on: one of possible paths. That path is the outcome. The bin it lands in is a single number, the count of rights on the path.
A rule that attaches a number to each outcome is a random variable. I write random variables as capital letters, like , and the values they can take as small letters, like . Here is the number of rights, and its values are .
A random variable whose values can be listed one by one, like a count, is discrete. Its shape is given by the probability mass function, or pmf, which says how likely each value is:
Every ball lands in some bin, so the pmf adds up to 1 over all the values: .
One run, or the long run
Watch the clip again. After 20 balls the bars are ragged: some bins are empty, one bar may stand far above its dot. After 1000 balls the bars sit on the dots.
The dots are the pmf. A pmf does not describe one run of 20 balls; it describes the shares in the long run, as every probability in What probability measures does. The middle bin’s share is . Of 20 balls, about should land there, give or take about . Three balls or seven would be ordinary. The clip’s first 20 put 6 there, a share of 0.300, and its 1000 put 265 there, 0.265.
Watch out
A ragged pile of 20 balls does not disprove the pmf. The pmf is the long-run shape; any one short run wobbles around it.
After the clip, drag the tilt. At the dots move left and peak at 3; at they peak at 7. The 1000 balls follow closely but not exactly: at the bars at 2 and 3 are 0.241 and 0.238, and at the bars at 7 and 8 are 0.243 and 0.246, so a neighbour of the peak can come out a hair taller. At more balls land in bin 1 than in any other: 0.388 of them, against in the long run.
Why the board makes this shape
Take one path with rights and lefts, in a given order. The bounces do not affect each other: each is independent of the others. So the chance of that one path is a product, for each right and for each left:
Every path with rights has this same chance, whatever the order. How many such paths are there? A path is fixed by choosing which of the 10 pegs send the ball right, so there are of them, the binomial coefficient of Counting. Add the equal chances of all these paths:
At every path has chance , and bin 5 collects paths: .
The same reasoning works for any number of tries with chance of success in each, the tries independent. The number of successes follows the binomial law, written :
With a single try, , the count is 1 with chance and 0 with chance . That one-try variable is called a Bernoulli variable. A binomial count is a sum of independent Bernoulli variables, one per peg.
The distribution function
Often the question is not “exactly 3?” but “at most 3?”. The distribution function of answers it:
It climbs in steps, one step at each value, each step as tall as the pmf there, from 0 on the far left to 1 on the far right. For the board at , the chance of at most 4 rights is
The chance of more than 4 is then , by the complement rule.
Two more shapes
Waiting for the first success. Roll a die until the first six. Let be the number of rolls it takes. For the first rolls must miss and the -th must hit, so with chance of a hit on each independent roll,
This is the geometric law, . Its pmf is largest at and falls by the same factor at each step. It has no last value: any number of misses in a row is possible, only less and less likely.
All values equally likely. A fair die’s face is 1 to 6, each with chance . A variable that takes values, each with chance , follows the discrete uniform law.
Worked example
1. Guessing a quiz. A quiz has 10 questions, each with 4 answers to pick from. You guess every answer at random, independently. The number right, , follows :
| Right answers | Ways | Chance |
|---|---|---|
| 0 | 1 | 0.0563 |
| 1 | 10 | 0.1877 |
| 2 | 45 | 0.2816 |
| 3 | 120 | 0.2503 |
| 4 | 210 | 0.1460 |
These add to . So the chance of passing with 5 or more right is , about one in 13.
The chance of at least one right answer is easier through the complement. All ten wrong has chance , so .
2. Waiting for a six. Roll a die until the first six. The chance that it comes within six rolls is one minus the chance that all six rolls miss:
The same complement works for every : for the geometric law.
Try it yourself. On the board at , what is the chance of exactly 5 rights? , the middle bin.
Where you’ll meet this
Counts of defects. A machine makes parts that are faulty with chance , each independently. The number of faulty parts in a box of follows , and a factory sets its checks by it.
Data links. A packet sent over a noisy link arrives or is lost. Out of packets, the number lost is binomial, and the number of tries until one gets through is geometric. Bit errors in a word of bits follow the same binomial law.
Retries. Any “try until it works” loop, from a phone redialling to a program retrying a server, counts its attempts with the geometric law.
In signal processing · a train of impulses
A pmf is a row of spikes: height at each value , nothing in between. In the signal processing course this is a train of scaled impulses. Adding two independent counts will turn out to convolve their pmfs, the subject of Sums of random variables.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Random variable | a number attached to each outcome | capital , values |
| Probability mass function | ||
| Distribution function | climbs in steps from 0 to 1 | |
| Bernoulli | 1 with chance , 0 with chance | one try |
| Binomial | , | successes in independent tries |
| Geometric | , | tries until the first success |
| Discrete uniform | on values | a fair die |