Chi-squared inverse function and incomplete gamma function

Click For Summary
SUMMARY

The discussion focuses on the challenges of explicitly expressing the chi-squared inverse function, particularly for large degrees of freedom (50,000). Participants highlight the inefficiency of iterative guessing methods for finding chi-squared values and suggest that the chi-squared CDF can be expressed as a ratio of the gamma function and the incomplete gamma function. They reference MATLAB's numerical solutions and the use of Newton's method for inverting the regularized incomplete gamma function. Additionally, they mention resources like the book by Abramowitz and Stegun and the Digital Library of Mathematical Functions for further understanding.

PREREQUISITES
  • Understanding of chi-squared distribution and its properties
  • Familiarity with gamma functions and incomplete gamma functions
  • Experience with numerical methods for solving integrals
  • Knowledge of programming in MATLAB and R for statistical computations
NEXT STEPS
  • Research "MATLAB chi2inv function" for numerical solutions of the chi-squared inverse function
  • Explore "Newton's method for numerical integration" to improve efficiency in calculations
  • Study "GNU Scientific Library functions" for implementations related to gamma functions
  • Review "Digital Library of Mathematical Functions" for advanced mathematical functions in probability theory
USEFUL FOR

Statisticians, data scientists, and programmers working with statistical distributions, particularly those dealing with large datasets and requiring efficient computation of chi-squared values.

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
23K
  • · Replies 15 ·
Replies
15
Views
2K