【问题标题】:How do you set the 'tail probabilities' in a scipy genextreme distribution?您如何在 scipy genextreme 分布中设置“尾部概率”?
【发布时间】:2014-02-17 19:01:59
【问题描述】:

有谁知道如何在 scipy 的 'genextreme' 分布中设置 'q' 参数(控制下尾概率或上尾概率)?

#/usr/bin/env python

将 numpy 导入为 np
将 pylab 导入为 plt
从 scipy.stats 导入 genextreme

mu, sigma = 10, 4
# 问题:如何在 genextreme 中设置 q,即下尾概率或上尾概率?
rv = genextreme(c=[0], loc=mu, scale=sigma)
x = np.linspace(0, 40, 50) # 从0-40生成50个值

y_pdf = rv.pdf(x)
plt.plot(x, y_pdf, 'ro-', label='PDF')

y_cdf = rv.cdf(x)
plt.plot(x, y_cdf, 'b*-', label='CDF')

plt.legend()
plt.show()

@Warren:感谢您提供的信息。我是 scipy 统计的新手。如何移动分布以使 pdf 在高端的权重更大?我尝试将“c”参数更改为 [0.9],但输出非常不稳定,曲棍球上升,然后几乎直线下降到零。

【问题讨论】:

    标签: statistics scipy


    【解决方案1】:

    q不是scipy的genextreme distribution的参数。它是方法ppf(cdf 的倒数)和isf(生存函数的倒数)的参数。如果您查看其他发行版的文档 - 例如normgamma--您会看到所有类级别的文档字符串在其“参数”中列出了 q,但该文档是对所有方法的参数的概述。 genextreme 具有标准的位置和比例参数,以及一个形状参数,c

    例子:

    >>> genextreme.cdf(genextreme.ppf(0.95, c=0.5), c=0.5)
    0.94999999999999996
    

    您可以找到有关generalized extreme distribution on wikipedia 的更多信息,但请注意,scipy 中使用的 shape 参数与维基百科文章中的 shape 参数的符号相反。例如,以下生成维基百科图:

    import numpy as np
    import matplotlib.pyplot as plt
    from scipy.stats import genextreme
    
    # Create the wikipedia plot.
    plt.figure(1)
    x = np.linspace(-4, 4, 201)
    plt.plot(x, genextreme.pdf(x, 0.5), color='#00FF00', label='c = 0.5')
    plt.plot(x, genextreme.pdf(x, 0.0), 'r', label='c = 0')
    plt.plot(x, genextreme.pdf(x, -0.5), 'b', label='c = -0.5')
    plt.ylim(-0.01, 0.51)
    plt.legend(loc='upper left')
    plt.xlabel('x')
    plt.ylabel('Density')
    plt.title('Generalized extreme value densities')
    plt.show()
    

    结果:

    cloc + scale / c。下面创建了带有c = -0.25scale = 5loc = -scale / c 的分布图(因此支持的左端位于 0):

    c = -0.25
    scale = 5
    loc = -scale / c
    x = np.linspace(0, 80, 401)
    pdf = genextreme.pdf(x, c, loc=loc, scale=scale)
    plt.plot(x, pdf)
    plt.xlabel('x')
    plt.ylabel('Density')
    

    剧情:

    scipy 文档站点上的stats tutorial 提供了有关分发类的更多信息,包括关于shifting and scaling a distribution 的部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-22
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 2020-08-04
      • 1970-01-01
      相关资源
      最近更新 更多