Issue
Why isn't the inverse gamma function producing the original x value?
Code
x = 0.2
alpha = 2
u = sp.stats.gamma.cdf(x, alpha)
x1 = sp.stats.invgamma.cdf(x, alpha)
print "x: ", x
print "G: ", u
print "GInv:", x1
Output
x: 0.2
G: 0.0175230963064
GInv: 0.0404276819945
When I perform a similar operation in Excel I get the same value back.
=GAMMADIST(Q15,2,1,TRUE)
=GAMMA.INV(Q16,2,1)
Output
0.2
0.017523096
0.2
I know I'm just overlooking something, but I can't seem to figure out why the inverse isn't working for me.
Solution
In scipy.stats
, gamma
is the gamma distribution and invgamma
is the inverse gamma distribution. These are two different probability distributions--see the wikipedia article for the relation of the inverse gamma to the gamma distribution.
If you want the inverse of gamma.cdf
, use gamma.ppf
. (The acronym ppf
stands for percent point function, which is another name for the quantile function.)
For example,
In [7]: p = gamma.cdf([1, 2, 3], 0.5)
In [8]: gamma.ppf(p, 0.5)
Out[8]: array([ 1., 2., 3.])
Answered By - Warren Weckesser
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.