我想用 Python 翻译以下 Matlab 代码:
tau=40 %scale parameter
a=3 %shape parameter
t = gaminv(0.90,a,tau);
代码返回 t = 212.8928。我试过:
import scipy.stats.distributions as dist
tau=40
a=3
t = dist.invgamma.cdf(90, a, scale = tau)
但是 python 代码不会返回相同的 t 值。我做错了什么吗?
请您参考如下方法:
您需要 scipy.stats.gamma 的 ppf(“百分比函数”,这是 CDF 或分位数函数的反函数的不太常见的名称)方法:
In [27]: from scipy.stats import gamma
In [28]: gamma.ppf(0.9, 3, scale=40)
Out[28]: 212.8928135133684
另见 How to calculate the inverse of the normal cumulative distribution function in python? ;那里的分布不同,但基本上是同一个问题。
invgamma是不同的分布。
