Create a k-nearest neighbors based spatial weights
knn_weights(
sf_obj,
k,
power = 1,
is_inverse = FALSE,
is_arc = FALSE,
is_mile = TRUE
)
An sf (simple feature) object
a positive integer number for k-nearest neighbors
(optional) The power (or exponent) of a number says how many times to use the number in a multiplication.
(optional) FALSE (default) or TRUE, apply inverse on distance value
(optional) FALSE (default) or TRUE, compute arc distance between two observations
(optional) TRUE (default) or FALSE, convert distance unit from mile to km.
An instance of Weight-class
library(sf)
guerry_path <- system.file("extdata", "Guerry.shp", package = "rgeoda")
guerry <- st_read(guerry_path)
#> Reading layer `Guerry' from data source
#> `/Users/runner/work/_temp/Library/rgeoda/extdata/Guerry.shp'
#> using driver `ESRI Shapefile'
#> Simple feature collection with 85 features and 29 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: 47680 ymin: 1703258 xmax: 1031401 ymax: 2677441
#> Projected CRS: NTF (Paris) / Lambert zone II
knn6_w <- knn_weights(guerry, 6)
summary(knn6_w)
#> name value
#> 1 number of observations: 85
#> 2 is symmetric: FALSE
#> 3 sparsity: 0.0705882352941176
#> 4 # min neighbors: 6
#> 5 # max neighbors: 6
#> 6 # mean neighbors: 6
#> 7 # median neighbors: 6
#> 8 has isolates: FALSE