Binomial Distribution

Chien
5 min readFeb 24, 2024

--

The binomial distribution represents a discrete probability distribution that applies to experiments characterized by two mutually exclusive outcomes, often called Bernoulli trials. It is utilized in sequences of independent trials where only two possible outcomes exist.

The Binomial Distribution has four attributes:

  1. Each experiment involves a sequence of n repeated trials.
  2. 2. Every trial can result in one of two possible outcomes.
  3. 3. The probability of success in any given trial is constant, denoted by p, which implies that the probability of failure is consistently q=1-p.
  4. 4. Trials are mutually independent, meaning the outcome of one trial does not influence the outcome of another.

The formula of Binomial Distribution

  • p(x): The probability of achieving a specific number of successes.
  • X: The specific number of successes desired.
  • N: The total number of trials conducted.
  • p: The probability of success in a single trial.
  • q: The probability of failure in a single trial, where q=1−p.

For example

Given a coin flip where the probability of obtaining heads is 1/2 and the probability of obtaining tails is also 1/2. If the coin is tossed five times, what is the probability of achieving two heads and three tails?

from math import comb

N = 5
X = 2
p_heads = 1/2
p_tails = 1/2

# The binomial probability formula
# P(X) = C(N, X) * (p^X) * ((1-p)^(N-X))
probability = comb(N, X) * (p_heads ** X) * (p_tails ** (N - X))

# result: 0.3125

The binomial distribution chart is symmetric

The Shape of the Binomial Distribution

The shape of the binomial distribution changes based on the probability of success (p) for flipping a coin and getting heads:

  • When p = 0.5, the distribution is symmetrical.
  • If p > 0.5, the distribution shows a negative skew.
  • If p < 0.5, the distribution shows a positive skew.

The degree of skewness increases as the probability (p) moves away from 0.5. However, with enough trials, the distribution approximates a normal distribution, regardless of p and q values. According to Howell, D. C. (2013), the distribution nears normalcy when both Np​ and Nq​ exceed 5.

For example: Negative Skew

Now, if a coin is flipped where the probability of landing heads is 3/4 and the probability of landing tails is 1/4, and the coin is tossed five times, what is the probability of getting exactly two heads and three tails?

from math import comb

N = 5
X = 2
p_heads = 3/4
p_tails = 1/4

# The binomial probability formula
# P(X) = C(N, X) * (p^X) * ((1-p)^(N-X))
probability = comb(N, X) * (p_heads ** X) * (p_tails ** (N - X))

# result: 0.087890625

The binomial distribution chart is non-symmetric (negative skew)

For example: Positive Skew

If a coin is flipped where the probability of landing on heads is 1/4 and the probability of landing on tails is 3/4. When the coin is tossed five times, what is the probability of getting exactly two heads and three tails?

from math import comb

N = 5
X = 2
p_heads = 1/4
p_tails = 3/4

# The binomial probability formula
# P(X) = C(N, X) * (p^X) * ((1-p)^(N-X))
probability = comb(N, X) * (p_heads ** X) * (p_tails ** (N - X))

# result: 0.263671875

The binomial distribution chart is non-symmetric (positive skew)

Mean and Variance of the Binomial Distribution

Mean of the Binomial Distribution

The mean (or expected value) of a binomial distribution, denoted as μ, gives the average number of successes that can be expected over n trials. It is calculated using the formula:

μ = n × p

  • n is the number of trials,
  • p is the probability of success on a single trial.

Variance of the Binomial Distribution

The variance of a binomial distribution, denoted as σ², measures the spread of the distribution, or how much the number of successes in n trials is likely to deviate from the mean. The variance is calculated with the formula:

σ² = n × p × (1−p)

  • n is the number of trials,
  • p is the probability of success on a single trial,
  • 1−p represents the probability of failure (denoted as q, with q=1−p).

For example

flipping a coin 20 times where the probability of landing heads (success) is p = 1/4 and tails (failure) is q = 3/4. In this context, “success” is defined as flipping heads. What is the probability of heads flipped is more than 8?

Np​ = 20 × 1/4 = 5 and Nq​ = 20 × 3/4 = 15 → fit “the distribution nears normalcy when both Np​ and Nq​ exceed 5 by Howell, D. C.”

  • μ = n × p = 20 × 1/4 = 5
  • σ² = n × p × (1−p) = 20 × 1/4 × 3/4 = 3.75

Use mean = 5 and variation = 3.75 to draw a chart. The number of heads flipped is more than 8 is highlighted in orange.

The standard score (Z-score) for obtaining 8 heads in the scenario of flipping a coin 20 times is approximately 1.55.

from math import sqrt

N = 20
p = 0.25
q = 1 - p

mean = N * p
variance = N * p * q
std_deviation = sqrt(variance)

successes = 8

# Calculate the Z-score
z_score = (successes - mean) / std_deviation

#result: 1.5491933

By referring to the Z-score table, the probability of obtaining more than 8 heads in a series of coin flips, corresponding to a Z-score of approximately 1.55 in a standard normal distribution, is approximately 6.07%.

Reference:

[1] Howell, D. C. (2013). Statistical methods for psychology. Wadsworth, Cengage Learning.

--

--