【发布时间】:2014-09-01 22:16:35
【问题描述】:
我需要 python 中某些分布的分位数。在 r 中,可以使用 qf、qnorm 和 qchi2 函数计算这些值。
有没有这些 R 函数的 python 等价物? 我一直在寻找 scipy 但我没有找到任何东西。
【问题讨论】:
我需要 python 中某些分布的分位数。在 r 中,可以使用 qf、qnorm 和 qchi2 函数计算这些值。
有没有这些 R 函数的 python 等价物? 我一直在寻找 scipy 但我没有找到任何东西。
【问题讨论】:
您可以在scipy.stats 中找到概率分布。每个发行版都定义了一组函数,例如,如果您转到norm 发行版并向下滚动页面,您可能会发现其中包含的方法
ppf(q, loc=0, scale=1) # Percent point function (inverse of cdf — percentiles)
这就是scipy 调用百分比点函数 并执行R q 函数所做的事情。
例如:
>>> from scipy.stats import norm
>>> norm.ppf(.5) # half of the mass is before zero
0.0
其他发行版的界面相同,比如chi^2:
>>> from scipy.stats import chi2
>>> chi2.ppf(.8, df=2) # two degress of freedom
3.2188758248682015
【讨论】:
qnorm 等效的操作。
NORMINV()函数,可以帮助未来的搜索者(谷歌人)。
R pnorm() 函数的等价物是:scipy.stats.norm.cdf() with python
R qnorm() 函数的等价物是:scipy.stats.norm.ppf() with python
【讨论】: