11

 import math

from scipy import stats

# Given values

mu_0 = 200  # Old recipe mean

x_bar = 190  # Sample mean

s = 15       # Sample standard deviation

n = 40      

# Sample size

alpha = 0.05

# Calculate t-statistic

t_stat = (x_bar - mu_0) / (s / math.sqrt(n))

df = n - 1

# Get critical t-value for one-tailed test

t_critical = stats.t.ppf(alpha, df)

# Calculate p-value

p_value = stats.t.cdf(t_stat, df)

# Print results

print(f"T-statistic: {t_stat:.3f}")

print(f"Critical t-value: {t_critical:.3f}")

print(f"P-value: {p_value:.5f}")

if t_stat < t_critical:

    print("Reject the null hypothesis: The new recipe has significantly fewer calories.")

else:

    print("Fail to reject the null hypothesis: Not enough evidence to support the claim.")

Comments