当我运行这个时:
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 轴绘制一条平坦的线。
我在这里做错了什么?
最佳答案
您的模型系数不正确。速率参数应接近 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)
关于r - Hist中Gamma分布的拟合曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54110221/