[R] Bayesian 95% Credible interval
Brunero Liseo
brunero.liseo at gmail.com
Fri Apr 6 21:07:36 CEST 2012
This is a function I use when the posterior is unimodal
I do not remember but I think I found it somewhere in the web
brunero
hpd<-function(x,p){
#generate an hpd set of level p, based
#on a sample x from the posterior
dx<-density(x)
md<-dx$x[dx$y==max(dx$y)]
px<-dx$y/sum(dx$y)
pxs<--sort(-px)
ct<-min(pxs[cumsum(pxs)< p])
list(hpdr=range(dx$x[px>=ct]),mode=md)
}
2012/4/6 Gyanendra Pokharel <gyanendra.pokharel at gmail.com>:
> Hi all,
> I have the data from the posterior distribution for some parameter. I want
> to find the 95% credible interval. I think "t.test(data)" is only for the
> confidence interval. I did not fine function for the Bayesian credible
> interval. Could some one suggest me?
>
> Thanks
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
=========================================================
Brunero Liseo
Dip. di metodi e modelli per il territorio, l'economia e la finanza
Sapienza Università di Roma
Tel. +39 06 49766973
Fax +39 06 4957606
http://geostasto.eco.uniroma1.it/utenti/liseo
=========================================================
More information about the R-help
mailing list