nb_match_test: Local Neighbor Match Test

View source: R/nb-match-test-impl.R

nb_match_testR Documentation

Local Neighbor Match Test

Description

Implements the Local Neighbor Match Test as described in Tobler's Law in a Multivariate World (Anselin and Li, 2020).

Usage

nb_match_test(
  x,
  nb,
  wt = st_weights(nb),
  k = 10,
  nsim = 499,
  scale = TRUE,
  .method = "euclidian",
  .p = 2
)

Arguments

x

a numeric vector or a list of numeric vectors of equal length.

nb

a neighbor list object for example as created by st_contiguity().

wt

a weights list as created by st_weights().

k

the number of neighbors to identify in attribute space. Should be the same as number of neighbors provided in st_knn.

nsim

the number of simulations to run for calculating the simulated p-value.

scale

default TRUE. Whether x should be scaled or not. Note that measures should be standardized.

.method

default "euclidian". The distance measure passed to stats::dist().

.p

default 2. The power of Minkowski distance passed to the p argument in stats::dist().

Value

a data.frame with columns

  • n_shared (integer): the number of shared neighbors between geographic and attribute space

  • nb_matches (list): matched neighbor indexes. Each element is an integer vector of same length as the ith observation of n_shared

  • knn_nb (list): the neighbors in attribute space

  • probability (numeric): the geometric probability of observing the number of matches

  • p_sim (numeric): a folded simulated p-value

Examples


if (requireNamespace("dplyr", quietly = TRUE)) {
library(magrittr)
guerry %>%
  dplyr::transmute(nb = st_knn(geometry, k = 10),
         nmt = nb_match_test(list(crime_pers, literacy, suicides),
                             nb, nsim = 999)) %>%
  tidyr::unnest(nmt)
 }

sfdep documentation built on Sept. 13, 2024, 5:07 p.m.