想要在 Python 中使用 TINV 在 Excel 中得到相同的结果

Want the same result in Python with using TINV in Excel

a= 0.05 b= 10.8

excel TINV(a,b) 的结果是 2.228138852

from scipy import stats 

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

结果为 1.7989330052096262

如何在 Python 中获得与在 Excel 中使用 TINV 得到的结果相同的结果?

我认为您需要了解两个因素。首先,在ExcelTINV Function截断自由度数(来源:微软)

If deg_freedom is not an integer, it is truncated.

所以在 Excel 中做 TINV(0.05 , 10.8)TINV(0.05 , 10) 将 return 相同的值。

第二个因素,Excel TINV 函数 return 是学生 t-distribution 的 two-tailed 的反函数。但是在 Python 中,您只使用了 1 个尾巴:

How to Find the T Critical Value in Python

所以你需要做 a/2。在 Python 你可以这样做:

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

如您所见,输出 2.2281388519649385 与您在 Excel 2,22813884242587 上获得的输出非常接近 2,22813884242587 不一样(我不知道为什么,我猜这是一个十进制问题)但非常接近。