贝叶斯-泊松分布。MLE,R中的前后分析

贝叶斯-泊松分布。MLE,R中的前后分析,r,R,我是这个网站的新手,我也在R中迈出了第一步 我在github上找到了类似的代码(用于二项分布),并试图将其应用到泊松分布中。结果是。。。嗯/ 有人能帮我把情节表现出来吗?怎么了 我所需要的是具有先验、后验和最大似然的图。 我也尝试使用dgamma(x,a,b),但结果出乎意料 GammaPriorPostPlot <- function(a,b,n,p){ standarizedLikelihood = dgamma(dane2, n*p+1, n*(1-p)+1) pri

我是这个网站的新手,我也在R中迈出了第一步

我在github上找到了类似的代码(用于二项分布),并试图将其应用到泊松分布中。结果是。。。嗯/ 有人能帮我把情节表现出来吗?怎么了

我所需要的是具有先验、后验和最大似然的图。 我也尝试使用dgamma(x,a,b),但结果出乎意料

GammaPriorPostPlot <- function(a,b,n,p){
    standarizedLikelihood = dgamma(dane2, n*p+1, n*(1-p)+1)
    prior = dgamma(dane2, a, b)
    posterior = dgamma(dane2, a+n*p, b+n*(1-p))
    maxDensity <- max(standarizedLikelihood, prior, posterior) # Use to make the y-axis high enough
    plot(dane2, standarizedLikelihood, type = 'l', lwd = 3, col = "blue", xlim <- c(0,1), ylim <- c(0, maxDensity), xlab = "theta", 
            ylab = 'density', main = 'Gamma(a,b)')
    lines(dane2, posterior, lwd = 3, col = "red")
    lines(dane2, prior, lwd = 3, col = "green")
    legend(x = 0.01, 
              y = maxDensity*0.95, 
              legend = c("likelihood", "Prior",  "Posterior"), 
              col = c("blue","green","red"), 
              lwd = c(3,3,3), cex = 0.7)
}

 manipulate(GammaPriorPostPlot(a,b,n,p),
            a = slider(1, 100, step=1, initial = 100, label = "a"),
            b = slider(1, 100, step=1, initial = 2, label = "b"),
            n = slider(1, 1000, step=1, initial = 10, label = "num of observations"),
            p = slider(0, 1, step=0.01, initial = 0.4, label = "success probability")

GammaPriorPostPlot
结果是。。。嗯/请更具体一些。它会给出一个错误吗?它没有显示情节吗?dane2是什么。。。当你调用
操纵
时,你认为我们已经加载了什么包?不幸的是,它只显示了一个带有图例的空白图,没有MLE行,前面和后面。即使在操纵滑块时,绘图中的线条也不会显示。对,这是操纵程序包。dane2是来自第三列(女性人数)范围(dane2[[3]])#[1]41 81
的数据向量,但xlim是c(0,1),进一步使用“