Chi-squared inverse function and incomplete gamma function

Click For Summary

Discussion Overview

The discussion revolves around the challenges of explicitly expressing the chi-squared inverse function, particularly in the context of programming and numerical methods. Participants explore various approaches to calculating the chi-squared cumulative distribution function (CDF) and the incomplete gamma function, with a focus on large degrees of freedom.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Some participants express frustration with the iterative guessing method used to find the chi-squared inverse function, particularly for large degrees of freedom (e.g., 50,000).
  • There is a suggestion that the chi-squared inverse function can be expressed as a ratio of the gamma function and the incomplete gamma function, with a proposal to express it as a difference of logs.
  • One participant mentions the scaled inverse chi-square distribution as a potential relevant concept, linking it to the characteristic function of the incomplete gamma function.
  • Another participant questions whether the characteristic function for the incomplete gamma function is an integral, which they consider a sum.
  • Several participants mention numerical methods used in MATLAB and R to invert the gamma CDF, noting issues with large values leading to program crashes.
  • There are references to the book of Abramowitz and Stegun and the Digital Library of Mathematical Functions, with some participants seeking clarification on specific equations and definitions related to the chi-squared distribution.
  • One participant emphasizes that they are not looking for the inverse chi-squared distribution, but rather the inverse function for the chi-squared distribution itself.

Areas of Agreement / Disagreement

Participants express a range of views on the methods for calculating the chi-squared inverse function, with no consensus reached on the best approach. Some participants agree on the challenges posed by large degrees of freedom, while others propose different mathematical perspectives and references.

Contextual Notes

Limitations include unresolved mathematical steps regarding the expression of the incomplete gamma function, as well as the dependence on specific programming environments and numerical methods. There is also ambiguity in the definitions and equations referenced, particularly concerning the relationship between the chi-squared CDF and the incomplete gamma function.

onanox
Messages
15
Reaction score
0
is there a way to explicitly express the chi-squared inverse function?

when programming it, I have had to resort to a guessing system where I find a chi value that is too low and too high, and evaluate the chi-squared CDF to reset the high and low points iteratively until it is within a preset tolerance to the correct value.

However, this a clunky and inefficient method.

Additionally, for large degrees of freedom (50,000 or so) I can't even calculate the chi-squared CDF because the values are too high. I noticed that this function can be expressed as a ratio of the gamma function and incomplete gamma function, so It occurred to me to express the value as a difference of logs of each piece. However, I have only found expressions of the incomplete gamma function as sums, which are difficult (impossible?) to log. is there any way to express the incomplete gamma function as a product?
 
Physics news on Phys.org
onanox said:
is there a way to explicitly express the chi-squared inverse function?

when programming it, I have had to resort to a guessing system where I find a chi value that is too low and too high, and evaluate the chi-squared CDF to reset the high and low points iteratively until it is within a preset tolerance to the correct value.

However, this a clunky and inefficient method.

Additionally, for large degrees of freedom (50,000 or so) I can't even calculate the chi-squared CDF because the values are too high. I noticed that this function can be expressed as a ratio of the gamma function and incomplete gamma function, so It occurred to me to express the value as a difference of logs of each piece. However, I have only found expressions of the incomplete gamma function as sums, which are difficult (impossible?) to log. is there any way to express the incomplete gamma function as a product?

I think the scaled inverse chi square distribution is what you're after. The scaling factor is the population variance. The characteristic function of the incomplete gamma is expressed as a product (as are all characteristic functions). This link may help:

http://jacki.wikidoc.org/index.php/Scale-inverse-chi-square_distribution
 
Last edited by a moderator:
well isn't the characteristic function for the incomplete gamma function an integral? which is a sum?

and just to clarify (and I might be wrong here) but I am not talking about the inverse chi-squared distribution, I am talking about the inverse function for the chi-squared function.
 
To invert the gamma cdf, two different approaches are described in the documentation for gaminv in MATLAB and qgamma in R.
 
in MATLAB, they just numerically solve the integral, however, with large degrees of freedom (50,000 or so) the program will crash because the values are just too large.
I guess this question is better suited for a programming board, and directed at larger number data types rather than better mathematical methods.
 
If you just want the quantile (inverse CDF) of the chi squared distribution, that can be approximated with the normal distribution inverse CDF for large numbers of degrees of freedom.

That isn't known analytically either, but MATLAB etc. have good approximations.

Or do you want something else? I have to admit I'm having trouble relating this to your question about the characteristic fn of a gamma function.
 
onanox said:
in MATLAB, they just numerically solve the integral, however, with large degrees of freedom (50,000 or so) the program will crash because the values are just too large.
I guess this question is better suited for a programming board, and directed at larger number data types rather than better mathematical methods.

MATLAB has no problems with large dof, e.g.

>>chi2inv(0.75,1e6) % returns 1.001e6
 
I meant, matlab's documentation does not give any real info except that they solve it numerically, yet when I try to use a similar method in AS3, the program errors on high values.
I apologize for my ambiguity.
 
  • #10
Here are the references for GAMMAINCINV which inverts the regularized incomplete gamma function (i.e. the gamma cdf with scale parameter 1) using Newton's method:

% References:
% [1] Abramowitz & Stegun, Handbook of Mathematical Functions,
% Sec. 6.5, especially 6.5.29 and 26.5.31.
% [2] Knuesel, L. (1986) "Computation of the Chi-square and Poisson
% Distribution", SIAM J. Sci. Stat. Comput., 7(3):1022-1036.

For the Newton iterations, to compute the derivative of gammainc (the gamma pdf) you should use exp(gammaln(...)*...) to avoid underflow/overflow.
 
  • #12
onanox said:
Q(xp)=1-P(xp)=p
any idea what this means?
especially noting that
Q(x2p | v) = p

I don't know what Q is. I think P(x_p) is probably the cumulative distribution of the chi-square as defined on page 262.

In browsing the online book, I notice that the bottom of some of the pages are cut off, such as page 936. I wonder if that's worth reporting to someone, or does everybody already know that? I have a hard copy of this book packed away somewhere.

A more modern reference is the Digital Library Of Mathematical Functions. They define a P and Q on this page: http://dlmf.nist.gov/8

The bad thing about this reference is that they have little explanation of how their special functions are used in probabiity theory.

I notice the Wikipedia article on the inverse chi-square ( http://en.wikipedia.org/wiki/Inverse-chi-square_distribution) says there are two different distributions by that name. Do we have the one you want?
 
  • #13
once again, I am NOT looking for an "inverse chi squared" distribution (which is really a reciprocal chi squared distribution)
I am looking for an inverse function for the chi squared distribution.after reading that link, it becomes apparent that the chi squared CDF is equivalent to the normalized incomplete gamma function.
the GNU Scientific Library defines a function for that, so I am currently checking that documentation.
 
Last edited:

Similar threads

  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
24K
  • · Replies 15 ·
Replies
15
Views
2K