2

I would like to translate the following Matlab code in Python:

 tau=40 %scale parameter
 a=3 %shape parameter
 t = gaminv(0.90,a,tau);

The code returns t = 212.8928. I've tried:

 import scipy.stats.distributions as dist
 tau=40
 a=3
 t = dist.invgamma.cdf(90, a, scale = tau)

but the python code doesn't return the same t value. Am I doing something wrong?

user1363251
  • 421
  • 1
  • 11
  • 24

1 Answers1

6

You want the ppf ("percent point function", which is a somewhat less common name for the inverse of the CDF or quantile function) method of scipy.stats.gamma:

In [27]: from scipy.stats import gamma

In [28]: gamma.ppf(0.9, 3, scale=40)
Out[28]: 212.8928135133684

See also How to calculate the inverse of the normal cumulative distribution function in python?; the distribution is different there, but it is basically the same question.

invgamma is a different distribution.

Community
  • 1
  • 1
Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214