kernel() creates a raster using a kernel density estimator of the density of points in a "points" GVector.
Usage
# S4 method for class 'GVector'
kernel(x, y, kernel = "Epanechnikov", optimize = TRUE, h = NULL)Arguments
- x
A "points"
GVector.- y
A
GRaster: The extent and resolution of this raster will be used to create the density raster. Otherwise, values in this raster are ignored.- kernel
Character: Name of the kernel function to use. Possible values include:
"Epanechnikov"(default)"Gaussian""uniform""triangular""quartic""triweight""cosine"
Partial matching is used, and case is ignored.
- optimize
Logical: If
TRUE(default), then attempt to find the optimal radius less than or equal to theradiusvalue using the "Gaussian" kernel. IfFALSE, use theradiusvalue as-is.- h
Numeric or
NULL(default): Smoothing bandwidth of kernel estimator.If this is
NULL, the Epanechnikov kernel is used, andoptimizeisTRUE, then Silverman's rule-of-thumb is used to estimate the optimal value ofh: $$h = 0.9 * min(\sigma_x / n^1/6, \sigma_y / n^1/6)$$If the Gaussian kernel is used, and
optimizeisTRUE, then the GRASSv.kernelfunction will attempt to identify the optimal bandwidth, up to the value ofh, ifhis defined.Otherwise, if
hisNULL, then the value will be arbitrarily set at 1/5th of the shorter of the distance of the x- and y-extent of the points.
Examples
if (grassStarted()) {
# Setup
library(sf)
library(terra)
# Elevation raster, plant specimen collections, rivers vector,
# outline of area vector
madElev <- fastData("madElev")
madDypsis <- fastData("madDypsis")
# Convert to fasterRaster format:
elev <- fast(madElev)
dypsis <- fast(madDypsis)
# Kernel density estimation:
kde <- kernel(dypsis, elev)
plot(kde)
plot(dypsis, add = TRUE, pch = 1)
}
