Skip to contents

Build a sparse neighbor-weight matrix via k-NN, optionally filtered by radius

Usage

buildKNNWeights(
  ref_coords,
  query_coords = ref_coords,
  k = 10,
  radius = Inf,
  include.self = TRUE
)

Arguments

ref_coords

data.frame/matrix of coordinates for the *source* units (rows = e.g. cells or spots).

query_coords

data.frame/matrix of coordinates for the *output* units (rows = e.g. spatial neighborhoods or spots), columns X, Y. Defaults to `ref_coords`.

k

number of nearest neighbors to search per query point.

radius

numeric distance cutoff; neighbors farther than this are dropped. Use `Inf` (default) to keep all `k` neighbors regardless of distance.

include.self

a boolean specifying whether to include self from the knn.

Value

sparse dgCMatrix, dim = nrow(query_coords) x nrow(ref_coords)