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?

  • $\begingroup$ 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? $\endgroup$ May 18, 2020 at 19:28

1 Answer 1


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)

In R:

[1] 0.9994777

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.