Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a t test table in python (numpy, scipy etc)?

I am trying as an exercise since I'm still fairly new to python and programming to make a script that takes a one sample pool of numbers and just use the t value from a table to make a more accurate deviation than a stdev.

example: 10 samples and I want the t table value from the column for 0.975. In this case it's 10-1, row 9 has the t value 2.262 in column 0.975

Is there any easy way to just type into python or any extra library that I just want the t value from row X column 0.975 and use it in further calculations?

Or do I have to find a CVS file and try and import values in that way? I have tried to go through scipy.stats functions but honestly its a bit overwhelming for someone just starting out and haven't done anything with p values or similar statistics before.

like image 477
MrZwing Avatar asked Mar 03 '18 15:03

MrZwing


1 Answers

You can use the ppf method (i.e. the quantile function) of scipy.stats.t:

In [129]: from scipy.stats import t

In [130]: alpha = 0.025

In [131]: t.ppf(1 - alpha, df=9)
Out[131]: 2.2621571627409915

t.ppf() ultimately calls scipy.special.stdtrit, so you could also use that function and avoid the slight overhead of going through t.ppf():

In [141]: from scipy.special import stdtrit

In [142]: alpha = 0.025

In [143]: stdtrit(9, 1 - alpha)
Out[143]: 2.2621571627409915

(If you are wondering how the function ended up with the name stdtrit, it is the Student T DisTRibution function Inverse with respect to T. Clear, right?)

like image 174
Warren Weckesser Avatar answered Nov 14 '22 23:11

Warren Weckesser