Home > database >  How to reproduce Excel's T.INV.2T in python?
How to reproduce Excel's T.INV.2T in python?

Time:10-15

I've read many similar posts that say Excel's T.INV.2T(probability, degs_Freedom) can be reproduced in python using scipy.stats.t.ppf().

If I use the example of T.INV.2T(0.05, 58) excels yields 2.002.

Based on other answers posted I should get the same answer using scipy.stats.t.ppf(0.05, 58), but I do not. I get -1.672.

Any ideas on what is wrong with my syntax?

CodePudding user response:

I don't remember why but you should use 0.025 (0.05/2) in Python. However, the probability is not alpha but 1 - alpha, so 1-0.025.

>>> t.ppf(1-0.025, df=58)
2.0017174830120923

>>> np.round(t.ppf(1-0.025, df=58), 3)
2.002

CodePudding user response:

In Excel, you have two functions for returning the inverse of the Student's t-distribution: T.INV and T.INV.2T.

The first returns a left-tailed inverse of the Student's t-distribution and the second returns a two-tailed one.

scipy.stats.t.ppf also returns a left-tailed inverse of t-distribution. So, if you want to compare scipy.stats.t.ppf with Excel you need to use the T.INV formula and not T.INV.2T – or you should divide the probability by two and then use it with scipy.

  • Related