import pandas as pd import numpy as np import scipy.stats as stats #from scipy.stats import norm #from scipy.stats import t from scipy.stats.distributions import t as tdist data = pd.read_excel("http://kanggc.iptime.org/book/data/chap11-3-2.xlsx") data var1 = data['var1'] var2 = data['var2'] d = var1 - var2 print("Data Frame of data is : ",f'\n{data}\n') print("Data Frame of d is : ", f'\n{d}\n') d_mean = np.mean(d) d_mean d_var = np.var(d, ddof=1) d_var t_cal = d_mean/(np.sqrt(d_var/6)) t_cal t5_1 = tdist.ppf(0.05, df=5) t5_1 t5_2 = tdist.ppf(0.95, df=5) t5_2 print("Mean of d is : ",d_mean) print("Variance of d is : ", d_var) print("Calculated t-statistic is : ",t_cal) res = stats.ttest_1samp(d, popmean=0, alternative='less') print(res) ci = res.confidence_interval(confidence_level=0.95) print(ci) ci.low ci.high print("The Lower Value of 95% Confidence Interval is :", ci.low) print("The Upper Value of 95% Confidence Interval is :", ci.high) print("Critical value of t distribution w/ p=0.05 and df=5 is : ",t5_1)