使用 Apache Commons 库计算 TDIST

Calculating TDIST using Apache Commons library

我正在尝试使用 commons-math 计算 2 尾学生分布。我正在使用 Excel 来比较值并验证我的结果是否正确。

所以使用excel计算TDIST(x, df, t),其中x = 5.968191467, df = 8, tail t = 2

=TDIST(ABS(5.968191467),8,2)

得到结果:0.000335084

像这样使用 commons Math :

TDistribution tDistribution = new TDistribution(8);
System.out.println(BigDecimal.valueOf(tDistribution.density(5.968191467)));

我得到结果:0.00018738010608336254

我应该使用什么来获得与 TDIST 值完全一样的结果?

要在 Excel 中复制您的公式,您可以使用 CDF:

2*(1.0 - tDistribution.cumulativeProbability(5.968191467))

一般 x 的正确公式是:

2*(1.0 - tDistribution.cumulativeProbability(Math.abs(x)))

(感谢 ryuichiro)。不要忘记加上绝对值,因为Excel中2个自由度的TDIST是对称公式,即

TDIST(-x,df,2) = TDIST(x,df,2)

并且 ryuchiro 中的那个不适用于负 x。还要检查 docs or this.