Why does tail probability in apache math drop to zero after 1E-16?

不打扰是莪最后的温柔 提交于 2019-12-12 03:48:28

问题


Apache Math 3.4 (and 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

Why does Apache Math return 0.0 in the second call? Some stat libraries (Excel, but not R) do return values that are much smaller than 1E-16 for the tail probabilities.

Additional Edit: In the comments below, Robert provides a direct way of calculating chi square tail probabilities using another function from Apache math library (regularizedGammaQ) that does not have this precision problem.

ChiSquaredDistribution Javadoc


回答1:


Note that the smallest value which can be subtracted from 1.0 to yield something less than 1.0 is approximately 1e-16; you can verify this directly. Maybe you should print out chisq.cumulativeProbability(131) itself. I don't know if it's correct but in any case let's not confuse the issue by subtracting it from 1.0.



来源:https://stackoverflow.com/questions/27773499/why-does-tail-probability-in-apache-math-drop-to-zero-after-1e-16

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!