I’m attempting to calculate the 89% credible interval for a posterior distribution of an estimate of a proportion (and so the result is necessarily bounded by [0,1]) in R using the bayestestR package.
However when using the HDI() from the bayestestR library the result is CI low 5.15e-260 & CI high 1.09 (faint blue lines on the plot below).
ci_hdi <- distributionDF%>%
filter(variable=="posterior")%>%
select("Mechanism")%>%
hdi(ci = 0.89, method="HDI")
(There are 1560 observations for this variable, so I have included the data here but see below for an MRE)
Prior, Likelihood and Posterior Distributions with CI
I assumed I was making an error somewhere so I reproduced the example from the vignette, and got a similar result:
library(bayestestR)
library(ggplot2)
ci_hdi <-ci(posterior, method = "HDI")
ci_eti <-ci(posterior, method = "ETI")
posterior <- distribution_beta(1000, 6, 2)
output <- estimate_density(posterior, extend = TRUE)
ggplot(
output, aes(x=x,y=y))+
geom_area(fill = "yellow")+
theme_classic()+
#HDI in blue
geom_vline(xintercept =ci_hdi$CI_low, colour = "royalblue", linewidth = 3)+
geom_vline(xintercept =ci_hdi$CI_high, colour = "royalblue", linewidth = 3)+
#ETI in red
geom_vline(xintercept =ci_eti$CI_low, colour = "red", linewidth = 3)+
geom_vline(xintercept =ci_eti$CI_high, colour = "red", linewidth = 3)
Resulting posterior distribution with CI
Is there occurring because the densities (variable) is not normalised to one?
skepticMedic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.