
constructs spatial weight matrices based on distance
Source:R/spdep_helpers.R
      spdep_distance_swm.RdConstructs spatial weight matrices based on distance via spdep package.
Usage
spdep_distance_swm(
  sfj,
  kernel = NULL,
  k = NULL,
  bandwidth = NULL,
  power = 1,
  style = "W",
  zero.policy = TRUE
)Arguments
- sfj
 An
sfobject or can be converted tosfbysf::st_as_sf().- kernel
 (optional) The kernel function, can be one of
uniform,triangular,quadratic(epanechnikov),quarticandgaussian. Default isNULL.- k
 (optional) The number of nearest neighbours. Default is
NULL. Only useful whenkernelis provided.- bandwidth
 (optional) The bandwidth, default is
NULL. When the spatial reference of sf object is the geographical coordinate system, the unit ofbandwidthiskm. The unit used in the projection coordinate system are consistent with those used in the sf object coordinate system.- power
 (optional) Default is
1. Useful whenkernelis not provided.- style
 (optional)
stylecan take valuesW,B,C, andS. More to seespdep::nb2mat(). Default isW. For spatial weights based on distance functions, a style ofBmeans using the original value of the calculated distance function.- zero.policy
 (optional) if
FALSEstop with error for any empty neighbour sets, ifTRUEpermit the weights list to be formed with zero-length weights vectors. Default isTRUE.
Details
five different kernel weight functions:
uniform: \(K_{(z)} = 1/2\),for \(\lvert z \rvert < 1\)
triangular \(K_{(z)} = 1 - \lvert z \rvert\),for \(\lvert z \rvert < 1\)
quadratic (epanechnikov) \(K_{(z)} = \frac{3}{4} \left( 1 - z^2 \right)\),for \(\lvert z \rvert < 1\)
quartic \(K_{(z)} = \frac{15}{16} {\left( 1 - z^2 \right)}^2\),for \(\lvert z \rvert < 1\)
gaussian \(K_{(z)} = \frac{1}{\sqrt{2 \pi}} e^{- \frac{z^2}{2}}\)
For the equation above, \(z = d_{ij} / h_i\) where \(h_i\) is the bandwidth
Note
When kernel is setting, using distance weight based on kernel function, Otherwise
the inverse distance weight will be used.
Examples
pts = sf::read_sf(system.file('extdata/pts.gpkg',package = 'sdsfun'))
wt1 = spdep_distance_swm(pts, style = 'B')
wt2 = spdep_distance_swm(pts, kernel = 'gaussian')
wt3 = spdep_distance_swm(pts, k = 3, kernel = 'gaussian')
wt4 = spdep_distance_swm(pts, k = 3, kernel = 'gaussian', bandwidth = 10000)