mNearestN function

m nearest neighbors based on a distance matrix

m nearest neighbors based on a distance matrix

This function finds the m nearest neighbors, given a matrix of distances.

mNearestN(distMat, m = 5, listv = FALSE, rn = FALSE)

Arguments

  • distMat: distance matrix
  • m: number of nearest neighbors, default value 5
  • listv: logical, default FALSE. If TRUE the list of neighbors should also be returned
  • rn: logical, default FALSE. If TRUE, the spatial weights matrix will be row-normalized

Returns

  • W: spatial weights matrix

  • nlist: list of indexes of the m nearest neighbors

Examples

data(gN3dist, package = "SDPDmod") fournn <- mNearestN(gN3dist, m = 4) mat1 <- rownor(fournn) tennn <- mNearestN(gN3dist, 10, listv = TRUE, rn = TRUE) mat2 <- tennn$W

Author(s)

Rozeta Simonovska

  • Maintainer: Rozeta Simonovska
  • License: GPL (>= 3)
  • Last published: 2024-04-13

Useful links