diff --git a/pkgs/math-pkgs/math-doc/math/scribblings/math-distributions.scrbl b/pkgs/math-pkgs/math-doc/math/scribblings/math-distributions.scrbl index d9d2cbffef..bcadafe6b8 100644 --- a/pkgs/math-pkgs/math-doc/math/scribblings/math-distributions.scrbl +++ b/pkgs/math-pkgs/math-doc/math/scribblings/math-distributions.scrbl @@ -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} diff --git a/pkgs/math-pkgs/math-lib/math/private/distributions/dist-functions.rkt b/pkgs/math-pkgs/math-lib/math/private/distributions/dist-functions.rkt index c1c7e9be13..35a849a385 100644 --- a/pkgs/math-pkgs/math-lib/math/private/distributions/dist-functions.rkt +++ b/pkgs/math-pkgs/math-lib/math/private/distributions/dist-functions.rkt @@ -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 α))