Function for constructing inverse distance weight.
Arguments
- sfj
Vector object that can be converted to
sf
bysf::st_as_sf()
.- power
(optional) Default is 1. Set to 2 for gravity weights.
- bandwidth
(optional) When the distance is bigger than bandwidth, the corresponding part of the weight matrix is set to 0. Default is
NULL
, which means not use the bandwidth.
Examples
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
pts = read_sf(system.file('extdata/pts.gpkg',package = 'sdsfun'))
wt = inverse_distance_swm(pts)
wt[1:5,1:5]
#> 1 2 3 4 5
#> 1 0.000000e+00 5.813118e-05 1.654238e-04 3.818149e-05 7.868869e-05
#> 2 5.813118e-05 0.000000e+00 7.576789e-05 2.988167e-05 3.913838e-05
#> 3 1.654238e-04 7.576789e-05 0.000000e+00 4.239359e-05 7.877952e-05
#> 4 3.818149e-05 2.988167e-05 4.239359e-05 0.000000e+00 6.845458e-05
#> 5 7.868869e-05 3.913838e-05 7.877952e-05 6.845458e-05 0.000000e+00