R/old_scripts/hdi.R

library("HDInterval")

tst2 <- c(rnorm(1e5), rnorm(5e4, 7))
hist(tst2, freq=FALSE)
(hdiMC <- hdi(tst2))
segments(hdiMC[1], 0, hdiMC[2], 0, lwd=3, col= "red" )


dens2 <- density(tst2)
lines(dens2, lwd=2, col= "blue" )
(hdiD1 <- hdi(dens2))  # default allowSplit = FALSE; note the warning
(ht <- attr(hdiD1, "height"))
segments(hdiD1[1], ht, hdiD1[2], ht, lty=3, col= "blue" )
(hdiD2 <- hdi(dens2, allowSplit=TRUE))
segments(hdiD2[, 1], ht, hdiD2[, 2], ht, lwd=3, col= "blue" )
tintinthong/pfilter documentation built on May 24, 2019, 9:55 a.m.