The local neighbor match test is to assess the extent of overlap between k-nearest neighbors in geographical space and k-nearest neighbors in multi-attribute space.

neighbor_match_test(
  df,
  k,
  scale_method = "standardize",
  distance_method = "euclidean",
  power = 1,
  is_inverse = FALSE,
  is_arc = FALSE,
  is_mile = TRUE
)

Arguments

df

A subset of sf object with selected variables. E.g. guerry[c("Crm_prs", "Crm_prp", "Litercy")]

k

a positive integer number for k-nearest neighbors searching.

scale_method

(optional) One of the scaling methods 'raw', 'standardize', 'demean', 'mad', 'range_standardize', 'range_adjust' to apply on input data. Default is 'standardize' (Z-score normalization).

distance_method

(optional) The type of distance metrics used to measure the distance between input data. Options are 'euclidean', 'manhattan'. Default is 'euclidean'.

power

(optional) The power (or exponent) of a number says 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

A data.frame with two columns "Cardinality" and "Probability".

Examples

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
data <- guerry[c('Crm_prs','Crm_prp','Litercy','Donatns','Infants','Suicids')]
nbr_test <- neighbor_match_test(data, 6)
nbr_test
#>    Cardinality  Probability
#> 1            2 5.263800e-02
#> 2            3 3.743147e-03
#> 3            2 5.263800e-02
#> 4            2 5.263800e-02
#> 5            0           NA
#> 6            1 3.116170e-01
#> 7            1 3.116170e-01
#> 8            2 5.263800e-02
#> 9            3 3.743147e-03
#> 10           1 3.116170e-01
#> 11           3 3.743147e-03
#> 12           2 5.263800e-02
#> 13           1 3.116170e-01
#> 14           1 3.116170e-01
#> 15           0           NA
#> 16           2 5.263800e-02
#> 17           1 3.116170e-01
#> 18           2 5.263800e-02
#> 19           1 3.116170e-01
#> 20           2 5.263800e-02
#> 21           2 5.263800e-02
#> 22           1 3.116170e-01
#> 23           2 5.263800e-02
#> 24           3 3.743147e-03
#> 25           1 3.116170e-01
#> 26           1 3.116170e-01
#> 27           1 3.116170e-01
#> 28           4 1.108168e-04
#> 29           3 3.743147e-03
#> 30           3 3.743147e-03
#> 31           0           NA
#> 32           2 5.263800e-02
#> 33           2 5.263800e-02
#> 34           1 3.116170e-01
#> 35           1 3.116170e-01
#> 36           0           NA
#> 37           1 3.116170e-01
#> 38           0           NA
#> 39           2 5.263800e-02
#> 40           3 3.743147e-03
#> 41           3 3.743147e-03
#> 42           0           NA
#> 43           2 5.263800e-02
#> 44           1 3.116170e-01
#> 45           1 3.116170e-01
#> 46           1 3.116170e-01
#> 47           2 5.263800e-02
#> 48           2 5.263800e-02
#> 49           2 5.263800e-02
#> 50           4 1.108168e-04
#> 51           2 5.263800e-02
#> 52           2 5.263800e-02
#> 53           3 3.743147e-03
#> 54           2 5.263800e-02
#> 55           2 5.263800e-02
#> 56           1 3.116170e-01
#> 57           4 1.108168e-04
#> 58           3 3.743147e-03
#> 59           1 3.116170e-01
#> 60           3 3.743147e-03
#> 61           2 5.263800e-02
#> 62           2 5.263800e-02
#> 63           3 3.743147e-03
#> 64           0           NA
#> 65           3 3.743147e-03
#> 66           3 3.743147e-03
#> 67           0           NA
#> 68           1 3.116170e-01
#> 69           0           NA
#> 70           2 5.263800e-02
#> 71           2 5.263800e-02
#> 72           1 3.116170e-01
#> 73           3 3.743147e-03
#> 74           1 3.116170e-01
#> 75           1 3.116170e-01
#> 76           2 5.263800e-02
#> 77           5 1.151344e-06
#> 78           4 1.108168e-04
#> 79           2 5.263800e-02
#> 80           3 3.743147e-03
#> 81           1 3.116170e-01
#> 82           0           NA
#> 83           0           NA
#> 84           1 3.116170e-01
#> 85           2 5.263800e-02