Python function to get the t-statistic
Have you tried scipy?
You will need to installl the scipy library...more about installing it here: http://www.scipy.org/install.html
Once installed, you can replicate the Excel functionality like such:
from scipy import stats#Studnt, n=999, p<0.05, 2-tail#equivalent to Excel TINV(0.05,999)print stats.t.ppf(1-0.025, 999)#Studnt, n=999, p<0.05%, Single tail#equivalent to Excel TINV(2*0.05,999)print stats.t.ppf(1-0.05, 999)
You can also read about installing the library here: how to install scipy for python?
Try the following code:
from scipy import stats#Studnt, n=22, 2-tail#stats.t.ppf(1-0.025, df)# df=n-1=22-1=21print (stats.t.ppf(1-0.025, 21))
You can try this code:
# for small samples (<50) we use t-statistics# n = 9, degree of freedom = 9-1 = 8# for 99% confidence interval, alpha = 1% = 0.01 and alpha/2 = 0.005from scipy import statsci = 99n = 9t = stats.t.ppf(1- ((100-ci)/2/100), n-1) # 99% CI, t8,0.005print(t) # 3.36