[英]Posterior distribution missing from plots
I'm trying to use R to calculate a posterior distribution and produce a triplot gragh for my prior, likelihood and posterior distribution.我正在尝试使用 R 来计算后验分布并为我的先验分布、似然分布和后验分布生成三重图。 I have the prior distribution π_1 (θ) = Be (1.5, 1.5).
我有先验分布 π_1 (θ) = Be (1.5, 1.5)。
Here is my R code:这是我的 R 代码:
n <- 25
X <- 16
a <- 1.5
b <- 1.5
grid <- seq(0,1,.01)
like <- dbinom(X,n,grid)
like
like <- like/sum(like)
like
prior <- dbeta(grid,a,b)
prior1 <- prior/sum(prior)
post <- like*prior
post <- post/sum(post)
It does give me a Triplot but I also want to get the value for my posterior distribution, but it seems something missing in my code.它确实给了我一个 Triplot,但我也想获得我的后验分布的值,但我的代码中似乎缺少一些东西。
To clarify, I am looking for the posterior distribution of θ for the above prior distribution为了澄清,我正在寻找上述先验分布的 θ 的后验分布
In addition, I have tried:此外,我尝试过:
install.packages("LearnBayes")
library("LearnBayes")
prior = c( a= 1.5, b = 1.5 )
data = c( s = 25, f = 16 )
triplot(prior,data)
It gives me a perfect Triplot, but again no value for posterior.它给了我一个完美的三线图,但同样没有后验价值。
It's there, but just that the prior is so weakly informative ( Beta[a=1.5, b=1.5]
is nearly uniform) that the likelihood function differs very little from the posterior.它就在那里,但只是先验信息太弱(
Beta[a=1.5, b=1.5]
几乎是一致的),以至于似然函数与后验差异很小。 An intuitive way to think about this is that a+b-2
is 1, meaning the prior is effectively only supported by 1 previous observation, whereas N
is 25, meaning the data is supported by 25 observations.一个直观的思考方式是
a+b-2
是 1,这意味着先验有效地只得到 1 个先前观察的支持,而N
是 25,这意味着数据得到了 25 个观察的支持。 This leads to the data dominating the posterior in terms of contributing information.这导致数据在贡献信息方面主导后验。
Changing the prior to be stronger will make the difference more apparent:将先验更改为更强将使差异更加明显:
prior <- c(a=10, b=10)
data <- c(s=25, f=16)
triplot(prior, data)
Note, there is nothing wrong with using a weakly informative prior, if that is all the information that is available.请注意,如果这是所有可用的信息,那么使用弱信息先验并没有错。 When the observed data is large enough, it should dominate the posterior.
当观察到的数据足够大时,它应该主导后验。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.