[
https://issues.apache.org/jira/browse/STATISTICS-25?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17220092#comment-17220092
]
Gilles Sadowski commented on STATISTICS-25:
-------------------------------------------
I confirm that the equivalent code in [Commons
Statistics|https://gitbox.apache.org/repos/asf?p=commons-statistics.git;a=blob;f=commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java;h=5f74ff50a5077135f9ecca268f3a782a132be176;hb=HEAD]
exhibits the same behaviour as {{Commons Math}} (used in the provided
example).
The cause is plain limitation of {{double}}-precision in the
[computation|https://gitbox.apache.org/repos/asf?p=commons-statistics.git;a=blob;f=commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java;h=5f74ff50a5077135f9ecca268f3a782a132be176;hb=HEAD#l97]
of
{noformat}
degreesOfFreedom / (degreesOfFreedom + (x * x)
{noformat}
When {{degreesOfFreedom}} grows very large, the value is 1, whatever {{x}}.
Could you please provide the equivalent code from one of those other libraries,
so that we can figure out how they work around this issue?
> T Distribution Inverse Cumulative Probability Function gives the Wrong Answer
> -----------------------------------------------------------------------------
>
> Key: STATISTICS-25
> URL: https://issues.apache.org/jira/browse/STATISTICS-25
> Project: Apache Commons Statistics
> Issue Type: Bug
> Reporter: Andreas Stefik
> Priority: Major
>
> Hi There,
> Given code like this:
>
> import org.apache.commons.math3.analysis.UnivariateFunction;
> import org.apache.commons.math3.analysis.solvers.BrentSolver;
> import org.apache.commons.math3.distribution.TDistribution;
> public class Main {
> public static void main(String[] args) {
> double df = 1E38;
> double t = 0.975;
> TDistribution dist = new TDistribution(df);
>
> double prob = dist.inverseCumulativeProbability(1.0 - t);
>
> System.out.println("Prob: " + prob);
> }
> }
>
> It is possible I am misunderstanding, but that seems equivalent to:
>
> scipy.stats.t.cdf(1.0 - 0.975, 1e38)
>
> In Python. They give different answers. Python gives 0.509972518193, which
> seems correct, whereas Apache Commons gives Prob: -6.462184036284304E-10.
> That's a huge difference.
> My hunch is that as you get closer to infinity it begins to fail, but I
> haven't checked carefully. For calls with much smaller degrees of freedom,
> you get answers that are basically the same as Python or online calculators.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)