betaHPD {pscl} | R Documentation |
Compute and optionally plot highest density regions for the Beta distribution
betaHPD(alpha,beta,p=.95,plot=FALSE)
alpha |
scalar, first shape parameter of the Beta density. Must be greater than 1, see details |
beta |
scalar, second shape parameter of the Beta density. Must be greater than 1, see details |
p |
scalar, content of HPD, must lie between 0 and 1 |
plot |
logical flag, if TRUE then plot the density and
show the HDR |
The Beta density arises frequently in Bayesian models of binary events, rates, and proportions, which take on values in the unit interval. For instance, the Beta density is a conjugate prior for the unknown success probability in binomial trials. With shape parameters α > 1 and β > 1, the Beta density is unimodal.
In general, a highest density region of f(theta) with content p in [0,1] is a set of regions mathcal{Q} of the parameter space with the following properties:
int_mathcal{Q} f(theta) dtheta = p
and
f(theta) > f(theta^*) , forall theta in mathcal{Q}, theta^* notin mathcal{Q}
For a continuous, unimodal density defined with respect to a single parameter (like the Beta case considered here), a HDR region is a contiguous interval in [0,1].
This function uses numerical methods are used to solve for the
boundaries of a HDR region for the Beta density, via repeated calls
the functions dbeta
, pbeta
and
qbeta
. The function uniroot
is used to
find points v and w such that
f(v) = f(w)
subject to the constraint
int_v^w f(theta; α, β) dtheta = p
If the numerical optimization is successful an vector of length 2,
containing v and w, defined above. If the optimization
fails for whatever reason, a vector of NAs
is returned.
Simon Jackman <jackman@stanford.edu>
betaHPD(4,5) betaHPD(2,120)