Table of contents
1.
Introduction
2.
Definition
2.1.
Properties of the binomial random variable
3.
Mean and Variance
4.
Probability mass function
5.
Cumulative distribution function
6.
Solved Examples
7.
Frequently Asked Questions
7.1.
What does the binomial distribution depend on?
7.2.
How is the binomial distribution used in real life?
7.3.
Which random variables are not binomial?
7.4.
What is an example of the binomial experiment?
8.
Conclusion
Last Updated: Oct 17, 2024

Binomial Random Variable

Author soham Medewar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Before going on to the topic, let us understand random variables. A random variable, usually written as X. Random variable, is a variable whose possible values are numerical outcomes of a random phenomenon. The binomial random variable is a special type of discrete random variable.

Binomial Random Variable

Before going on to the topic, let us understand random variables. A random variable, usually written X, is a variable whose possible values are numerical outcomes of a random phenomenon.

Definition

In statistics and probability, the binomial distribution with parameters p and n is the discrete probability distribution of a sequence of successes of n independent experiments. Each is asking a yes or no question. Each has its Boolean-valued outcome, where the probability of success is p, and the probability of failure is q (q = 1-p). A single success/failure experiment is also called a Bernoulli trial or Bernoulli experiment. A sequence of outcomes is called a Bernoulli process; the binomial distribution is a Bernoulli distribution for a single trial.

Properties of the binomial random variable

  • There are a finite number of trials in a binomial experiment(let the number of trials be n).
  • All the trials must be independent.
  • Each trial has exactly two possible outcomes, i.e., success or failure.
  • The probability of success is constant for all the trials, i.e., p.

The number of successes(r) in n successive independent trials of a Bernoulli experiment is called a binomial random variable.

Mean and Variance

If X is a binomially distributed random variable, where p is the probability of success and q is the probability of failure and n is the number of trials.
Mean of X = E(X) = np
Variance of X = Var(X) = npq

Probability mass function

The probability of achieving r success in n trials will be(if success is r, then failures will be n-r):
Probability: p(1 - p)n - r

The total number of ways to achieve “r” successes is:
nCr = n! / ((n - r)!*r!)

Therefore, the probability mass function or total probability of achieving r successes and n-r failures is:
p.m.f =  (n! / ((n - r)!*r!))*(p(1 - p)n - r)

Example

Let us understand the probability mass function by a small example. Consider a coin-tossing experiment of a biased coin if the coin is tossed 10 times and the probability of getting head is 0.58. Suppose getting head is considered a success then, create the binomial distribution table that will contain the probability of r successes for each possible value of r.

r012345678910
P(r)

0.00017

 

0.0023

 

0.0146

 

0.0539

 

0.1304

 

0.2161

 

0.2487

 

0.1963

 

0.1016

 

0.0311

 

0.0043

 

Let us use scipy and matplotlib library to draw the table and to plot the distribution.

Code

from scipy.stats import binom
import matplotlib.pyplot as plt

n = 10
p = 0.58
# defining the list of r values
r_values = list(range(n + 1))
# obtaining the mean and variance 
mean, var = binom.stats(n, p)

# list of pmf values
dist = [binom.pmf(r, n, p) forin r_values ]

# printing the table
print("r\tp(r)")
forin range(n + 1):
    print(str(r_values[i]) + "\t" + str(dist[i]))
# printing mean and variance
print("mean = "+str(mean))
print("variance = "+str(var))

# plotting the distribution
plt.scatter(r_values, dist, color = "red")

Output

r p(r)
0 0.00017080198121677845
1 0.002358694026326941
2 0.014657598592174546
3 0.0539771884664206
4 0.13044487212718306
5 0.21616578809647477
6 0.24876221646022886
7 0.19630215720671115
8 0.10165647426776102
9 0.031196166706508714
10 0.004308042068994052
mean = 5.8
variance = 2.436

When the probability of success and failure are equal, then the binomial distribution will be a normal distribution. (change the value of p to 0.5 and plot the graph)

Cumulative distribution function

For a random variable X, X's cumulative distribution function (CDF) calculates the SUM of the probabilities for 0, 1, 2, ... up to the value of X. It calculates the probability of obtaining at most X success in n trials.

Let us take an illustrative example(same question taken for pmf) to plot cumulative distribution function.
p = 0.58
n = 10

Code

from scipy.stats import binom
import matplotlib.pyplot as plt

n = 10
p = 0.58
# defining the list of r values
r_values = list(range(n + 1))

# list of pmf values
dist = [binom.cdf(r, n, p) forin r_values ]

# printing the table
print("r\tcdf")
forin range(n + 1):
    print(str(r_values[i]) + "\t" + str(dist[i]))

# plotting the distribution
plt.scatter(r_values, dist, color = "red")

Output

r cdf
0 0.0001708019812167784
1 0.0025294960075437174
2 0.017187094599718265
3 0.07116428306613881
4 0.2016091551933219
5 0.41777494328979653
6 0.6665371597500251
7 0.8628393169567361
8 0.9644957912244972
9 0.995691957931006
10 1.0

Solved Examples

  1. A coin is tossed 7 times. What is the probability of getting exactly 5 heads? If the coin is unbiased.
    Solution: n = 7
                   r = 5
                   p = 0.5
                   q = 0.5
    Therefore, the probability of getting exactly 5 heads will be:
    7C5.(1/2)5.(1/2)2
    = 21 / 128
    = 0.164
     
  2. A unbiased coin is tossed n times. The probability of occurring head six times is the same as occurring head comes eight times, then find the value of n.
    Solution: P(6) = P(8)
    From the given condition, we can write
    nC6.(1/2)6.(1/2)n - 6nC8.(1/2)8.(1/2)n - 8
    nC6.(1/2)nnC8.(1/2)n
    nC6nC8
    6 = n - 8
    n = 14
    Therefore, the value of n is 14
     
  3. With a 5/7 probability, a person can achieve his target. Total 2 chances are given to a person. What is the total probability that a person can achieve a target at least once?
    Solution: p = 5/7
                   q = 2/7
                   n = 2
    Probability of achieving target at least once = P(1) + P(2)
    2C1.(5/7)1.(2/7)12C2.(5/7)2.(2/7)0
    = 45 / 49
    = 0.9183
    Therefore, the probability of achieving the target is 0.9183

Frequently Asked Questions

What does the binomial distribution depend on?

The binomial distribution is calculated by multiplying the probability of success raised to the power of the number of successes and the probability of failure raised to the power of the difference between the number of successes and the number of trials.

How is the binomial distribution used in real life?

Many instances of binomial distributions can be found in real life. For example, if a new drug is introduced to cure a disease, it either cures the disease (it's successful) or doesn't cure it (a failure). If you purchase a lottery ticket, you're either going to win money, or you aren't.

Which random variables are not binomial?

The random variables which do not have exactly 2 outcomes are not binomial random variables.

What is an example of the binomial experiment?

A binomial experiment is an experiment where you have a fixed number of independent trials with only have two outcomes.

Conclusion

In this article, we have discussed:

  • Definition and properties of binomial distribution
  • Mean and variance of binomial distribution
  • Plotting the binomial distributions p.m.f
  • The cumulative distribution function of binomial distribution

Want to learn more about Machine Learning? Here is an excellent course that can guide you in learning. 

Happy Coding!

Live masterclass