Learn · Chapter 5

The binomial distribution

The four conditions, the formula, its mean and variance, and the off-by-one trap.

Counting successes

Many business questions count how often something happens in a fixed number of tries: how many of 20 doses are unsatisfactory, how many of 12 customers open an e-mail, how many of 10 bulbs are faulty. The binomial distribution is the model for that count when four conditions hold:

  • A fixed number of trials, \(n\), decided in advance.
  • Two outcomes for each trial, called success and failure. A "success" is simply the outcome being counted, such as a faulty bulb.
  • The same probability of success, \(p\), on every trial.
  • Independent trials: the outcome of one trial does not change the chances of another.

Then \(X\), the number of successes, is binomial: \(X \sim B(n, p)\).

Deriving the formula

A vaccine maker, Brambleford, finds that each dose is unsatisfactory with probability \(p = \tfrac{1}{3}\). Take a batch of \(n = 10\) doses. One way to get exactly 3 unsatisfactory doses is for the first three to be unsatisfactory and the other seven fine; by independence, that has probability \(\left(\tfrac{1}{3}\right)^3 \left(\tfrac{2}{3}\right)^7 = 0.0021677\). Every other arrangement of 3 unsatisfactory doses among the 10 has the same probability, and there are \(\binom{10}{3} = 120\) of them, so

In general, the number of ways to choose which \(k\) of the \(n\) trials are the successes is the binomial coefficient, and

k = 3

P(X ≤ 3) = 0.5593

Open this set-up in the explorer
Brambleford: unsatisfactory doses in a batch of 10, each with probability 1/3, with P(X ≤ 3) shaded

Use 1/3, not 0.33

The probability is one in three, and it should be entered as 1/3. Rounding it to 0.33 looks harmless but moves the answers: \(P(X = 3)\) becomes 0.2614 instead of 0.2601, \(P(X \le 3)\) becomes 0.5684 instead of 0.5593, and for a batch of 20 the chance of 11 or more unsatisfactory doses falls from 0.0376 to 0.035. The error is small in the middle and grows in the tails, which is where quality decisions are made.

Mean, variance and shape

A batch of 10 doses has on average \(10 \times \tfrac{1}{3} = 3.3333\) unsatisfactory doses, with variance \(10 \times \tfrac{1}{3} \times \tfrac{2}{3} = 2.2222\) and standard deviation 1.4907. The shape depends on \(p\): skewed to the right when \(p < 0.5\), symmetric at \(p = 0.5\), skewed to the left above it, and closer to a bell as \(n\) grows. A Galton board shows why: each ball makes \(n\) left-or-right bounces, and its bin counts the bounces to the right.

Try this Drop balls through 10 rows of pegs and watch the bins fill up to the binomial's bars.

Words to probabilities, and the off-by-one trap

The formula is the easy part; the words are where answers go wrong. For a count, the boundary value carries probability, so turn each phrase into an exact set of values before writing any code:

Turning words into the values they count
The wordsThe valuesscipyExcel
exactly 3P(X = 3)binom.pmf(3, n, p)=BINOM.DIST(3, n, p, FALSE)
at most 3, no more than 3P(X ≤ 3)binom.cdf(3, n, p)=BINOM.DIST(3, n, p, TRUE)
fewer than 3P(X ≤ 2)binom.cdf(2, n, p)=BINOM.DIST(2, n, p, TRUE)
at least 3P(X ≥ 3) = 1 − F(2)binom.sf(2, n, p)=1-BINOM.DIST(2, n, p, TRUE)
more than 3P(X ≥ 4) = 1 − F(3)binom.sf(3, n, p)=1-BINOM.DIST(3, n, p, TRUE)
between 3 and 6, both includedP(3 ≤ X ≤ 6)binom.cdf(6, n, p) - binom.cdf(2, n, p)=BINOM.DIST(6, n, p, TRUE)-BINOM.DIST(2, n, p, TRUE)

