import numpy as np from scipy import stats sample = np.array([10.2, 9.8, 10.5, 10.1, 9.9, 10.4]) before = np.array([72, 75, 71, 70, 74, 73]) after = np.array([68, 72, 69, 66, 71, 70]) group_a = np.array([14.2, 13.8, 15.0, 14.5, 13.9, 14.7]) group_b = np.array([12.6, 13.1, 12.9, 12.4, 13.0, 12.8]) one_sample = stats.ttest_1samp(sample, popmean=10.0) paired = stats.ttest_rel(after, before) welch = stats.ttest_ind(group_a, group_b, equal_var=False) ci = welch.confidence_interval(confidence_level=0.95) print(f"one-sample vs 10.0: statistic={one_sample.statistic:.3f}, pvalue={one_sample.pvalue:.4f}, df={one_sample.df:.1f}") print(f"paired after-before: statistic={paired.statistic:.3f}, pvalue={paired.pvalue:.4f}, df={paired.df:.1f}") print(f"welch group A vs B: statistic={welch.statistic:.3f}, pvalue={welch.pvalue:.4f}, df={welch.df:.1f}") print(f"welch 95% CI: {ci.low:.2f} to {ci.high:.2f}") print("reject equal means at alpha=0.05:", welch.pvalue < 0.05)