Learn R Programming

sparr (version 0.3-2)

NS: Normal scale rule for bivariate KDE bandwidths

Description

Provides the (isotropic) optimal bandwidth for a bivariate normal density based on a simple expression.

Usage

NS(data, nstar = NULL, scaler = NA)

Arguments

data
An object of type data.frame, list, matrix, or ppp givin
nstar
A single numeric, positive value to use in place of the number of observations n in the NS formula. If NULL (default), n will simply be the number of observations in data.
scaler
A single numeric, positive value to use for transforming the result with respect to the scale of the recorded data (i.e. a scalar representation of the standard deviation of the data). If NA (default), the scaling value is set as the mean of

Value

  • A single numeric value of the estimated bandwidth.

Warning

The NS bandwidth is an approximation, and assumes that the target density is bivariate normal. This is considered rare in e.g. epidemiological applications. Nevertheless, it remains a quick and easy `rule-of-thumb' method with which one may obtain a smoothing parameter in general applications.

Details

This function calculates a smoothing bandwidth for kernel density estimates of 2-dimensional data: the optimal value which would minimise the asymptotic mean integrated squared error of the bivariate normal density function, assuming the standard Gaussian kernel function. See Wand and Jones (1995) for example. If the data argument is a data.frame or a matrix, this must have exactly two columns containing the x ([,1]) and y ([,2]) data values. Should data be a list, this must have two vector components of equal length named x and y. Alternatively, data may be an object of class ppp (see ppp.object).

References

Wand, M.P. and Jones, C.M., 1995. Kernel Smoothing, Chapman & Hall, London.

Examples

Run this code
data(PBC)
PBC.casedata <- split(PBC)[[1]]
PBC.controldata <- split(PBC)[[2]]

pbc.h <- NS(PBC, nstar = sqrt(PBC.casedata$n * PBC.controldata$n))


##Scaling bandwidth for case data using standard deviations
sd.x <- sd(PBC.casedata$x)
sd.y <- sd(PBC.casedata$y)

NS(data = PBC.casedata, scaler = mean(sd.x, sd.y))

Run the code above in your browser using DataLab