Search code examples
pythonscipystatisticsdata-science

Calculate T-Student [Test] for different standard Statistical tables in python


I need calculate t-value using (alpha)/2 and df (degrees of freedom) for the next table:

https://www.fisterra.com/mbe/investiga/t_student/images/t_stud4.gif

test : t(n-1,alpha/2) and (gl = df)

I want to compute the value for (alpha/2, df) = (0.05/2, 9). Using referenced table I got:

t(0.025,9) = 2.262

What is the right way?

I just found the following code,

import scipy.stats as sts
sts.t.ppf(0.95,9) = 1.8331129

which is for alternating table:

http://image.slidesharecdn.com/tablat-student-120318105418-phpapp02/95/tabla-t-student-1-728.jpg?cb=1332086091


Solution

  • Try the following

    import scipy.stats
    
    def t(alpha, gl):
        return scipy.stats.t.ppf(1-(alpha/2), gl)
    

    You can test it with

    print(t(0.05,9))
    

    The result will be 2.262