The binomial distribution

Many questions count successes in n independent trials, each with the same chance p: heads in 10 flips, defective parts in a box of 20, correct guesses on a quiz.

The number of successes X follows the binomial distribution:

P(X = k) = C(n, k) × pᵏ × (1 − p)ⁿ⁻ᵏ

  • pᵏ(1 − p)ⁿ⁻ᵏ is the chance of one particular order of k successes and n − k failures.
  • C(n, k), "n choose k", counts how many such orders there are.

Its mean is n × p and its variance n × p × (1 − p).

from math import comb

n, p = 10, 0.5
for k in range(n + 1):
    prob = comb(n, k) * p ** k * (1 - p) ** (n - k)
    print(k, "heads:", round(prob, 4))
print("mean n*p =", n * p)
Open in compiler

For 10 fair coins, 5 heads is most likely, but only about 25% of the time. Exactly 10 heads happens once in 1,024 tries.

Common mistakes

  • Using it when trials are not independent, or p changes (drawing without replacement from a small group).
  • Forgetting C(n, k): the chance of "HHT" is not the chance of "two heads in three flips".

Quick check

1. C(4, 2) = ?
2. Mean number of sixes in 30 rolls?
3. Which situation is binomial?

Practice problems for this lesson

My notes

Write down what you want to remember from this lesson. Notes are saved on this device as you type, and appear on your dashboard.