Day 4 - Binomial and geometric distributions
Binomial distribution
Problem 1
The ratio of boys to girls for babies born in Russia is \(r=\frac{N_b}{N_g}=1.09\). If there is 1 child born per birth, what proportion of Russian families with exactly 6 children will have at least 3 boys?
Mathematical explanation
Let's first compute the probability of having a boy :
where: * \(N_b\) is the number of boys * \(N_g\) is the number of girls * \(r=\frac{N_b}{N_g}\)
r = 1.09
p_b=r/(r+1)
print(f"The probability of having a boy is p={p_b:3f}")
The probability of having a boy is p=0.521531
The probability of getting 3 boys in 6 children is given by :
In order to compute the proportion of Russian families with exactly 6 children will have at 3 least boys we need to compute the cumulative probability distribution
Let's code it !
import math
def bi_dist(x, n, p):
b = (math.factorial(n)/(math.factorial(x)*math.factorial(n-x)))*(p**x)*((1-p)**(n-x))
return(b)
b, p, n = 0, p_b, 6
for i in range(3,7):
b += bi_dist(i, n, p)
print(f"probability of getting at least 3 boys in a family with exactly 6 children : {b:.3f}")
probability of getting at least 3 boys in a family with exactly 6 children : 0.696
Problem 2
A manufacturer of metal pistons finds that, 12% on average, of the pistons they manufacture are rejected because they are incorrectly sized. What is the probability that a batch of 10 pistons will contain: * No more than 2 rejects? * At least 2 rejects?
Mathematical explanation
On average 12% of the pistons are rejected, this means that a piston has a probability of \(p_{rejected}=0.12\) to be rejected.
The probability of getting less than 2 faulty pistons in a batch is :
b, p, n = 0, 12/100, 10
for i in range(0,3):
b += bi_dist(i, n, p)
print(f"The probability of getting less than 2 faulty pistons in a batch is : {b:.3f}")
The probability of getting less than 2 faulty pistons in a batch is : 0.891
The probability that a batch of 10 pistons will contain at least 2 rejects :
b, p, n = 0, 12/100, 10
for i in range(2,11):
b += bi_dist(i, n, p)
print(f"The probability of getting at least 2 faulty pistons in a batch is : {b:.3f}")
The probability of getting at least 2 faulty pistons in a batch is : 0.342
Geometric distribution
Problem 1
The probability that a machine produces a defective product is \(\frac{1}{3}\). What is the probability that the first defect is found during the fith inspection?
Mathematical explanation
In this case, we will use a geometric distribution to evaluate the probability : * \(n=5\) * \(p=\frac{1}{3}\)
Hence, the probability that the first defect is found during the fith inspection is \(g(n=5,p=1/3)\)
print(f"The probability that the first defect is found during the fith inspection is {round(((1-p)**(n-1)) * p, 3)}")
The probability that the first defect is found during the fith inspection is 0.038
Problem 2
The probability that a machine produces a defective product is \(\frac{1}{3}\). What is the probability that the first defect is found during the first 5 inspections?
Mathematical explanation
In this problem, we need to compute the cumulative distribution function
p_x5 = 0
p=1/3
n=5
for i in range(1,n+1):
p_x5+=(1-p)**(i-1) * p
print(f"The probability that the first defect is found during the first 5 inspection is {round(p_x5, 3)}")
The probability that the first defect is found during the first 5 inspection is 0.868