R:如何使用 ggplot2 的 stat_function 绘制gumbel分布
如果这相当脆弱,请耐心等待,如果我遗漏了任何内容,请随时提出问题...
我正在尝试根据以下链接进行一些 50 年极端风力计算
http://www.wasp.dk/Products/weng/ExtremeWinds.htm
他们似乎使用分布,所以我使用包“evir”中的函数gumbel来拟合数据的分布,并使用包“evd”中的函数dgumbel作为绘图函数。
package("evd")
package("evir")
speeds2 <- data.frame(speed=sample(10:50,1000,rep=TRUE))
gumbel(speeds2$speed)
然后我尝试使用 ggplot2 的 stat_function 来绘制它,就像这样(除了现在我已经为 loc 和 scale 输入了虚拟值。
library(ggplot2)
ggplot(data=speeds2, aes(x=speed)) +
stat_function(fun=dgumbel, args=list(loc=1, scale=0.5))
我收到以下错误:
Error in dgev(x, loc = loc, scale = scale, shape = 0, log = log) :
unused argument(s) (loc = loc, scale = scale, shape = 0, log = log)
我不确定我是否以正确的方式这样做。任何指针都会是非常感谢。
Please bear with me if this is rather tenuous, and feel free to ask questions if I have left anything out...
I'm attempting to do some 50 year extreme wind calculations based on the following link
http://www.wasp.dk/Products/weng/ExtremeWinds.htm
They seem to use the gumbel distribution, so I have used function gumbel in package "evir" to fit the distribution to the data, and function dgumbel in package "evd" as the plotting function.
package("evd")
package("evir")
speeds2 <- data.frame(speed=sample(10:50,1000,rep=TRUE))
gumbel(speeds2$speed)
I have then tried to plot this using ggplot2's stat_function, like so (except for now I have put in dummy values for loc and scale.
library(ggplot2)
ggplot(data=speeds2, aes(x=speed)) +
stat_function(fun=dgumbel, args=list(loc=1, scale=0.5))
I get the following error:
Error in dgev(x, loc = loc, scale = scale, shape = 0, log = log) :
unused argument(s) (loc = loc, scale = scale, shape = 0, log = log)
I am unsure if I am doing this the right way. Any pointers would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我编写的一个通用函数,用于简化具有拟合密度和经验密度的数据绘制。
以下是如何使用它的两个示例
示例 1:拟合 Gumbel
示例 2:拟合正态分布
Here is a generic function that I wrote to simplify plotting of data with fitted and empirical densities.
Here are two examples of how you would use it
Example 1: Fit a Gumbel
Example 2: Fit a Normal Distribution
早些时候的会议显示,gumbel 调用的参数估计值接近 24 和 11。
如果您仅使用 1 和 0.5 的参数,您会得到一条直线。仅加载
evd
可以防止与evir
中与 dgumbel 相关的函数发生冲突。当您第二次加载evir
时,您会得到:演示如何在特定(表现更好)包中调用
dgumbel
函数:我认为 Ramnath 的建议是添加经验 '密度'很好,但我更喜欢使用 geom_histogram:
Earlier session showed that the parameter estimates from the gumbel call were near 24 and 11.
If you only used the parameters of 1 and 0.5, you got a straight flat line. Loading only
evd
prevents conflicts with the dgumbel-related functions inevir
. When you loadevir
second you get:Demonstrating how to make a call to a
dgumbel
function in a particular (better behaved) package:I think Ramnath's suggestion to add the empiric 'density' is good but I prefer to use geom_histogram:
通过对代码进行少量修改(添加几何图形),它对我来说效果很好。
With a small, modification to your code (adding a geom) it works fine for me.