Learn R Programming

hdrcde (version 2.11)

hdr: Highest Density Regions

Description

Calculates and plots highest density regions in one dimension including the HDR boxplot.

Usage

hdr(x, prob = c(50, 95, 99), den, h=hdrbw(x,mean(prob)), nn=5000, all.modes=FALSE)
hdr.den(x, prob = c(50, 95, 99), den, h=hdrbw(x,mean(prob)), xlab=NULL, ylab="Density", ...)
hdr.boxplot(x, prob = c(99, 50), h=hdrbw(x,mean(prob)), boxlabels = "", col = gray((9:1)/10), 
    main="", xlab="", ylab="", pch=1, ...)

Arguments

x
Numeric vector containing data. In hdr and hdr.den, if x is missing then den must be provided, and the HDR is computed from the given density. For hdr.boxplot, x
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.
nn
Number of random numbers used in computing f-alpha quantiles.
all.modes
Return all local modes or just the global mode?
boxlabels
Label for each box plotted.
col
Colours for regions of each box.
main
Overall title for the plot.
xlab
Label for x-axis.
ylab
Label for y-axis.
pch
Plotting character.
...
Other arguments passed to plot.

Value

  • hdr.boxplot retuns nothing. hdr and hdr.den return a list of three components:
  • hdrThe endpoints of each interval in each HDR
  • modeThe estimated mode of the density.
  • falphaThe value of the density at the boundaries of each HDR.

Details

Either x or den must be provided. Hyndman's (1996) density quantile algorithm is used for calculation. hdr.den plots the density with the HDRs superimposed. hdr.boxplot displays a boxplot based on HDRs.

References

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

See Also

hdr.boxplot.2d

Examples

Run this code
hdr(faithful$eruptions)
hdr.boxplot(faithful$eruptions)
hdr.den(faithful$eruptions)

x <- c(rnorm(100,0,1), rnorm(100,4,1))
par(mfrow=c(1,2))
boxplot(x)
hdr.boxplot(x)
par(mfrow=c(1,1))
hdr.den(x)

Run the code above in your browser using DataLab