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 data1 = pd.read_stata("http://kanggc.iptime.org/book/data/chap11-2-1.dta") data1.head() var1 = data1['var1'] var1.describe() print("Data Frame of data1 is : ",f'\n{data1}\n') print("Summary Statistics of data1 is : ", f'\n{data1.describe()}\n') xbar = np.mean(var1) xbar xstd = np.std(var1, ddof=1) xstd #t14 = stats.t.ppf(0.95, 14) #t14 t_cal = (xbar-34.5)/(xstd/np.sqrt(15)) t_cal t14_1 = tdist.ppf(0.025, df=14) t14_1 t14_2 = tdist.ppf(0.975, df=14) t14_2 print("Mean of var1 is : ",f'\n{xbar}\n') print("Standard Deviation of data1 is : ", f'\n{xstd}\n') print("Calculated t-statistic is : ",f'\n{t_cal}\n') res = stats.ttest_1samp(data1, popmean=34.5, alternative='two-sided') 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)