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 numerical example is helpful to illustrate how to employ a confidence interval with normal distribution to estimate the population mean for a specific situation.
A company wants to launch a new product, but before deciding the price, you want to know the average price of all such products on the market. for a sample of 21 similar products an average price of US$ 70.5 was obtained and a standard deviation of US$ 4.5 for all products. What is the IC of 90% for the average price?
For this example: n (sample size) = 21, x̄ (sample mean) = 70.5, σ standard deviation of the population (use sample standard deviation s if population standard deviation is unknown) = 4.5, and t α/2, n-1 (critical value) = 1.725.
The interval confidence estimation for the population mean using sample data is given by:
μ = x̄ +- t α/2 * s/(n^0.5).
μ = 70.5 +- 1.725 * 4.5/(21^0.5)
= 70.5 +- 1.725 * 4.5/4.58
= 70.5 +- 1.725 * 0.98
= 70.5 +- 1.69
= [68.81, 72.19]
The next code in Python helps to automate the computation of confidence interval using a normal distribution. This could be easily adapted to any other numerical example which fullfill the same conditions.
from scipy.stats import t
n = 21 # Sample size
df = n - 1 # Degree of freedom
x = 70.5 # Mean od the sample
sigma = 4.5 # Sample standard deviation
p = 0.90 # Confidence level: population percentage covered by the interval
alfa = 1-p # obtaining the significance level: alpha
pr = 1-alfa/2 # percentage of the population higher than the critical level t
ts = t.ppf(pr,df) # computing the critical t alpha/2
mux = x # using sample as a estimator to population mean
sigmax = sigma/(n**0.5) # normalized standard deviation
marg = ts*sigmax # margin of error
mux1 = x - marg # lower critical value
mux2 = x + marg # upper critical value
print('CI with ',p*100,'% = [ ',round(mux1,2),',',round(mux2,2),']') # Confidence interval
CI with 90.0 % = [ 68.81 , 72.19 ]
The previous complete code is available in the following link:
https://colab.research.google.com/drive/1iMVV-i3ObUDECBsYP7YiwJFnBSU-x4Ue?usp=sharing