Kernel Smoothing of a Two-Dimensional Density

DESCRIPTION:

Smooths a two-dimensional process using kernels.

USAGE:

kern2d(x, y, bw=<<see below>>, nx=25, ny=25, 
       lims=c(range(x), range(y)), kernfun=dnorm) 

REQUIRED ARGUMENTS:

x
numeric vector with the X-coordinates of the two-dimensional process
y
numeric vector with the Y-coordinates of the two-dimensional process. This must be the same length as x.

OPTIONAL ARGUMENTS:

bw
bandwidth parameter. This should be a numeric vector with 2 components, giving the values desired for the bandwidth in each of the x or the y directions. If only one number, then the same value will be repeated for both directions. See the DETAILS section for its default.
nx
integer. Number of X-points in the grid used by the kernel estimators. Defaults to 25.
ny
integer. Number of Y-points in the grid used by the kernel estimators. Defaults to 25.
lims
numeric vector with 4 components defining the bounding box of the two-dimensional process to smooth.
kernfun
the kernel function. Use the function dnorm for the Gaussian kernel, or kernquart for the quartic. This can be any function that takes a one-dimensional vector and returns its smoothed version.

VALUE:

a list with 4 components as follows:
x,y
numeric vectors containing the gridded values in the horizontal and vertical directions respectively.
z
estimates of intensity corresponding to x, y respectively.
bw
the input or estimated bandwidth parameter.

DETAILS:

The returned value may be given to the function image for a graphical display of intensity over the area enclosed by boundary.

The bandwidth parameter default value is determined using Venables and Ripley's (1994) suggested "rule of thumb" for the Inter Quantile Range R and the Gaussian kernel of bandwidth the standard deviation, bw <- 4*1.06*min(sqrt(var(x)), R/1.34)*length(x)^(-1/5) Ideally, the user should try several values before deciding on an useful bandwidth, perhaps starting with the default above.

This function is based on Venables and Ripley's kde2d function.

REFERENCES:

Venables, W. N. and Ripley, B. D. (1994). Modern Applied Statistics with S-Plus. Springer-Verlag, New York.

SEE ALSO:

, .

EXAMPLES:

plot(geyser$duration, geyser$waiting, type="n") 
image(kern2d(geyser$duration, geyser$waiting)) 
points(geyser$duration, geyser$waiting)