jstat/jstat — Issue #27: bug in gamma/chisq cdf and inverse cdf
Author: richarddmorey
Created: 2011-12-25 15:24:55+00:00
State: open

(I just cloned the repository today, so I think I'm working with the most recent version; I would give you a revision number, but I don't know much about git)

There are several issues with the gamma cdf and inverse cdf.

* On line 143 of distribution.js, the inverse cdf of the gamma distribution is defined as:

2 * jStat.gammapInv( p, 0.5 * dof );

However, the function gammapInv() is undefined. On line 173 of special.js, the function gammapinv() is defined (note the case change). This just seems to be a typo, and I would just correct it and submit the change, *but*:

* The function for the cdf and inverse cdf of the gamma functions are still wrong even with the change. For instance,

jStat.gamma.cdf(1,4,2);

returns 1.764162786476752, which of course can't be correct because it is greater than 1. I believe the problem is the fact that the gamma.cdf(x, dof) function is defined on line 139 of distribution.js as

jStat.gammap( x / 2, dof / 2 );

however, the gamma cdf must be normalized (see [the R help](http://stat.ethz.ch/R-manual/R-patched/library/stats/html/GammaDist.html), for instance). I played around with getting that to work, but couldn't get them to match up with R even with normalizing; I figured someone with more familiarity with the jStat code would probably be able to fix it quickly.