r - Hist中Gamma分布的拟合曲线

标签 r plot histogram curve-fitting

当我运行这个时:

x<-c(73,6,77,81,91,120,150,61,65,68,18,20,23,12,14,18,23,26,26,27,2,3,3,40,41,41,6,10,11,12,37,38,38,6,73,6,51)
a<-1.286486;b<-30.59584

hist(x,breaks=c(0,20,40,60,80,100,120,160),probability = T,xaxt="n")
curve(dgamma(x,a,b),from=0,to=160,col="red",lwd=2,add=T)

它应该在直方图上生成 Gamma 分布曲线。相反,它只是沿着 x 轴绘制一条平坦的线。

enter image description here

我在这里做错了什么?

最佳答案

您的模型系数不正确。速率参数应接近 0.03。

x<-c(73,6,77,81,91,120,150,61,65,68,18,20,23,12,14,18,23,26,26,27, 2,3,3,40,41,41,6,10,11,12,37,38,38,6,73,6,51)

library(fitdistrplus)
model<-fitdist(x, "gamma")
print(model$estimate)
#    shape      rate 
#1.1911710 0.0311047 
a=model$estimate[1]
b=model$estimate[2]    

h<-hist(x,breaks=c(0,20,40,60,80,100,120,160),probability = T)
curve(dgamma(x,a,b),from=0,to=160,col="red",lwd=2,add=T)

enter image description here

关于r - Hist中Gamma分布的拟合曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54110221/

相关文章:

r - 获取星期二的向量,但如果星期二适逢假期,则将其替换为 R 中的星期三

r - 了解 Shiny Server 上托管的 R Shiny 应用程序的可扩展性

python - plotly,python,在其他子图上绘制直方图?

gnuplot - gnuplot 直方图上的平滑线

r - 根据条件从数据帧创建具有二进制值的 df

通过分组(以另一个变量为条件)对列进行R排序

plot - Gnuplot:用定义半径的圆绘图

python - 如何在 Python 中的同一个图上绘制两个不同的间隔时间序列

python - 在 python 中绘制填充的多边形

sql - 如何在 SQL 中制作对数直方图?