adsmooth: Adaptive Kernel density estimation

Description Usage Arguments Value Note Author(s) Examples

Description

Generates kernel density estimates of data defined on polygonal regions. Automatically selects the global bandwidth (if necessary) via cross validation, and has boundary bias correction performed via an adaptive boundary kernel. Bias is of order h0^4 in the interior, and of order h0^2 for points on or near the boundary.

Usage

1
adsmooth(points, boundary, h0=0, kernel="gaussian", type="adaptivecorrected", nx=50, ny=50, plot=FALSE)

Arguments

points

a vector of x,y coordinates.

boundary

a polygon boundary file (list of vertices of boundary)

h0

the (global) smoothing bandwidth to use. If h0=0 it is chosen automatically via cross validation

kernel

a character string specifying the type of kernel to use. Choices are "gaussian" or "biweight"

type

a character string specifying the type of estimate used. Choices are "fixed", "fixedcorrected", "fixedcorrected0", "adaptive", "adaptivecorrected", and "adaptivecorrected0"

nx

the grid resolution in the x direction at which the estimate is evaluated

ny

the grid resolution in the y direction at which the estimate is evaluated

plot

whether or not adsmooth should plot the resulting estimate

Value

p

the kernel density estimate, in (x,y,z) coordinates

Note

Large data sets (eg > 1000 points) will take a reasonable length of time (more than 30 seconds) to generate the "adaptivecorrected" estimate if cross validation is to be used to generate the global bandwidth.

The "corrected0" estimates are estimates formed by dividing each kernel by the amount of weight contained within the boundary. "corrected" estimates use a linear boundary kernel.

Author(s)

Jonathan Marshall J.C.Marshall@massey.ac.nz

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## load in some data from the splancs library
library(splancs)
data(southlancs)
## compute adaptive kernel estimate and plot directly
p <- adsmooth(southlancs.pts[southlancs.cc == 0,],southlancs.bdy, plot=TRUE)
## compute the adaptive kernel without plotting, on a refined scale
p <- adsmooth(southlancs.pts[southlancs.cc == 0,],southlancs.bdy,nx=100,ny=100)
## plot the boundary
polymap(southlancs.bdy,border="grey")
## plot as a contour plot
contour(p, nlevels=10, add=TRUE,drawlabels=FALSE)
## overlay the case points
pointmap(southlancs.pts[southlancs.cc == 1,], add=TRUE, pch=19, col="green")
title("Density map using adaptive smoothing on controls.  Cases in green.")

jmarshallnz/adsmooth documentation built on May 19, 2019, 1:51 p.m.