相当于 R 的 qnorm、qf 和 qchi2 [英] python equivalent of qnorm, qf and qchi2 of R
问题描述
我需要 python 中某些分布的分位数.在 r 中,可以使用 qf、qnorm 和 qchi2 函数计算这些值.
是否有与这些 R 函数等效的 Python 函数?我一直在寻找 scipy 但我没有找到任何东西.
您可以在 scipy.stats
.每个发行版都定义了一组函数,例如,如果您转到 norm
分布并向下滚动页面,您可能会找到包含
ppf(q, loc=0, scale=1) #百分比点函数(cdf的倒数——百分位数)
这就是 scipy 调用 Percent point function 并执行 R q 函数所做的.
例如:
<预><代码>>>>从 scipy.stats 导入规范>>>norm.ppf(.5) # 质量的一半在零之前0.0其他发行版的界面相同,比如chi^2
:
I need the quantile of some distributions in python. In r it is possible to compute these values using the qf, qnorm and qchi2 functions.
Is there any python equivalent of these R functions? I have been looking on scipy but I did non find anything.
You may find probability distributions in scipy.stats
. Every distribution defines a set of functions, for example if you go to norm
distribution and scroll down the page you may find the methods which include
ppf(q, loc=0, scale=1) # Percent point function (inverse of cdf — percentiles)
that is what scipy calls Percent point function and does what R q functions do.
For example:
>>> from scipy.stats import norm
>>> norm.ppf(.5) # half of the mass is before zero
0.0
Same interface for other distributions, say chi^2
:
>>> from scipy.stats import chi2
>>> chi2.ppf(.8, df=2) # two degress of freedom
3.2188758248682015
这篇关于相当于 R 的 qnorm、qf 和 qchi2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!