Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gamma distribution in python

We have qgamma in R and gamm.inv in excel, and I am not able to get the same results using invgamma function in python. For example in excel GAMMA.INV(0.99,35,0.08)=4.01, I can get the same value from R using qgamma with probability=0.99, alpha(scale)=35.0, shape=0.08.

But when I am using invgamma.pdf(0.99,35,0.8) it returns 1.61787636512e-15.

What is the right way of doing it? I have tried both gamma and invgamma with pdf, ppf, cdf but nothing is matching with the value I am getting from qgamma in R or GAMMA.INV in excel

like image 549
SKD Avatar asked Oct 18 '25 15:10

SKD


1 Answers

qgamma and GAMMA.INV give the inverse cumulative distribution function of a gamma distribution.

invgamma represents an inverse gamma distribution, which is a completely different thing. Explaining the difference is out of scope for this site, as it's a statistics issue, not a programming issue, but you should really get it solidly understood before you proceed.

The SciPy distribution object for a gamma distribution is scipy.stats.gamma, and the method for the inverse cumulative distribution function is ppf, short for "percentile point function" (another name for the inverse CDF). Thus, you should be using scipy.stats.gamma.ppf. Make sure to pass it the right arguments.

like image 144
user2357112 supports Monica Avatar answered Oct 20 '25 05:10

user2357112 supports Monica