用于广义帕累托分布的具有多条密度曲线的叠加直方图

Posted

技术标签:

【中文标题】用于广义帕累托分布的具有多条密度曲线的叠加直方图【英文标题】:Overlay histogram with multiple density curves for generalized pareto distribution 【发布时间】:2021-08-21 02:59:48 【问题描述】:

我想为广义帕累托分布绘制具有多条密度曲线的叠加直方图。如您所见,密度曲线不清晰可见。他们有什么办法说清楚吗?谢谢。

library(eva)
data(lowestoft)
data = as.vector(lowestoft)

d1 = dgpd(data, 0,  31.38105, 10.15003)
d2 = dgpd(data, 0, 2.9431553, 0.6778055)
d3 = dgpd(data,0, 5.413916, 17.162103)
d4 = dgpd(data,0, 43.18705, 13.98005)


N = length(data)
allden = c(d1, d2, d3, d4)
settings = c(rep('d1', N), rep('d2', N), 
             rep('d3', N), rep('d4', N))


mydata = data.frame(x= rep(data, 4), allden = allden, Methods = settings)

ggplot(mydata, aes(x)) +
  geom_histogram(aes(y = stat(density)), binwidth = 1, fill = "grey", color = "black")+
  geom_line(aes(x = x, y=allden, color = Methods)) 

【问题讨论】:

【参考方案1】:

您可以做的一件事是像这样为geom_line 添加一个单独的缩放 y 轴

library(eva)
data(lowestoft)
data = as.vector(lowestoft)

d1 = dgpd(data, 0,  31.38105, 10.15003)
d2 = dgpd(data, 0, 2.9431553, 0.6778055)
d3 = dgpd(data,0, 5.413916, 17.162103)
d4 = dgpd(data,0, 43.18705, 13.98005)


N = length(data)
allden = c(d1, d2, d3, d4)
settings = c(rep('d1', N), rep('d2', N), 
             rep('d3', N), rep('d4', N))


mydata = data.frame(x= rep(data, 4), allden = allden, Methods = settings)

coef <- 8
ggplot(mydata, aes(x,allden)) +
  geom_histogram(aes(y = stat(density)), binwidth = 1, fill = "grey", color = "black") +
  geom_line(aes(x = x, y=allden*coef, color = Methods)) +
  scale_y_continuous(name="Histogram Axis",
                     sec.axis = sec_axis(trans~./coef, name='Line Axis'))

【讨论】:

以上是关于用于广义帕累托分布的具有多条密度曲线的叠加直方图的主要内容,如果未能解决你的问题,请参考以下文章

积累分布用例-洛伦兹曲线和随机游走

用密度曲线叠加直方图

综述:广义的分布外检测(异常检测、开集识别、OOD检测)

使用 ggplot2 沿平滑曲线绘制直方图或密度

R语言自定义编写函数生成学生化残差的直方图(dist of studentized residuals),并叠加标准正太曲线核密度曲线轴须图rug曲线检验模型是否满足正态性(normality)

tableau-创建帕累托图