189. One-Sample Z-Test for Mean
Warning: Pipulation standard deviation, , is known.
Example
Your favorite candy company claims their chocolate bars have a mean weight of 200 grams, and their population standard deviation is 5 grams. You’ve noticed that they’ve seemed lighter than usual. You take a simple random sample of 35 candy bars and find they have a mean weight of 198 grams. At = 0.05 test the company’s claim.
Where:
Reject . At there is sufficient evidence that the mean weight of the chocolate bars is less than 200 grams.
Code
import numpy as np
from scipy.stats import norm
mu = 200.0
sigma = 5.0
xbar = 198
n = 35
alpha = 0.05
cv = norm.ppf(alpha)
z = (xbar - mu) / (sigma / np.sqrt(n))
p = norm.cdf(z)
if z <= cv:
print("Reject null hypothesis")
else:
print("Fail to reject null hypothesis")