Apache Math 3.4(和 3.3),java 1.8.0_25
import org.apache.commons.math3.distribution.ChiSquaredDistribution;
ChiSquaredDistribution chisq = new ChiSquaredDistribution(23)
System.out.println(1.0 - chisq.cumulativeProbability(130) // 1.1102230246251565E-16
System.out.println(1.0 - chisq.cumulativeProbability(131) // 0.0
为什么 Apache Math 在第二次调用中返回 0.0?一些统计库(Excel,但不是 R)确实返回的值远小于 1E-16 的尾部概率。
附加编辑:在下面的评论中,Robert 提供了一种直接计算卡方尾概率的方法,该方法使用 Apache 数学库 (regularizedGammaQ) 中不存在此精度问题的另一个函数。