1. Concepts & Definitions
1.1. Example of random variables
1.2. Probability of events to random variables
1.4. Discrete uniform distribution of probability
1.5. Bernoulli distribution of probability
1.6. Binomial distribution of probability
1.7. Hypergeometrical distribution of probability
2. Problem & Solution
It is denoted as X ∼ B(n, p). And is read as X is a discrete random variable that follows Binomial distribution with parameters n, p. Where n is the number of trials, and p is the success probability for each trial.
The binomial distribution is a discrete probability distribution of the number of successes in the ‘n’ independent experiments sequence. The two outcomes of a Binomial trial could be Success/Failure, Pass/Fail, and Win/Lose.
Generally, the outcome success is denoted as 1, and the probability associated with it is p. And Failure is denoted as 0, and the probability associated with it is q = 1-p.
The Binomial distribution PMF formula follows:
In certain customs, it was verified that 5% of the products of a company have documentation problems. A customs inspector randomly selects 2 products. Find the probabilities of the following events:
1. EO is the event that “exactly one of them has a problem”?
2. AO is the event that “And at least 1”?
The next Figure illustrates the inspection problem described before. The success event (S) corresponds to finding a product with a documentation issue, and the unsuccess event (U) corresponds to not finding it. Each stage is a product selection and the result column gives the corresponding joint probability for each combination of events. The column p(x) gives the probability to achieve a certain number of successful events. The sum of joint probabilities and p(x) are equal to 1.
Use the previous equation to compute the probabilities with n = 2 (number of trials), p = 0.05 (success probability to find an issue), q = 0.95 (unsuccess probability of not finding an issue):
• Find exactly one issue:
p(x = 1) = 2(0.05)(0.95) = 0.095
• Find at least one issue is to find: P(x ≥ 1).
Observe that p(x = 0) + p(x = 1) + p(x = 2) = 1 .
Then p(x = 0) + P(x ≥ 1) = 1 leads to P(x ≥ 1) = 1 − p(x = 0). Now, compute p(x = 0): p(x = 0) = 0.9025.
Finally: P(x ≥ 1) = 1 − 0.9025 = 0.0975.
The following code shows how to compute binomial probabilities employing PMF of Binomial distribution using binom.pmf command.
from scipy.stats import binom
import matplotlib.pyplot as plt
import numpy as np
#creating an array of values between
#0 to 20 with a difference of 1
x = np.arange(0, 20, 1)
y = binom.pmf(x, 20, 0.5)
plt.plot(x,y,'r-',x, y,'bo')
plt.show()
plt.bar(x, y)
plt.show()
The following code shows the probability of the numerical example employing PMF of Binomial distribution using binom.pmf command.
from scipy.stats import binom
import matplotlib.pyplot as plt
import numpy as np
# computing P(X) for each X.
x = [0, 1, 2]
y = binom.pmf(x, 2, 0.05)
print(' X |',x)
print('P(X) |',y)
X | [0, 1, 2]
P(X) | [0.9025 0.095 0.0025]
The previous complete code is available in the following link:
https://colab.research.google.com/drive/1IVtHZ1uhOmrkwL0JtTBxtW0wCrFVhpfM?usp=sharing