Question

I'm trying to calculate a the inverse of 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 TINV with 5 degrees of freedom and 95.45% I use

=TINV(0.0455,5)

And get the Result: 2.64865

Using commons Math like so :

TDistribution t = new TDistribution(5);
double value = t.inverseCumulativeProbability(0.9545);

I get Result : 2.08913

I'm probably doing something wrong obviously. I'm not really that math savvy but I need to port an Excel sheet formula to Java for a project and got stuck on this.

What should I be using to get the result exactly like the TINV value? What am I missing.

Was it helpful?

Solution

MS documentation [1] says that TINV returns a two-tailed value. I'm pretty sure Commons Math is returning a one-tailed value. In order to get Commons Math to agree with Excel, cut the tail mass in half, i.e., call

t.inverseCumulativeProbability (1 - tail_mass/2);

[1] http://office.microsoft.com/en-us/excel-help/tinv-function-HP010335663.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top