Bernoulli trials
A Bernoulli trial is an experiment with two outcomes, called success and failure. Success has probability , a number from 0 to 1, and failure .
"Success" is only a label for the outcome being counted. A coin landing heads (), a die showing a six () and a part failing its test are all Bernoulli trials.
Rule: Bernoulli distribution
is 1 for a success and 0 for a failure, so it counts successes in one trial. The second line packs both cases into one formula, for or 1.
With or there is no chance involved: the trial always fails, or always succeeds.
The binomial distribution
Now repeat the trial times. The trials are independent and each has the same . Let be the number of successes; it can be any whole number from 0 to .
Take and . By independence (lesson 5.1.3), the probability of a sequence is the product of its trials' probabilities: has .
| sequences | successes | each sequence | |
|---|---|---|---|
| 0 | 0.216 | ||
| , , | 1 | ||
| , , | 2 | ||
| 3 | 0.064 |
Every sequence with successes has the same probability, . The number of such sequences is the number of ways to choose which of the trials succeed: , from lesson 5.1.2. Here .
Rule: Binomial distribution
The count of successes in independent trials, each with success probability . We write , read " has the binomial distribution with trials and probability ". A Bernoulli trial is the case .
Ten trials with
For and , three successes have probability . The whole pmf, to four decimals:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
|---|---|---|---|---|---|---|---|---|---|
| 0.0282 | 0.1211 | 0.2335 | 0.2668 | 0.2001 | 0.1029 | 0.0368 | 0.0090 | 0.0014 |
has probability 0.0001, and rounds to 0. The distribution function of lesson 5.2.1 adds up from the left: . At the other end, .
Try it
The first line is the table for and . Then the cell computes for from the formula, with math.comb. binom.pmf, binom.cdf and binom.sf from scipy.stats give , and .
Then 100,000 runs of 10 trials, with a fixed seed: each row of trials is one run. In this run the three shares are within 0.001 of the exact answers.
binom.sf(4, n, p) is , which is . To get , ask for binom.sf(k - 1, n, p).
None, all and at least one
Three cases come up often and need no counting. No successes means every trial fails, and all successes means every trial succeeds. "At least one" is the complement of none (lesson 5.1.1).
Rule: None, all, at least one
For 10 trials with , none has probability , and at least one .
A tempting shortcut is wrong. In 10 rolls of a die, the chance of at least one six is , not , which is more than 1.
The shape
With the pmf is symmetric: , because . For , both and have probability 0.1172.
With below one half, the bars pile up on the left, with a long tail to the right. Above one half, the picture is the mirror image.
The failures are a binomial count too: if , then . So for equals for : both are 0.2013.
Try it
The first line checks the symmetry for , the second the mirror between and .
The last line compares at least one six in 10 rolls with the wrong shortcut .
Try it below. Set the interval from 0 to 2 and check ; then move from 0.1 to 0.9 and watch the bars slide across. The dashed line marks the long-run average of , which lesson 5.3.1 defines; lesson 5.3.2 shows it is .
Explore
Each bar is the probability of one value. Change the parameters, then set an interval: the shaded bars add up to its probability.
The dashed line is the mean.
- Probability
- P(2 ≤ X ≤ 4) = 0.7004
- Mean
- 3
- Variance
- 2.1, so the standard deviation is 1.4491
When the binomial does not apply
The binomial needs four things: a fixed number of trials , two outcomes per trial, the same every time, and independent trials. Check each before using it.
Draw two cards from a shuffled deck of 52 without putting the first back, and count the aces. The chance of an ace changes after the first card, so the trials are not independent. By counting (lesson 5.1.2), .
The binomial with and would give : right if the first card goes back, wrong here. Counts from draws without replacement follow the hypergeometric distribution, named here only.
Try it
Cards 0 to 3 are the aces. Sorting 52 random numbers shuffles the deck, one row per shuffle, and the first two columns are the cards drawn.
rng.integers instead draws each card from the full deck, as if the first went back. In this seeded run the shares are 0.00453 and 0.00552, against the exact 0.004525 and 0.005917.
When the number of trials is not fixed in advance, the next section's distribution may be the one you need.
The geometric distribution
Repeat independent trials with success probability until the first success. Let be the number of trials this takes, the success included. can be , with no upper limit.
means failures and then a success. By independence, that has probability .
Rule: Geometric distribution
The number of trials up to and including the first success, for . We write . Each extra trial multiplies the probability by .
Roll a die until a six appears, so . The first six comes on roll 1 with probability , on roll 2 with , and on roll 3 with .
The probabilities add up to 1. They form a geometric series with first term and ratio , whose sum is by lesson 1.5.3. With the series is all zeros: a success never comes.
The tail
means the first trials all fail. So the tail has a short formula, and the distribution function follows from it.
Rule: Geometric tail
For a whole number . The second line is the complement rule, as in lesson 5.2.1.
With a die, : about one time in three, six rolls bring no six. And , so a six arrives within four rolls about half the time: lesson 5.1.3's chance of at least one six in 4 rolls.
The number of rolls up to the first six. Each bar is of the one before. The highlighted tail, which goes on past 24, holds of the probability.
How many rolls make you 95% sure of a six? You need , so by lesson 1.4.4. Seventeen rolls are enough: , while is not yet below 0.05.
Trials or failures?
Some books and libraries count the failures before the first success instead, , with values and . Check which one a formula uses. scipy.stats.geom and NumPy's rng.geometric both count trials, like this lesson.
Try it
geom.pmf, geom.sf and geom.cdf give the probabilities above. loc=-1 shifts the values down by 1, to count failures: for .
The last lines roll until a six 100,000 times with a fixed seed. In this run 0.3344 of the runs need more than six rolls, and the smallest count is 1, as it must be.
Lesson 5.2.3 lets the number of trials grow while successes become rare, which gives the Poisson distribution. Lesson 5.4.2 meets the continuous version of a waiting time, and case study 5.2.5 counts defaults in a loan portfolio with the binomial.
Common mistakes
- Do not forget . Exactly two sixes in five rolls has probability , not 0.0161: there are ten orders.
- "At least one" is , not . The product can exceed 1.
sf(k)is . For usesf(k - 1).- Check that the trials are independent with the same . Cards drawn without replacement are not binomial.
- Trials or failures? A geometric formula may count trials (from 1) or failures before the first success (from 0).
- The geometric tail has in the power. ; is the single value .
Bernoulli, binomial and geometric distributions
0 of 12 correct
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
How to type answers
- Powers with
^:x^7,2^(1/3),a^-2. - Multiply with
*or by writing side by side:3x^2,2(x+1). ln(x)is the natural log,log(x, 2)is log base 2,eis Euler's number,sqrt(x)is a square root.sin(x),cos(x)andtan(x)take radians; writepifor π andsin(x)^2for sin²x.- Your first answer to each question is saved: it counts towards your score and brings the question back for review.
- Exact answers like
ln(20)/ln(3)are best. Decimals need about 4 significant figures.
Summary card
- A Bernoulli trial succeeds with probability : , .
- The number of successes in independent trials with the same is : for .
- and . The pmf is symmetric for , and .
- The number of trials up to the first success is : for , with tail .
- In
scipy.stats,binomandgeom(which counts trials) have.pmf,.cdfand.sf;sf(k)is .