Probability & Statistics · Binomial distribution

Binomial distribution

The binomial distribution gives the probability of exactly k successes in n independent trials that each succeed with the same probability p: P(X = k) = C(n, k)·pk(1 − p)n−k. On a Galton board each row of pegs is one trial, and the bin a ball lands in counts its right turns.

The binomial distribution in this visualization

Repeat a yes-or-no trial nn times, independently and with the same chance pp of “yes” each time. The number of yeses XX then has the binomial distribution: P(X=k)=(nk) pk(1−p)n−kP(X = k) = \binom{n}{k}\,p^k(1 - p)^{n-k} for k=0,1,…,nk = 0, 1, \dots, n. On the Galton board each row of pegs is one trial and a turn to the right is a yes, so the bin a ball lands in counts its right turns. The outlined bars are the exact probabilities; the balls you drop fill them in as frequencies.

Where do the two factors come from? A ball that ends in bin kk turned right kk times and left n−kn - k times, in some order. Because the turns are independent and pp never changes, every such path has the same probability, one factor per peg: pk(1−p)n−kp^k(1 - p)^{n-k}. The number of such paths is the number of ways to choose which kk of the nn rows are right turns, (nk)\binom{n}{k}; counted peg by peg, each peg is reached from the two above it, which is how Pascal’s triangle adds up. Without those conditions the product need not give a path’s probability. Dealing cards without replacement is the common case: the chance that the next card is a heart depends on the cards already dealt, so the number of hearts in a hand follows a hypergeometric distribution, not a binomial one.

Why is the bin with the most paths not always the most likely? Take 0<p<10 < p < 1. The middle of the board has the most paths, but when p≠1/2p \ne 1/2 each of them is less likely than a path with more of the likelier turn. Split into factors shows the tug of war on a log scale, where the product becomes a sum: the path counts form an arch, one path’s chance is a straight line of slope ln⁡p1−p\ln\frac{p}{1-p}, and the line tilts the arch. Neighbouring bins give the peak exactly: P(k+1)P(k)=n−kk+1⋅p1−p\frac{P(k+1)}{P(k)} = \frac{n-k}{k+1}\cdot\frac{p}{1-p}, which exceeds 1 while k<(n+1)p−1k < (n+1)p - 1. So the most likely count is ⌊(n+1)p⌋\lfloor (n+1)p \rfloor; when (n+1)p(n+1)p is a whole number, it ties with the bin just below.

What are the mean and the spread? Score each yes as 1 and each no as 0; then XX is the sum of nn scores, each with mean pp and variance p(1−p)p(1 - p). Means always add, and for independent trials so do variances: XX has mean npnp and standard deviation np(1−p)\sqrt{np(1 - p)}. For a fixed nn the spread is widest at p=1/2p = 1/2 and shrinks toward zero as pp approaches 0 or 1; at the endpoints every trial gives the same answer. After a run the readout puts the balls’ mean and standard deviation beside these values; they vary from run to run, because the balls are a sample. Once np(1−p)np(1 - p) is no longer small the bars look like a bell, and the central limit theorem says why.

Things to notice

  • A yellow bar above or below its outline is not an error: a run is a sample. A bin that expects about 200 balls typically misses by a dozen or so; as balls add up the bars settle toward the outlines, though any one bar can drift away for a while.

Controls

  • Drag across the bins, or the ▲ under them, to choose a bin; click it or press Enter to light its paths one at a time. Above 400 paths, only a sample of 400 lights up. Afterwards each segment’s width shows the share of the bin’s paths that use it.
  • The first five balls fall slowly: at each peg a random number uu sends the ball right when u<pu < p. Press the key again to pause; the balls already in the bins stay.

Related