The Brambleford batch of 20 shows the trap. "At least 11 unsatisfactory" is \(P(X \ge 11) = 1 - F(10) = 0.0376\); writing binom.sf(11, 20, 1/3) instead computes \(P(X > 11)\) and leaves out the bar at 11.

A sentence can also count the other outcome. "At least 13 of the 20 doses are satisfactory" means at most 7 are unsatisfactory, so with \(X\) counting the unsatisfactory doses the answer is \(P(X \le 7) = 0.6615\). Decide once what \(X\) counts, and turn every sentence into that count.

Try this Practise turning sentences into inequalities, scipy calls and Excel formulas, checked as you go.

E-mail opens and LED bulbs

A newsletter goes to 12 customers, each of whom opens it with probability 0.25, independently. The expected number of opens is \(12 \times 0.25 = 3\), the chance of 4 or more is \(P(X \ge 4) = 1 - F(3) = 0.3512\), and the chance that nobody opens it is \(0.75^{12} = 0.0317\).

A maker of LED bulbs knows that 5 % of its bulbs are faulty. In a box of 20, the chance of at most one faulty bulb is \(P(X \le 1) = 0.7358\), so about one box in four has two or more.

k = 1

P(X ≤ 1) = 0.7358

Open this set-up in the explorer
LED bulbs: faulty bulbs in a box of 20, each faulty with probability 0.05, with P(X ≤ 1) shaded

When the binomial is the wrong tool

  • Sampling without replacement from a small group. Dealing 5 cards from one deck changes the chances after every card, so \(p\) is not constant (the hypergeometric distribution fits). With a large population and a small sample, the binomial is a fine approximation.
  • Trials that affect each other. Infections that spread, customers who talk to each other, or bulbs from one faulty production run are not independent, and the binomial understates the chance of many failures at once.
  • Chances that differ. If some customers are far more likely than others to open an e-mail, a single \(p\) for all of them misstates the spread.
  • No fixed \(n\). Calls per hour and defects per metre have no number of trials: that is the Poisson distribution of chapter 6.

In code

What it computes Python (scipy.stats) Excel
P(X = 3) for a batch of 10 binom.pmf(3, 10, 1/3) =BINOM.DIST(3, 10, 1/3, FALSE)
P(X ≥ 11) for a batch of 20 binom.sf(10, 20, 1/3) =1-BINOM.DIST(10, 20, 1/3, TRUE)
At least 13 of 20 satisfactory binom.cdf(7, 20, 1/3) =BINOM.DIST(7, 20, 1/3, TRUE)
The mean and the variance binom.mean(10, 1/3), binom.var(10, 1/3) =10*(1/3)
The number of arrangements math.comb(10, 3) =COMBIN(10, 3)
Remember: Use the binomial for the number of successes in \(n\) independent trials with the same \(p\). Enter \(p\) exactly: 1/3, not 0.33. Turn the words into the exact set of values first, then choose pmf, cdf or sf: "at least \(k\)" is binom.sf(k - 1, n, p).

Quiz

Three questions on the chapter. Your best score is kept in this browser.

1. Which of these counts is not binomial?
2. With \(X \sim B(20, 1/3)\) counting unsatisfactory doses, which call gives the chance that at least 11 are unsatisfactory?
3. Each dose in a batch of 20 is unsatisfactory with probability 1/3. What is the chance that at least 13 are satisfactory?
Answer every question first.
Probability foundations · step 9 of 10

The binomial and the off-by-one trap

The four conditions first, then Brambleford with p = 1/3, not 0.33. Put the words-to-values table on the screen: at least 11 is 1 − F(10), which binom.sf(10, 20, 1/3) computes. Ask what at least 13 satisfactory doses of 20 means in unsatisfactory ones.

All steps
An unhandled error has occurred. Reload 🗙

Reconnecting…

Your connection to Introduction to Probability Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.