2

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?

f_puras
  • 2,521
  • 4
  • 33
  • 38

2 Answers2

1

To replicate your formula in Excel you can use CDF:

2*(1.0 - tDistribution.cumulativeProbability(5.968191467))
ryuichiro
  • 3,765
  • 1
  • 16
  • 21
0

The right formula for a general x is:

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

(thanks to ryuichiro). Do not forget to add the absolute value, because TDIST for 2 degrees of freedom in Excel is a symmetrical formula, that is

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

and the one of ryuchiro would not work for negative x's. Check also the docs or this.

Gismo Ranas
  • 6,043
  • 3
  • 27
  • 39