Searching the student-t distribution table for values using python

For a meaningful interpolation, you would first need to define a 2D inperpolation function (bilinear, bicubic).

For better resutls directly use the scipy implementations of the percent point function (i.e. the inverse cumulative distribution function).

from scipy.stats import t
alpha = 0.05  # significance level = 5% 
df = 5  # degrees of freedom                                        
v = t.ppf(1 - alpha/2, df) 
print(f'v: {v}') 

Result is v: 2.57058 so the result is the same as the 2.571 from your table.

This code reproduces your student_t list:

def calc_v(alpha,df):
    v = t.ppf(1 - alpha/2, df)  # t-critical value
    return v

alphas = [ 0.5, 0.1, 0.05, 0.01]
student_t = [[00, 50, 90, 95, 99]]
for i in range(21):
    df = i+1
    student_t.append([df]+[calc_v(alpha,df) for alpha in alphas])
for df in [30,40,50,60,61]:
    student_t.append([df]+[calc_v(alpha,df) for alpha in alphas])

As said above, the inverse of the ppf is the cdf. It can be calculated like this:

P = 1 - 2*(1 - t.cdf(2.571,df = 5))

Which gives P = 0.950025.

Standard Normal

For standard normal distribution the ppf is also implemented in scipy:

from scipy.stats import norm
norm.ppf(q, loc=0, scale=1)

Leave a Comment