【问题标题】:Why do the Frechet distributions differ in scipy.stats vs R为什么 Frechet 分布在 scipy.stats 与 R 中不同
【发布时间】:2015-06-11 14:18:09
【问题描述】:

我在 R 中安装了一个 frechet 发行版,并希望在 python 脚本中使用它。然而,在 scipy.stats.frechet_r 中输入相同的分布参数会给我一条非常不同的曲线。这是我的实现中的错误还是 scipy 中的错误?

R 分布:

vs Scipy 分布:

R frechet 参数:loc=17.440, shape=0.198, scale=8.153

python 代码:

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

F=frechet_r(loc=17.440  ,scale= 8.153, c=   0.198)              
x=np.arange(0.01,120,0.01)
ax.plot(x, F.pdf(x), 'k-', lw=2)

plt.show()

编辑 - 相关文档。

Frechet 参数是在 R 中使用 'evd' 包 http://cran.r-project.org/web/packages/evd/evd.pdf 中的 fgev 函数计算的(第 40 页)

scipy 文档的链接: http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.frechet_r.html#scipy.stats.frechet_r

【问题讨论】:

  • 您是自己编写 Frechet 代码还是从包裹中获得的?您能否提供指向 Python 版本和 R 版本文档的链接(或发布您的代码)?最可能的可能性只是参数化的差异。
  • @BenBolker 备用参数化解释也是我的想法。如果我是 mysticvisionnnn,我可能会尝试使用 scale = 1/8.153 或 c = 1/0.198 并查看其中任何一个是否与 R 给出的匹配。不过最好还是追踪文档。

标签: python r scipy distribution


【解决方案1】:

我没有使用 scipy.stats 中的 frechet_r 函数(当我快速测试它时,我得到了与你相同的情节),但你可以从 scipy.stats 中的 genextreme 获得所需的行为。值得注意的是,对于 genextreme,Frechet 和 Weibull 形状参数具有与通常情况相反的符号。也就是说,在您的情况下,您需要使用 -0.198 的形状参数:

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

x=np.arange(0.01,120,0.01)
# The order for this is array, shape, loc, scale
F=gev.pdf(x,-0.198,loc=17.44,scale=8.153)

plt.plot(x,F,'g',lw=2)
plt.show()

【讨论】:

    猜你喜欢
    • 2021-04-10
    • 2016-09-13
    • 2019-01-25
    • 2018-10-15
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    相关资源
    最近更新 更多