Made `real-dist-hpd-interval' return type more precise; documented

This commit is contained in:
Neil Toronto 2014-03-26 15:25:40 -06:00
parent 32e8ec76b0
commit 970eed82af
2 changed files with 15 additions and 1 deletions

View File

@ -254,6 +254,20 @@ the two endpoints are swapped first.) The @racket[log?] and @racket[1-p?] argume
meaning of the return value in the same way as the corresponding arguments to @racket[cdf].
}
@defproc[(real-dist-hpd-interval [d Real-Dist] [α Real]) (Values Flonum Flonum)]{
Finds the smallest interval for which @racket[d] assigns probability @racket[α], if one exists.
@examples[#:eval untyped-eval
(define d (beta-dist 3 2))
(define-values (x0 x1) (real-dist-hpd-interval d 0.8))
(plot (list
(function-interval (λ (x) 0) (distribution-pdf d) x0 x1
#:line1-style 'transparent
#:line2-style 'transparent
#:label "80% HPD region")
(function (distribution-pdf d) 0 1
#:label "Beta(3,2)")))]
}
@section{Finite Distribution Families}
@subsection{Unordered Discrete Distributions}

View File

@ -82,7 +82,7 @@
;; ===================================================================================================
;; Highest probability density (HPD) regions
(: real-dist-hpd-interval (-> Real-Dist Real (Values Real Real)))
(: real-dist-hpd-interval (-> Real-Dist Real (Values Flonum Flonum)))
(define (real-dist-hpd-interval d α)
(when (or (α . <= . 0) (α . > . 1))
(raise-argument-error 'real-dist-hpd-interval "Real in (0,1]" 1 d α))