utils-density2d: Bivariate Density Tools

utils-density2dR Documentation

Bivariate Density Tools

Description

Kernel density estimator and histogram counter for bivariate distributions

Usage

density2d(x, y = NULL, n = 20, h = NULL, limits = c(range(x), range(y))) 

hist2d(x, y = NULL, n = c(20, 20))

Arguments

x, y

two vectors of coordinates of data. If y is NULL then x is assumed to be a two column matrix, where the first column contains the x data, and the second column the y data.

n

n - an integer specifying the number of grid points in each direction. The default value is 20.
[hist2D] -
In this case n may be a scalar or a two element vector. The default value is 20.

h

a vector of bandwidths for x and y directions. Defaults to normal reference bandwidth.

limits

the limits of the rectangle covered by the grid.

Value

density2d and hist2d return a list with three elements $x, $y, and $z. x and y are vectors spanning the two dimensional grid and z the corresponding matrix. The output can directly serve as input to the plotting functions image, contour and persp.

Author(s)

W.N. Venables and B.D. Ripley for the underlying kde2d function,
Gregory R. Warnes for the underlying hist2d function,
Diethelm Wuertz for the Rmetrics R-port.

References

Azzalini A., (2004); The sn Package; R Reference Guide available from www.r-project.org.

Venables W.N., Ripley B.D., (2002); Modern Applied Statistics with S, Fourth Edition, Springer.

Warnes G.R., (2004); The gregmisc Package; R Reference Guide available from www.r-project.org.

Examples

## hist2d - 
   # Normal Random Numbers:
   set.seed(4711)
   X <- rnorm2d(40000)
   # 2D Histogram Plot:
   Z <- hist2d(X)
   image(Z)
   contour(Z, add=TRUE)

fMultivar documentation built on July 9, 2023, 3:08 p.m.