Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

hdr

Highest Density Regions


Description

Calculates highest density regions in one dimension

Usage

hdr(
  x = NULL,
  prob = c(50, 95, 99),
  den = NULL,
  h = hdrbw(BoxCox(x, lambda), mean(prob)),
  lambda = 1,
  nn = 5000,
  all.modes = FALSE
)

Arguments

x

Numeric vector containing data. If x is missing then den must be provided, and the HDR is computed from the given density.

prob

Probability coverage required for HDRs

den

Density of data as list with components x and y. If omitted, the density is estimated from x using density.

h

Optional bandwidth for calculation of density.

lambda

Box-Cox transformation parameter where 0 <= lambda <= 1.

nn

Number of random numbers used in computing f-alpha quantiles.

all.modes

Return all local modes or just the global mode?

Details

Either x or den must be provided. When x is provided, the density is estimated using kernel density estimation. A Box-Cox transformation is used if lambda!=1, as described in Wand, Marron and Ruppert (1991). This allows the density estimate to be non-zero only on the positive real line. The default kernel bandwidth h is selected using the algorithm of Samworth and Wand (2010).

Hyndman's (1996) density quantile algorithm is used for calculation.

Value

A list of three components:

hdr

The endpoints of each interval in each HDR

mode

The estimated mode of the density.

falpha

The value of the density at the boundaries of each HDR.

Author(s)

Rob J Hyndman

References

Hyndman, R.J. (1996) Computing and graphing highest density regions. American Statistician, 50, 120-126.

Samworth, R.J. and Wand, M.P. (2010). Asymptotics and optimal bandwidth selection for highest density region estimation. The Annals of Statistics, 38, 1767-1792.

Wand, M.P., Marron, J S., Ruppert, D. (1991) Transformations in density estimation. Journal of the American Statistical Association, 86, 343-353.

See Also

Examples

# Old faithful eruption duration times
hdr(faithful$eruptions)

hdrcde

Highest Density Regions and Conditional Density Estimation

v3.4
GPL-3
Authors
Rob Hyndman [aut, cre, cph] (<https://orcid.org/0000-0002-2140-5352>), Jochen Einbeck [aut] (<https://orcid.org/0000-0002-9457-2020>), Matthew Wand [aut] (<https://orcid.org/0000-0003-2555-896X>), Simon Carrignon [ctb] (<https://orcid.org/0000-0002-4416-1389>), Fan Cheng [ctb] (<https://orcid.org/0000-0003-0009-3262>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.