简体   繁体   中英

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. I have the prior distribution π_1 (θ) = Be (1.5, 1.5).

Here is my R code:

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.

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM