Want the same result in Python with using TINV in Excel

Viewed 61

a= 0.05 b= 10.8

the result in excel TINV(a,b) is 2.228138852

from scipy import stats 

result = stats.t.ppf(1 - a, b)

the result is 1.7989330052096262

How I can get the same result in Python what I get by using TINV in Excel?

1 Answers

I think there are 2 factors you need to know. First of all, in Excel TINV Function truncates the number of degrees of freedom (source: Microsoft)

If deg_freedom is not an integer, it is truncated.

So in Excel doing TINV(0.05 , 10.8) and TINV(0.05 , 10) will return the same value.

Second factor, Excel TINV function returns the two-tailed inverse of the Student's t-distribution. But in Python, you are using only 1 tail:

How to Find the T Critical Value in Python

So you need to do a/2. In Python you could do then:

from scipy import stats
a= 0.05
b= 10 # Integer because Excel truncates degrees of freedom
result = stats.t.ppf(1-a/2, b)
print(result)

2.2281388519649385

As you can see, the ouput 2.2281388519649385 is pretty close to what you get on Excel 2,22813884242587 Not the same (I don't know why, I guess it's a decimal issue) but pretty close.

Related