Learn R Programming

weird (version 3.1.0)

hdr_regions: Highest density regions for each observation

Description

For a dist_kde object, determine which highest density region (HDR) each observation falls in, for one or more coverage probabilities. Some densities are multimodal, so the HDR for a given prob can consist of several disjoint regions; the returned columns identify the specific region (1, 2, ...) that each observation falls in, ordered from lowest to highest along the first variable, with NA for observations outside the HDR at that prob.

Usage

hdr_regions(object, prob)

Value

A tibble containing the data used to estimate object, along with one additional integer column per element of prob (named hdr_<100*prob>) showing which region of the corresponding HDR each observation falls in.

Arguments

object

A dist_kde object, as returned by dist_kde(), containing a single distribution estimated from univariate or bivariate data.

prob

A numeric vector of probabilities giving the HDR coverage (between 0 and 1).

Author

Rob J Hyndman

See Also

hdr_table, gg_hdrboxplot

Examples

Run this code
dist_kde(oldfaithful$duration) |> hdr_regions(c(0.5, 0.95))
dist_kde(oldfaithful[, c("duration", "waiting")]) |> hdr_regions(0.90)

Run the code above in your browser using DataLab