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 ∼ H(N, K, n, k). And is read as X is a discrete random variable that follows hypergeometric with parameter N which is the population size that contains exactly K objects with specific features and k is the number of successes (random draws for which the object drawn has a specified feature) in n draws without replacement. In contrast, the Binomial distribution describes the probability of k successes in n draws with replacement.
The Hypergeometric 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 from a population of 100 products without replacement. 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”?
Use previous equation to compute the probabilities with N = 100 (population size), K = 5 (number of success in population), n = 2 (sample size):
• Find exactly one issue:
p(k = 1) = (5·95)/(100·99/2) = (10·95)/(100·99) = 0.096
• Find at least one issue is to find: P(x ≥ 1). Observe that p(x = 0) + p(x = 1) = 1. Then p(x = 0) + P(x ≥ 1) = 1 leads to P(x ≥ 1) = 1 − p(x = 0). Now, using equation to compute p(k = 0):
p(k = 0) = (95·94/2)/(100·99/2) = (95·94)/(100·99) = 0.9020
Finally: P(x ≥ 1) = 1 − 0.9020 = 0.098.
The following code shows how to compute binomial probabilities employing PMF of Hypergeometric distribution using hypergeom.pmf command.
from scipy.stats import hypergeom
import matplotlib.pyplot as plt
import numpy as np
#creating an array of values between
#0 to n+1 with a difference of 1
# K = Pop. size, K = success cases in pop., n = sample size.
[N, K, n] = [20, 7, 12]
x = np.arange(0, n+1)
y = hypergeom(N, K, n).pmf(x)
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 Hypergeometric distribution using hypergeom.pmf command.
from scipy.stats import hypergeom
import matplotlib.pyplot as plt
import numpy as np
# computing P(X) for each X.
x = [0, 1, 2]
N = 100
K = 5
n = 2
y = hypergeom(N, K, n).pmf(x)
print(' X |',x)
print('P(X) |',y)
X | [0, 1, 2]
P(X) | [0.9020202 0.0959596 0.0020202]
The previous complete code is available in the following link:
https://colab.research.google.com/drive/1fRlaepBYZV5WY-VmfmfPlLhIytQyGG0F?usp=sharing