Learn R Programming

sparr (version 0.2-2)

OS: Maximal smoothing principle (oversmoothing) for bivariate KDE bandwidths

Description

Provides an (isotropic) bandwidth estimate for use in bivariate KDE based on the oversmoothing factor introduced by Terrell (1990).

Usage

OS(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 OS 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. If NA (default), the scaling value is set as the mean of the interquartile ranges (IQR) of the x and y data

Value

  • A single numeric value of the estimated bandwidth.

Details

This function calculates a smoothing bandwidth for kernel density estimates of bivariate data, following the maximal smoothing priciple of Terrell (1990). 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

Davies, T.M. and Hazelton, M.L. (2010), Adaptive kernel estimation of spatial relative risk, Statistics in Medicine, 29(23) 2423-2437. Terrell, G.R. (1990), The maximal smoothing principle in density estimation, Journal of the American Statistical Association, 85, 470-477.

Examples

Run this code
data(PBC)

##Using geometric mean of case and control counts as n
n1 <- sum(PBC$data[,3])
n2 <- nrow(PBC$data) - n1

OS(data = PBC$data[,1:2], nstar = sqrt(n1 * n2))

##Scaling bandwidth for case data using standard deviations
sd.x <- sd(PBC$data[PBC$data[,3]==1,1])
sd.y <- sd(PBC$data[PBC$data[,3]==1,2])

OS(data = PBC$data[PBC$data[,3]==1,1:2], scaler = mean(sd.x, sd.y))

Run the code above in your browser using DataLab