我尝试将直方图和伽马分布计算的最大似然估计结合起来,而直方图表示x的观测值,而线表示伽马分布计算的最大似然估计值。示例图如下所示:
然而,X轴的直方图长度为13,而X轴的伽马分布长度为512,它一直抱怨`
错误:美学必须是长度1或与数据相同
(13):X,Y
den <- density(x) # x's length is 13, however den's length is 512
dat <- data.frame(x = den$x, y = den$y)
dataframe = data.frame(days = days, x = x)
ggplot(data = dat) +
geom_line(aes(x=dat$x, y=dgamma(dat$x,shape, rate)), color="red", size = 1) +
theme_classic()
bplot = ggplot(data = dataframe,aes(x = dataframe$days, y = (dataframe$x)/sum(dataframe$x)));
bplot +
geom_bar(stat="identity", width=0.5)+
geom_line(aes(x=dat$x, y=dgamma(dat$x,shape, rate)), color="blue", size = 1)