Learn R Programming

pscl (version 0.5)

betaHPD: Compute and optionally plot beta HDRs

Description

Compute and optionally plot highest density regions for the Beta distribution

Usage

betaHPD(alpha,beta,p=.95,plot=FALSE)

Arguments

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

Value

  • 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.

Details

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 $\alpha > 1$ and $\beta > 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) d\theta = p$$ and $$f(\theta) > f(\theta^*) \, \forall\ \theta \in \mathcal{Q}, \theta^* \not\in \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; \alpha, \beta) d\theta = p$$

See Also

pbeta, qbeta, dbeta, uniroot

Examples

Run this code
betaHPD(4,5)
betaHPD(2,120)

Run the code above in your browser using DataLab