liveBook · Manning

Binomial distribution

As explained in Statistics Every Programmer Needs

A binomial distribution gives the probabilities of the number of successes in a fixed number of independent binary trials with a common success probability.

A binomial distribution models the number of successes in a fixed number of repeatable trials. Each trial has two outcomes, success or failure, and shares the same success probability. section 3.1.2

Validate these assumptions before applying the model:

  • Fix the number of trials in advance. section 3.1.2
  • Require independence: one trial neither changes subsequent outcomes nor depends on previous outcomes. section 3.1.2
  • Classify every outcome as success or failure, with success probability p and failure probability 1 − p. section 3.1.2
  • Keep p constant across all trials; the trials must be alike as well as independent. section 3.1.2

The probability mass function assigns a probability to each possible number k of successes. It combines the number of ways to choose those successes with the probability of each resulting sequence: C(n,k)p^k(1−p)^(n−k). section 3.1.2

Calculate seven successes in twenty trials

For n = 20, k = 7, and p = 0.5, the binomial coefficient is 77,520 and the resulting probability is 7.39288330078125%. Changing p to 0.2 gives 5.454985048652523% through scipy.stats.binom.pmf(k, n, p).

Figure 3.4 A first pair of binomial distributions where the probability of success equals 0.20 (on the left) and 0.50 (on the right), given 20 independent trials. Although the distributions are binomial, the data is nonetheless distributed normally.
figure

Compare distributions across twenty trials as p changes from 0.20 to 0.50; the plotted shape and location illustrate how the success probability affects outcomes. section 3.1.2

How Statistics Every Programmer Needs covers it

How deep it goes
Defines assumptions, parameters, the probability mass function, manual calculations, SciPy implementation, and plotted comparisons.
Examples
Uses coin flips, quality-control pass/fail inspections, medical test results, binary surveys, and twenty-trial probability calculations.
What it assumes
Builds from probability, counting rules, combinations, discrete random variables, and probability distributions.
What you can do after
Apply it via NumPy and SciPy to calculate and visualize probabilities for specified numbers of successes.
How it connects
Connects random variables, discrete random variables, probability mass functions, probability distributions, and normal distributions.

Also explained in

Compare how 6 books explain binomial distribution →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.