How to specify gamma distribution using shape and rate in Python?

Question:

With Scipy gamma distribution, one can only specify shape, loc, and scale. How do I create a gamma variable with shape and rate?

Asked By: Heisenberg

||

Answers:

Inverse scale (1/scale) is rate parameter.

So if you have shape and rate you can create gamma rv with this code

>>> from scipy.stats import gamma
>>> rv = gamma(shape, scale = 1.0/rate)

Read more about different parametrizations of Gamma distribution on Wikipedia:
http://en.wikipedia.org/wiki/Gamma_distribution

Answered By: Konstantin

you can do it with the scale parameter, rate=1/scale

in R :

pgamma(1/2, 2, rate=5) and pgamma(1/2, 2, scale=0.2) are identical

Answered By: Mir Ilias

Accodring to wikipedia, rate is 1/scale, so you could use the scipy distribution directly or wrap it with something like

def my_gamma(x,q,a,loc,freq,size,moments):
    return scipy.stats.gamma(x, q, a,loc, 1.0/freq, size, moments)
Answered By: Nat Knight

I am stuck with the same problem.

Not able to include the loc in Symbulate to use the function RV.
My line code looks like :

rv=RV(Gamma(shape,rate))

I did fit a Gamma distribution to my data with stats.gamma and got a loc. I don’t know how to include loc within shape and rate.

That would be very useful! thank you.

Answered By: Haifa Tebib
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.