Search code examples
javaexcelapache-commons-math

Calculating TDIST using Apache Commons library


I'm trying to calculate a 2 tailed Student Distribution using commons-math. I'm using Excel to compare values and validate if my results are correct.

So Using excel to calculate TDIST(x, df, t) with x = 5.968191467, df = 8, tail t = 2

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

And get the Result: 0.000335084

Using commons Math like so :

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

I get Result : 0.00018738010608336254

What should I be using to get the result exactly like the TDIST value?


Solution

  • To replicate your formula in Excel you can use CDF:

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