1. Concepts & Definitions
1.2. Central Limit Theorem (CLT)
1.5. Confidence interval and normal distribution
1.6. Applying normal confidence interval
1.7. Normal versus Student's T distributions
1.8. Confidence interval and Student T distribution
1.9. Applying Student T confidence interval
1.10. Estimating sample size using normal distribution
1.11. Estimating sample size using Student T distribution
1.12. Estimating proportion using samples
2. Problem & Solution
2.1. Confidence interval for weight of HS6 code
The next code helps to compute the sample size n necessary to compute the confidence interval to estimate the mean weight of some products employing the data set of HS6 code.
The first part of the code employs the code developed in Track 07 - section 2.1 which resulted in the following code:
https://colab.research.google.com/drive/1Xo-2dWDgL-gmDJH3QmB6b4YMlntgQqtu?usp=sharing
The next code includes the code based on the estimation of sample size n using a Margin of error equal to 4000. The concept and code related to computing sample size n employs the discussion made in Track 07 - section 2.10.
from scipy.stats import norm
p = 0.90 # Confidence level: population percentage covered by the interval
muz = 0 # mean of the standard normal
sigmaz = 1 # standard deviation of standard normal
alfa = 1-p # obtaining the significance level: alpha
pr = 1-alfa/2 # percentage of the population higher than the critical level z
z = norm.ppf(pr, muz, sigmaz) # computing the critical z alpha/2
s = std_sample # compute the standard deviation of the sample
# Range of the confidence interval
W = 4000
# Finally the final sample size n.
n = round((2*z*s/W)**2,0)
n = int(n)
print('Sample size = ',n)
Sample size = 100
The previous complete code is available in the following link:
https://colab.research.google.com/drive/18XhGkxYDJE7qC3zYLCfatdgWoF_uwoFo?usp=sharing