"""Numbers for the What-to-write templates (Welch result for the ALT example; paired t-test for the paired example).
Python 3.13, SciPy 1.18.1. Run: python template_check.py > template_check_output.txt"""
import numpy as np
from scipy import stats

# ALT example from summary statistics (treated - control), Welch's t-test
r = stats.ttest_ind_from_stats(58.17, 8.13, 6, 47.17, 7.94, 6, equal_var=False)
v1, v2 = 7.94**2 / 6, 8.13**2 / 6
df = (v1 + v2) ** 2 / (v1**2 / 5 + v2**2 / 5)
half = stats.t.ppf(0.975, df) * np.sqrt(v1 + v2)
print(f"ALT: difference 11.00, 95% CI {11 - half:.1f} to {11 + half:.1f}; Welch t({df:.2f}) = {r.statistic:.2f}, p = {r.pvalue:.3f}")

# Paired example (after - before), paired t-test
before = np.array([52.1, 47.3, 55.8, 49.0, 60.2, 51.5])
after = np.array([58.4, 50.9, 63.0, 55.2, 64.1, 59.8])
p = stats.ttest_rel(after, before)
ci = p.confidence_interval(0.95)
print(f"paired: mean change {(after - before).mean():.2f}, 95% CI {ci.low:.2f} to {ci.high:.2f}; t({p.df:.0f}) = {p.statistic:.2f}, p = {p.pvalue:.4f}")
