gpt4 book ai didi

python - 为什么 Frechet 分布在 scipy.stats 和 R 中不同

转载 作者:太空宇宙 更新时间:2023-11-04 03:31:58 26 4
gpt4 key购买 nike

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

R分布: R frechet

与 Scipy 分布: scipy frechet

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()

编辑 - 相关文档。

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

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

最佳答案

我没有使用 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()

Python Frechet distribution

关于python - 为什么 Frechet 分布在 scipy.stats 和 R 中不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30783440/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com