data(cars)
flist <- alist(
dist ~ dnorm( mu , sigma ) ,
mu <- a+b*speed ,
c(a,b) ~ dnorm(0,1) ,
sigma ~ dexp(1)
)
fit <- quap( flist ,
start=list(a=40,b=0.1,sigma=20) ,
data=cars )
samp <- extract.samples(fit, n = 100)
HPDI(samp)
> HPDI(samp)
|0.89 0.89|
-1.942856 2.685888
> coda::HPDinterval(coda::as.mcmc(x), prob = 0.89)
lower upper
a -1.724315 1.735476
b 2.721952 3.141751
sigma 12.080041 16.184893
attr(,"Probability")
[1] 0.89
This is due to the sapply() wrongly flattening the result returned by the coda code.