Sitemap

Binomial Distribution

7 min readMay 23, 2024

--

Here we will try to understand what is Binomial Distribution and how it can be approximated to Normal Distribution.

Pre-Requisites

I assume you are aware of the below terms and principles:

  • Probability Basics
  • Random Variables (Discrete and Continuous)
  • Histograms and Distributions

Let’s Begin 😀

Binomial Distribution

The Binomial distribution is a discrete probability distribution that describes the number of successes in a fixed number of independent and identically distributed Bernoulli trials, each with the same probability of success.

In simpler terms, it models the number of times an event occurs in a given number of trials.

Assumptions of Binomial Distribution

  • Fixed number of trials (e.g. Tossing a coin 10 times)
  • Discrete Outcomes (e.g. Heads or Tails)
  • Two possible outcomes. (e.g. Success and Fail)
  • The events are independent (e.g. Toss in 2nd trial is independent of toss in the first trial)
  • Constant probability of success (i.e. across all the trials the probability of getting a heads is 0.5)

Parameters of the Distribution

Parameters are values that define the specific characteristics and behavior of the distribution.

These parameters are used to specify the shape, spread, and other attributes of the distribution.

Our Binomial Distribution is made up of 2 such parameters

Parameters:

n → number of trials

P → probability of success

The binomial distribution models the number of successes in n independent trials with a success probability p .

Let’s take an example of dice throw.

Lets say we throw the die 7 times in a row. Now we want to find out the probability of getting exactly 3 sixes.

Then the Binomial Distribution can be given as below:

n = Number of fixed trials

k = Number of Success

P = Probability of success

Given the dice roll we can use the above formula to find the probablity of 3 sixes in 7 rolls. But instead of doing it manually we will be using the below python code to solve the same.

from scipy.stats import binom
n = 7
k = 3
p = 1/6 # probablity of getting a 6 (success probablity)
res = binom.pmf(n = n, p = p, k = k)
print(round(res,2))

and the result we get is 0.08 which is approx. 8%

The below code will give us the binomial distribution for this experiment

num_sixes = [i for i in range(0,7)]
prob_sixes = list(map(lambda x: binom.pmf(n = n,p = 1/6, k = x),num_sixes))
plt.bar(num_sixes,prob_sixes)
plt.xlabel('Number of sixes')
plt.ylabel('Probabity of getting a six')
plt.title('Probablity of getting n six in & trials')
plt.show()

So, as per the above distribution we can we that if we roll a die 7 times, we will have ~39% chances of getting 1 six and so on.

Now, it is possible from the above distribution to answer some other questions as well.

Let’s say

What are the chance of getting at least 2 sixes of 7 dice rolls?

Now we can simply add the probabilities of getting sixes greater than equal to 2 and we will have the answer.

P(X ≥ 2) = P(X = 2) + P(X = 3) + P(X = 2) + P(X = 3) + P(X = 2)

prob = 0
for i in range(2,7):
prob += binom.pmf(n = 7, p = 1/6, k = i)
print(round(prob,2))

And we will end up with 33%. Nice!!

Cumulative Probablity Distribution

What we just did can be simplified by using Cumulative Probability Distribution

It describes the probability that a random variable X takes on a value less than or equal to a specific value x.

So basically we are summing up the Probablity of current trial to the previous one and this is how it will look like.

num_sixes = [i for i in range(0,7)]
prob_sixes_cdf = list(map(lambda x: binom.cdf(n = 7,p = 1/6, k = x),num_sixes))
plt.bar(num_sixes,prob_sixes)
plt.xlabel('Number of sixes')
plt.ylabel('Probabity of getting a six')
plt.title('Probablity of getting n six in & trials')
plt.show()

Now instead of adding the probabilities for P(X = 2) to P(X = 6), we can simply find the complement of cumulative probability of P(X = 1)

P(X ≥ 2) = 1 — (cumulative P(X = 1))

