// BetaHDI returns the Highhest Density Interval limits of the Beta Distribution.
func BetaHDI(α, β, credMass, tol float64) (lo, hi float64) {
	f := iwFix(α, β, credMass)
	// func fmin(f func(float64) float64, ax, bx, tol float64) float64 {

	min := fmin(f, 0, 1-credMass, tol)
	lo = dst.BetaQtlFor(α, β, min)
	hi = dst.BetaQtlFor(α, β, credMass+min)
	return lo, hi
}
Exemple #2
0
// Binomial proportion, credible interval, beta prior, equal tail area.
// Bolstad 2007 (2e): 153
// untested ...
func BinomPiCrIBP(α, β, alpha float64, n, k int64) (low, upp float64) {
	// k-observed successes
	// n - total number of observations
	// α - beta prior a
	// β - beta prior b
	// alpha - posterior probability that the true proportion lies outside the credible interval

	low = dst.BetaQtlFor(alpha/2.0, α+float64(k), β+float64(n-k))
	upp = dst.BetaQtlFor(1.0-alpha/2.0, α+float64(k), β+float64(n-k))
	return
}
// Interval width
func iw(α, β, credMass, lowTailPr float64) float64 {
	return dst.BetaQtlFor(α, β, credMass+lowTailPr) - dst.BetaQtlFor(α, β, lowTailPr)
}