Last data update: 2014.03.03

R: Normal scale rule for bivariate KDE bandwidths
NSR Documentation

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 giving the observed data from which we wish to calculate the NS bandwidth. See ‘Details’ for further information.

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 the interquartile ranges (IQR) of the x and y data values divided by 1.34 (Gaussian IQR).

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).

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.

Author(s)

T.M. Davies

References

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

Examples


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))

Results