Create a distance-based weights

distance_weights(
  sf_obj,
  dist_thres,
  power = 1,
  is_inverse = FALSE,
  is_arc = FALSE,
  is_mile = TRUE
)

Arguments

sf_obj

An sf (simple feature) object

dist_thres

A positive numeric value of distance threshold

power

(optional) The power (or exponent) of a number indicates how many times to use the number in a multiplication.

is_inverse

(optional) FALSE (default) or TRUE, apply inverse on distance value

is_arc

(optional) FALSE (default) or TRUE, compute arc distance between two observations

is_mile

(optional) TRUE (default) or FALSE, convert distance unit from mile to km.

Value

An instance of Weight-class

Examples

library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
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
dist_thres <- min_distthreshold(guerry)
dist_w <- distance_weights(guerry, dist_thres)
summary(dist_w)
#>                      name              value
#> 1 number of observations:                 85
#> 2          is symmetric:                TRUE
#> 3               sparsity: 0.0434602076124567
#> 4        # min neighbors:                  1
#> 5        # max neighbors:                  7
#> 6       # mean neighbors:   3.69411764705882
#> 7     # median neighbors:                  4
#> 8           has isolates:              FALSE