displayNeighbors: Plot neighbor sets for a Nearest-Neighbor Gaussian Process...

View source: R/v03_NNGP_neighbors.R

displayNeighborsR Documentation

Plot neighbor sets for a Nearest-Neighbor Gaussian Process (NNGP)

Description

Visualizes the neighbor set for a given location based on an ordered Nearest-Neighbor Gaussian Process (NNGP) constructed using Vecchia's approximation.

Usage

displayNeighbors(ind, coords.sorted, neighbor_idx, proj)

Arguments

ind

Integer index of the focal location (in the sorted order).

coords.sorted

Numeric matrix (M \times 2) of spatial coordinates sorted according to the ordering used in the NNGP construction. Output from computeNeighbors.

neighbor_idx

Integer matrix (M \times k) where each row contains the indices of the neighbors for a given location. Output from computeNeighbors.

proj

Coordinate reference system (CRS) used for plotting. Can be an EPSG code or a CRS object compatible with sf.

Details

The function assumes that coordinates and neighbor indices are based on an ordered representation of the data (e.g., sorted by x-coordinate or another ordering used in Vecchia's approximation).

The neighbor set for location i consists of previously ordered locations, as defined by the NNGP construction.

Value

A ggplot2 object showing:

  • All spatial locations (black markers)

  • The focal location (red point)

  • Its neighbors (blue points)

  • A vertical reference line at the focal location's x-coordinate

Author(s)

Fabian Ketwaroo

See Also

computeNeighbors

Examples

coords <- matrix(runif(40), ncol = 2)
res <- computeNeighbors(coords, k = 5, proj = 4326)
p <- displayNeighbors(
  ind = 10,
  coords.sorted = res$coords_sorted,
  neighbor_idx = res$neighbor_idx,
  proj = 4326
)
print(p)


BayesNSGP documentation built on Sept. 10, 2026, 5:08 p.m.