[SciPy-User] discrepancy in chi square cumulative distribution and gamma functions?

James Jensen jdjensen at eng.ucsd.edu
Wed Mar 25 19:43:17 EDT 2015


>From what I understand, the cdf of a chi-square distribution with k degrees
of freedom and a test statistic x is

lower_incomplete_gamma(k/2, x/2) / gamma(k/2)

So you would expect the following two lines of code to yield the same
result:

cdf1 = scipy.stats.chi2.cdf(x, k)
cdf2 = scipy.special.gammainc(0.5 * k, 0.5 * x) / scipy.special.gamma(0.5 *
k)

Here's the ratio cdf1 / cdf2 for k=1, 2, ...20:

1 1.77245385091
2 1.0
3 0.886226925453
4 1.0
5 1.32934038818
6 2.0
7 3.32335097045
8 6.0
9 11.6317283966
10 24.0
11 52.3427777846
12 120.0
13 287.885277815
14 720.0
15 1871.2543058
16 5040.0
17 14034.4072935
18 40320.0
19 119292.461995
20 362880.0

The discrepancy appears to be a function of k but not of x, i.e. it's
constant for different x with the same k.

I suspect I'm missing something obvious, but I can't see it. Any thoughts?

James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150325/adbe56d5/attachment.html>


More information about the SciPy-User mailing list