Find highest-density intervals for an orientation distribution

Description

Identify the angular regions containing a chosen proportion of a measured or summed orientation distribution at its highest densities.

Usage

hpdi(x, mass = 0.954)

Arguments

x

A skyscapeR.spd or skyscapeR.pdf object, or one data frame/list with numeric components x and y.

mass

Probability mass, greater than zero and at most one. Default is 0.954.

Details

A distribution with several peaks can give several disjoint intervals. The mass parameter applies to the selected regions together; the result describes concentration of the supplied density rather than significance against a null model.

Uses the existing discrete density-threshold method: sort sampled densities, find the threshold reaching the requested fraction of their sum, and include all points tied at that threshold. Consequently, the selected mass can exceed the requested value. Densities need not sum to one.

Coordinates must be finite and strictly increasing on an equally spaced grid. Missing grid points are permitted when gaps are integer multiples of the smallest observed step; omitted points are treated as zero mass and split intervals. This accommodates cutoff-trimmed azimuth distributions. Other irregular grids are rejected; no unequal-width integration is done. A single point is permitted and returns a zero-width interval.

Densities must be finite, nonnegative and have a positive total. If a saved distribution contains negative densities, regenerate it from the inputs with coordtrans before estimating intervals. Endpoints are sampled coordinates, not interpolated boundaries. Regions crossing the azimuth wrap are reported separately at the two ends of the grid; they are not joined into a circular interval.

Hyndman (1996) defines a highest-density region by a common density threshold. The discrete grid and tie rule above implement that principle for sampled curves.

Value

For a PDF object, a list of interval matrices, one per distribution, even for a single distribution. For SPD or x/y input, one matrix. Each matrix has columns start and end, with ordered endpoints and one row per contiguous region, sorted by start.

Validation

Known tied, truncated and disjoint test distributions returned the expected interval endpoints and achieved the requested minimum discrete mass. See D01 validation in the technical manual.

In D02 the default transformation grid split the middle 80 percent highest-density region of a three-mode ridge case; a finer grid recovered the three reference regions. See the D02 check in the technical manual.

Scientific checks

References

Hyndman, R. J. (1996). Computing and Graphing Highest Density Regions. The American Statistician 50, 120-126. doi:10.1080/00031305.1996.10474359.

See Also

az.pdf, dec.pdf, spd, plot.skyscapeR.pdf

Examples

xx <- seq(-6, 6, by=0.01)
hpdi(data.frame(x=xx, y=stats::dnorm(xx)), mass=0.95)

# Two separated peaks produce two ordered intervals:
yy <- stats::dnorm(xx, -3, 0.5) + stats::dnorm(xx, 3, 0.5)
hpdi(data.frame(x=xx, y=yy), mass=0.8)

# PDF objects always return a list:
Az <- az.pdf(az=c(90,120), unc=2, verbose=FALSE)
hpdi(Az)