Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 37 ยท Probability Distributions

The Binomial Distribution

Learn when to use the binomial distribution, the formula C(n,k) p^k (1-p)^(n-k), its mean and variance, and how to compute probabilities in code.

Suppose you guess every answer on a 5-question multiple-choice quiz with four options each. How likely is it that you pass by getting three or more right? Or: a factory knows that 2% of its bulbs are faulty; what is the chance that a box of 50 contains no faulty bulb? These share one structure, and the binomial distribution handles it.

It builds on discrete random variables and on the multiplication rule for independent events.

When is a variable binomial?

Check four conditions (a handy memory aid is BINS):

  1. Binary: each trial has two outcomes, "success" and "failure".
  2. Independent: trials do not affect each other.
  3. N fixed: the number of trials n is decided in advance.
  4. Same probability: each trial has the same success probability p.

Then X = number of successes in n trials is written X ~ B(n, p).

The formula

Text
P(X = k) = C(n, k) ร— p^k ร— (1 - p)^(n - k)

C(n, k) = n! / (k! (n - k)!) counts the ways to choose which k of the n trials are successes. Each particular arrangement has probability p^k (1-p)^(n-k) by the multiplication rule.

Example: a fair coin

Ten flips, p = 0.5. The probability of exactly 3 heads:

Text
P(X = 3) = C(10, 3) ร— 0.5ยณ ร— 0.5โท = 120 / 1024 = 0.1171875
Python Binomial probabilities from the formula

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For the quiz, P(X โ‰ฅ 3) = 0.087890625 + 0.0146484375 + 0.0009765625 = 0.103515625, about a 10% chance of passing by pure guessing.

Mean and variance

Text
E(X) = n p
Var(X) = n p (1 - p)

For 5 questions with p = 0.25, the expected number of correct guesses is 1.25, and the variance is 5 ร— 0.25 ร— 0.75 = 0.9375.

Shape

The shape depends on p. When p = 0.5 the distribution is symmetric. When p is small it leans right; when p is large, left. As n grows, it looks more and more like a bell curve (see the normal distribution).

Python Plot three binomial distributions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Cumulative probabilities and "at least"

Questions are often "at most", "at least" or "between". Add the individual probabilities, or use the complement:

Text
P(X โ‰ฅ 1) = 1 - P(X = 0)
P(X โ‰ฅ 3) = 1 - [P(0) + P(1) + P(2)]

The bulb example: with p = 0.02 faulty and 50 bulbs, P(no faulty) = 0.98^50, about 0.364.

Python Cumulative probability and a simulation check

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Drawing without replacement from a small group is not binomial, because the probability changes after each draw. If the group is much larger than the sample (a common rule of thumb is at least ten times larger), the binomial is a good approximation.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which situation is binomial?

    Twelve fixed, independent trials, each with success probability 1/6. The others are not counts of successes in a fixed number of independent trials.
  2. 2. X ~ B(20, 0.3). What is E(X)?

    E(X) = n p = 20 ร— 0.3 = 6.
  3. 3. X ~ B(20, 0.3). What is Var(X)?

    Var(X) = n p (1 - p) = 20 ร— 0.3 ร— 0.7 = 4.2.
  4. 4. For a fair coin flipped 10 times, P(exactly 3 heads) equals...

    C(10, 3) = 120 arrangements, each with probability (1/2)^10 = 1/1024.

Summary

  • Binomial: n fixed independent trials, same success probability p; X counts successes.
  • P(X = k) = C(n, k) p^k (1-p)^(n-k).
  • Mean np, variance np(1-p).
  • Use the complement for "at least" questions.
  • Without replacement from a small population, the binomial does not apply exactly.

Next: The Normal Distribution