In this post, you will learn about the concepts of negative binomial distribution explained using real-world examples and Python code. We will go over some of the following topics to understand negative binomial distribution:
Negative binomial distribution is a discrete probability distribution representing the probability of random variable, X, which is number of Bernoulli trials required to have r number of successes. This random variable is called as negative binomial random variable. And, the experiment representing X number of Bernoulli trials required to product r successes is called as negative binomial experiment. Let’s understand the concept with the example of tossing a coin. Let’s say we want to continue flipping the coin until 3 heads come. This experiment of flipping a coin until 3 heads (r=3) come can be called as negative binomial experiment. And, the number of times the coin need to be flipped in each experiment represent the value of negative binomial random variable, X.
The negative binomial experiment would have the following properties:
The negative binomial distribution can be represented as the following when X represents the number of trials needed to get r successes where the probability of success in each trial is P.
[latex]\Large B^{*}(X; r, P)[/latex]
.
The expected value / mean of the negative binomial distribution is defined as the expected / mean number of trials required to achieve r successes where the probability of success is P.
[latex]\Large \mu_{X} = \frac{r}{P}[/latex]
.
Negative binomial distribution definitions vary with the definition of negative binomial random variable. Here are different definitions of the negative binomial random variable:
[latex]\Large \mu_{X} = k*\frac{P}{(1-P)}[/latex]
.
[latex]\Large \mu_{X} = r*\frac{1-P}{P}[/latex]
.
To understand the difference between binomial and negative binomial distribution, lets understand the difference between binomial and negative binomial experiment.
Binomial experiment is getting number of successes in N number of Bernoulli trials. The binomial random variable is number of successes. In binomial distribution, the number of trials are fixed.
Negative binomial experiment is about performing Bernoulli trials until r successes is achieved. The negative binomial random variable, X, is number of trials which are required to achieve r successes. In negative binomial distribution, the number of trials are not fixed.
In both the above cases, the following properties holds good:
Here are some real-world examples of negative binomial distribution:
Here is the Python code representing negative binomial distribution. Pay attention that Scipy.stats nbinom can be used to calculate probability distribution.
import numpy as np
from scipy.stats import nbinom
import matplotlib.pyplot as plt
#
# X = Discrete negative binomial random variable representing number of sales call required to get r=3 leads
# P = Probability of successful sales call
#
X = np.arange(3, 30)
r = 3
P = 0.1
#
# Calculate geometric probability distribution
#
nbinom_pd = nbinom.pmf(X, r, P)
#
# Plot the probability distribution
#
fig, ax = plt.subplots(1, 1, figsize=(8, 6))
ax.plot(X, nbinom_pd, 'bo', ms=8, label='nbinom pmf')
ax.plot(X, nbinom_pd, 'bo', ms=8, label='nbinom pmf')
plt.ylabel("Probability", fontsize="18")
plt.xlabel("X - No. of Sales Call", fontsize="18")
plt.title("Negative Binomial Distribution - No. of Sales Call Vs Probability", fontsize="18")
ax.vlines(X, 0, nbinom_pd, colors='b', lw=5, alpha=0.5)
Here is how the negative binomial distribution plot would look like:
Here is the summary of what you learned in this post regarding negative binomial distribution:
In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…
Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…
With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…
Anxiety is a common mental health condition that affects millions of people around the world.…
In machine learning, confounder features or variables can significantly affect the accuracy and validity of…
Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…