# Computing expected frequencies for gamma distribution R VS Python

I am tryng to "translate" from R to Python a code that computed expected frequencies from the Gamma distribution.

More specifically, I have this line of code:

(pgamma(3,shape=a.est,rate=l.est)-pgamma(0,shape=a.est,rate=l.est))*200 that calculate expected frequencies from a gamma distribution of size 200, and shape a.est <- <-((med.gam)^2)/var.gam and rate l.est<-avg.gam / var.gam.

I found out in Python the scipy.stats package, and this is my implementation:

(gamma.cdf(3, a_est, 1/l_est) - gamma.cdf(0, a_est, 1/l_est)) * 200

However, the results are quite different between R and Python, this makes me think I am making some sort of mistakes. Is this way to calculate expected frequencies in python correct?

• This question is probably gonna be closed because it is off-topic, but to help you further, why not plot some of those curves, or individual values to debug and find out how those functions work? May 18, 2020 at 19:28

Ok if you read the manual:

gamma takes a as a shape parameter for .
....
cdf(x, a, loc=0, scale=1)


The parameter that comes after the shape is location, not scale. You need to do:

a_est = 3
l_est = 2
from scipy.stats import gamma, norm
gamma.cdf(6, a_est, scale=1/l_est)
0.9994777419499671


In R:

pgamma(6,shape=a_est,rate=l_est)
[1] 0.9994777