A critical range is the central interval of test-statistic values that is not extreme enough to reject the null hypothesis. In a two-tailed test with 95% confidence, the standard-normal critical range is approximately [-1.959964, 1.959964]. Values outside it fall in the alpha regions and count as statistically significant. section 6.6
Potato-chip bag weights
Testing the claim that bags average 142 grams produces a Z-statistic of -2.4062. Because it falls outside [-1.959964, 1.959964], reject the null hypothesis: the sample provides enough evidence that the mean differs from 142 grams. section 6.6
from math import sqrt #1
from scipy.stats import norm #1
mu = 142.0 #2
n = 41 #3
x_bar = 140.2 #4
s = 4.79 #5
alpha = 0.05 #6
z_stat = (x_bar - mu) / (s / sqrt(n)) #7
critical_z = norm.ppf(1 - (alpha / 2)) #8
print("Population mean: ", mu) #9
print("Sample mean: ", x_bar) #9
print("Sample standard deviation: ", s) #9
print("Sample size: ", n) #9
print("Level of confidence: ", 1 - alpha) #9
print("Level of significance: ", alpha) #9
print("z-statistic: ", z_stat) #9
print("Critical value: ", critical_z) #9
if -critical_z <= z_stat <= critical_z: #10
print("Decision: Fail to reject the null hypothesis. "
"The sample does not provide enough evidence the mean is different.") #11
else:
print("Decision: Reject the null hypothesis. "
"The sample provides enough evidence the mean is different.") #11
"""
Population mean: 142.0
Sample mean: 140.2
Sample standard deviation: 4.79
Sample size: 41
Level of confidence: 0.95
Level of significance: 0.05
z-statistic: -2.4061844733568267
Critical value: 1.959963984540054
Decision: Reject the null hypothesis. The sample provides enough evidence the
mean is different
"""
Calculate the Z-statistic and two-tailed critical value in Python, then compare the statistic with the critical range to make the decision. section 6.6
