scipy.stats.gengamma#

scipy.stats.gengamma = <scipy.stats._continuous_distns.gengamma_gen object>[source]#

广义伽马连续随机变量。

作为 rv_continuous 类的实例,gengamma 对象继承了它的一组通用方法(详见下面的完整列表),并使用此特定分布的详细信息完成它们。

方法

rvs(a, c, loc=0, scale=1, size=1, random_state=None)

随机变量。

pdf(x, a, c, loc=0, scale=1)

概率密度函数。

logpdf(x, a, c, loc=0, scale=1)

概率密度函数的对数。

cdf(x, a, c, loc=0, scale=1)

累积分布函数。

logcdf(x, a, c, loc=0, scale=1)

累积分布函数的对数。

sf(x, a, c, loc=0, scale=1)

生存函数(也定义为 1 - cdf,但 sf 有时更准确)。

logsf(x, a, c, loc=0, scale=1)

生存函数的对数。

ppf(q, a, c, loc=0, scale=1)

百分点函数(cdf 的逆函数——百分位数)。

isf(q, a, c, loc=0, scale=1)

逆生存函数(sf 的逆函数)。

moment(order, a, c, loc=0, scale=1)

指定阶数的非中心矩。

stats(a, c, loc=0, scale=1, moments=’mv’)

均值(‘m’),方差(‘v’),偏度(‘s’)和/或峰度(‘k’)。

entropy(a, c, loc=0, scale=1)

RV 的(微分)熵。

fit(data)

通用数据的参数估计。 有关关键字参数的详细文档,请参见 scipy.stats.rv_continuous.fit

expect(func, args=(a, c), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds)

函数(一个参数)关于分布的期望值。

median(a, c, loc=0, scale=1)

分布的中位数。

mean(a, c, loc=0, scale=1)

分布的均值。

var(a, c, loc=0, scale=1)

分布的方差。

std(a, c, loc=0, scale=1)

分布的标准差。

interval(confidence, a, c, loc=0, scale=1)

中位数周围具有相等面积的置信区间。

另请参见

gamma, invgamma, weibull_min

注释

gengamma 的概率密度函数为 ([1])

\[f(x, a, c) = \frac{|c| x^{c a-1} \exp(-x^c)}{\Gamma(a)}\]

对于 \(x \ge 0\), \(a > 0\), 并且 \(c \ne 0\)\(\Gamma\) 是伽马函数 (scipy.special.gamma)。

gengamma 接受 \(a\)\(c\) 作为形状参数。

上面的概率密度以“标准化”形式定义。 要移动和/或缩放分布,请使用 locscale 参数。 具体来说,gengamma.pdf(x, a, c, loc, scale)gengamma.pdf(y, a, c) / scale 完全等效,其中 y = (x - loc) / scale。 请注意,移动分布的位置不会使其成为“非中心”分布; 一些分布的非中心推广版本在单独的类中提供。

参考文献

[1]

E.W. Stacy, “Gamma Distribution 的泛化”, Annals of Mathematical Statistics, Vol 33(3), pp. 1187–1192.

示例

>>> import numpy as np
>>> from scipy.stats import gengamma
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1, 1)

获取支持

>>> a, c = 4.42, -3.12
>>> lb, ub = gengamma.support(a, c)

计算前四个矩

>>> mean, var, skew, kurt = gengamma.stats(a, c, moments='mvsk')

显示概率密度函数 (pdf)

>>> x = np.linspace(gengamma.ppf(0.01, a, c),
...                 gengamma.ppf(0.99, a, c), 100)
>>> ax.plot(x, gengamma.pdf(x, a, c),
...        'r-', lw=5, alpha=0.6, label='gengamma pdf')

或者,可以调用分布对象(作为函数)来固定形状、位置和比例参数。 这将返回一个“冻结”的 RV 对象,该对象保存给定的固定参数。

冻结分布并显示冻结的 pdf

>>> rv = gengamma(a, c)
>>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

检查 cdfppf 的准确性

>>> vals = gengamma.ppf([0.001, 0.5, 0.999], a, c)
>>> np.allclose([0.001, 0.5, 0.999], gengamma.cdf(vals, a, c))
True

生成随机数

>>> r = gengamma.rvs(a, c, size=1000)

并比较直方图

>>> ax.hist(r, density=True, bins='auto', histtype='stepfilled', alpha=0.2)
>>> ax.set_xlim([x[0], x[-1]])
>>> ax.legend(loc='best', frameon=False)
>>> plt.show()
../../_images/scipy-stats-gengamma-1.png