spdep_distance_swm {sdsfun} | R Documentation |
constructs spatial weight matrices based on distance
Description
Constructs 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 sf object. |
kernel |
(optional) The kernel function, can be one of |
k |
(optional) The number of nearest neighbours. Default is |
bandwidth |
(optional) The bandwidth, default is |
power |
(optional) Default is |
style |
(optional) |
zero.policy |
(optional) if |
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)} = {\left(2 \pi\right)}^{\frac{1}{2}} e^{- \frac{z^2}{2}}
For the equation above, z = d_{ij} / h_i
where h_i
is the bandwidth
Value
A matrix
Note
When kernel
is setting, using distance weight based on kernel function, Otherwise
the inverse distance weight will be used.
Examples
library(sf)
pts = 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)