res = 1 - binom.cdf(n=7,p=1/6,k=1)
print(round(res,2))

From here as well we will be getting the same response as above i.e. ~33%.

Mean of Binomial Distribution

It tells us the average number of successes in a given number of trials, given the probability of success on each trial.

μ = n*p

Get Saurav Naik’s stories in your inbox

Join Medium for free to get updates from this writer.

How did we get it?

We know from the assumptions of Binomial Distribution that we can have two outcomes i.e. Success and Failure

P(Success) = P

P(Failure) = (1 — P)

Also, we know that throughout all the trials P is going to be the same.

Now from the above let’s say we are doing an experiment like tossing a single coin n times.

In each trial:

P(X = 1) = P

P(X = 0) = 1 — P

So the Expected Value (or Mean) in each trial is :

E[X] = 1 * P * 0 * (1 — P) = P

We have already defined that our Binomial distribution consists of n such independent trials (another assumption)

Hence:

μ = P + P + P + P + ……n times

μ = n*p

Where

n = Number of fixed trials

p = Probability of Success

How does it help?

In manufacturing, the mean of a binomial distribution can help in assessing the quality of products.

For instance, if a factory produces light bulbs with a 95% success rate (i.e., 95% are not defective), and tests are done on batches of 100 bulbs, the mean number of non-defective bulbs (successes) expected in each batch is:

100 * 0.95 = 95

This information helps in setting quality standards and identifying when a batch deviates significantly from the norm, which could indicate a problem in the production process.

Variance of Binomial Distribution

The variance of a binomial distribution is a measure of the spread or dispersion of the distribution. It tells us how much the number of successes varies around the mean. For a binomial distribution with parameters n (number of trials) and p (probability of success).

Below is the formula:

var = n * p * (1 - p)

How did we get it?

We already know that mean(μ) = n * p

Variance is defined as:
σ² = Var(X) = E[X²] — (E[X])²

Where E[X] is the expected value or simply mean.

To find the variance, we need E(X²), the expected value of the square of X. We use the property of binomial distributions and the fact that:

E(X²) = E[X(X-1) + X]

E[X(X-1)] + E[X]

For a binomial distribution:
E[X(X-1)] = n * p * (n-1) * p = n(n-1)*p² → eq.1

E[X] = n * p → eq.2

combining eq.1 and eq.2:

E[X(X-1) + X] = n(n-1)*p² + n * p

Phew!!! Half way done 😅

Now,

(E[X])² = (n * p)² is a no brainer

We now have both parts of the equation σ² = Var(X) = E[X²] — (E[X])²

combining them

var = n(n-1)*p² + n * p + (n² * p²)

Simplify the expression:
σ² = n * p² * (n-1) + n * p — n² * p²
σ²= n * p² * (n — 1) + n * p — n * p²
σ² = n * p * (p * (n-1) + 1 — p)
σ² = n * p * (p * n — p + 1 — p)
σ² = n * p * (n * p — p + 1 — p)
σ² = n * p * (n * p — p + 1 — p)
σ² = n * p * (n * p — 2 * p + 1)
σ² = n * p * (1 — p)

Thus, the variance of the binomial distribution is:
σ² = n * p * (1 — p)

n = Number of fixed trials

p = Probability of Success of

(1 — p) = Probability of failure (remember Binomial distributions can have only two outcomes Success and Failure)

Now let’s see how it helps us:

Referring to the manufacturing example

Imagine a factory producing screws. Each screw has a probability p = 0.95 of meeting quality standards (success), and the probability of being defective 1 — p = 0.05 (failure). If a batch consists of n = 100 screws, the variance of the number of screws meeting quality standards can be calculated as:

σ² = 100 * 0.95 * 0.05 = 4.75

This variance tells us the extent to which the number of high-quality screws in each batch deviates from the average (which is μ = 95 screws).

A lower variance indicates that the quality control process is consistent, while a higher variance might indicate variability in the manufacturing process that needs to be addressed.

--

--