1. Concepts & Definitions
1.1. Defining statistical test of hypothesis
1.2. Numerical example of test of hypothesis for mean
1.3. Code for test of hypothesis for mean
1.4. Code for right tailed test of hypothesis for mean
1.5. Code for left tailed test of hypothesis for mean
1.6. Code for small sample hypothesis for mean
1.7. P-Value and test of hypothesis
1.8. Statistical power and power analysis
1.9. Shapiro Wilk for normality test
2. Problem & Solution
2.1. Shapiro Wilk to verify CLT Simulator
Load the notebook with commands developed in Track 08 - section 2.2. (Click on the link):
https://colab.research.google.com/drive/1x59Luhf0j8H1l4BjcqzdmiclSsz0nZrz?usp=sharing
2. Reload all cells with code before inserting a new code cell.
---Now, the purpose of the next is to verify using a test of hypothesis for normally distributed data, and a confidence level equal to 95%, if it is true that each sample mean has the same value as the population mean or it is different. For this purpose, let's adapt the developments made in Track 08 - section 1.4.
from scipy.stats import norm
muz = 0
sigmaz = 1
p = 0.95
alfa = 1 - p
pr = 1 - alfa/2
z = norm.ppf(pr,muz,sigmaz)
print("Given alpha = ",str(round(alfa,2)),", Zcrit = ",round(z,2))
Given alpha = 0.05 , Zcrit = 1.96
mi = pop_mean_weight
H0 = "The value is equal to " + str(mi)
n = sample_size
s = pop_std_weight
sx = s/(n**(0.5))
print('Null hypothesis:',H0)
for sample_mean in list_means_samples:
xb = sample_mean
zobs = (xb - mi)/sx
#print('For sample_mean:', sample_mean)
#print("Zobs = ",zobs,"e Zcrit = ",z)
if (zobs > z)|(-zobs < -z): # Zobs belongs to the critical region
print("For sample mean ",sample_mean,"Zobs = ",zobs,"Zcrit = ",z," - Reject H0.")
else:
print("For sample mean ",sample_mean,"Zobs = ",zobs,"Zcrit = ",z," - Do not reject H0.")
The complete code is available in the following link:
https://colab.research.google.com/drive/1BXMpi9jLRCpW56UUIrz1CrM_F6HU-wHA?usp=sharing