kde: Kernel Density Estimation

Description Usage Arguments Details Value Examples

View source: R/kde.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
kde(
  points,
  band_width,
  decay = 1,
  kernel = c("quartic", "uniform", "triweight", "epanechnikov", "triangular"),
  scaled = FALSE,
  weights = c(),
  grid,
  cell_size
)

Arguments

points

sf data.frame containing only POINTS.

band_width

numeric specifing the band width for KDE.

decay

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

kernel

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

scaled

logical specifing 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 specifing 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).

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

1
2
3
4
5
6
7
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 Nov. 29, 2020, 1:07 a.m.