kde: Kernel Density Estimation

View source: R/kde.R

kdeR Documentation

Kernel Density Estimation

Description

KDE for spatial data. The algorithm is heavily inspired by Heatmap tool in QGIS. The help for QGIS tools is provided at the QGIS website. The a tutorial is provided here.

Usage

kde(
  points,
  band_width,
  decay = 1,
  kernel = c("quartic", "uniform", "triweight", "epanechnikov", "triangular"),
  scaled = FALSE,
  weights = c(),
  grid,
  cell_size,
  quiet = FALSE
)

Arguments

points

sf data.frame containing only POINTS.

band_width

numeric specifying the band width for KDE.

decay

numeric specifying the decay parameter for "triangular" kernel. For other kernels besides "triangular" the parameter is not used.

kernel

character specifying type of kernel to use. Available implemented kernels are "uniform", "quartic", "triweight", "epanechnikov", "triangular". Default is "quartic" and if unknown kernel name is used it falls back to the default value.

scaled

logical specifying if the output values should be scaled. Default value is FALSE.

weights

numeric vector of weights for individual points.

grid

either sf data.frame (outcome of function create_grid_rectangular or create_grid_hexagonal) or Raster-class (outcome of function create_raster). Does not have to be specified if cell_size is set.

cell_size

numeric specifying the distance for equal spaced points. Must be higher than 0. Can be left out if grid is provided as grid is used instead. The code used to generate grid is create_grid_rectangular(points, cell_size, band_width).

quiet

Should printing of progress bar be suppressed? Default 'FALSE'.

Details

grid parameter specifies output of the function. KDE is calculated on the specified grid. If grid is Raster-class then outcome is also Raster-class. If grid is sf data.frame then outcome is also sf data.frame.

Value

either sf data.frame or Raster-class depending on class of grid parameter.

Examples

library(sf)
nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(32031)
grid <- create_grid_hexagonal(nc, cell_size = 100000)
points <- st_sample(nc, 500) %>% st_as_sf()
kde_estimate_grid <- kde(points, band_width = 150000, grid = grid)
raster <- create_raster(nc, cell_size = 100000)
kde_estimate_raster <- kde(points, band_width = 150000, grid = raster)


SpatialKDE documentation built on March 7, 2023, 6:25 p.m.