kernel()
creates a raster using a kernel density estimator of the density of points in a "points" GVector
.
# S4 method for GVector
kernel(x, y, kernel = "Epanechnikov", optimize = TRUE, h = NULL)
A GRaster
.
A "points" GVector
.
A GRaster
: The extent and resolution of this raster will be used to create the density raster. Otherwise, values in this raster are ignored.
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.
Logical: If TRUE
(default), then attempt to find the optimal radius less than or equal to the radius
value using the "Gaussian" kernel. If FALSE
, use the radius
value as-is.
Numeric or NULL
(default): Smoothing bandwidth of kernel estimator.
If this is NULL
, the Epanechnikov kernel is used, and optimize
is TRUE
, then Silverman's rule-of-thumb is used to estimate the optimal value of h
:
If the Gaussian kernel is used, and optimize
is TRUE
, then the GRASS v.kernel
function will attempt to identify the optimal bandwidth, up to the value of h
, if h
is defined.
Otherwise, if h
is NULL
, 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.
GRASS manual page for module v.kernel
(see grassHelp("v.kernel")
)
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)
}
Run the code above in your browser using DataLab