I had to derive the chi-squared confidence intervals for a AR(1) red noise model generated theoretically to fit the power spectra of a time series. The shape function of the power spectra of the red noise model is given by $$\frac{1-\rho^2}{1-2\rho\cos\frac{k\pi}{f_s}+\rho^2}$$ However, to derive the $95\%$ and $99\%$ confidence intervals I had to first do this (python 3.7):
Ci95=(2*sc.gammaincinv(nw2/2, 0.95))/nw2
Ci99=(2*sc.gammaincinv(nw2/2, 0.99))/nw2
where nw2 is, I figured out (and please correct me if I am wrong), the degrees of freedom. Then I had to multiply the theoretically derived red noise spectra with Ci95 and Ci99 to get the confidence levels.
Can anyone please explain the connection between the chi-square confidence intervals and the inverse gamma function? I had looked up for the connection between chi-square and gamma function, but none actually touched upon this particular aspect.
The key point is that if $X \sim \chi^2_{\nu}$, a chi-squared distribution with $\nu$ degrees of freedom,
then you can also say $X \sim \operatorname{Gamma}\left(k=\frac\nu2,\theta=2\right)$, a Gamma distribution with shape parameter $\frac\nu2$ and scale parameter $2$ or rate parameter $\frac12$.
In both cases $X$ will have a probability density function of $\frac{1}{\Gamma(\nu /2) 2^{\nu/2}} x^{\nu/2 - 1} e^{-{x}/{2}}$ for $x>0$.
So if your programming language can work with one of these distributions, then it can work with the other with a suitable adjustment to the parameters.