View source: R/v03_NNGP_neighbors.R
| computeNeighbors | R Documentation |
Computes ordered neighbor sets based on Vecchia's approximation for a set of spatial coordinates. Locations are first ordered by their x-coordinate, and neighbors are selected from previously ordered locations.
computeNeighbors(coords, k, proj)
coords |
Numeric matrix ( |
k |
Positive integer. Number of neighbors for each location. |
proj |
Coordinate reference system (CRS) used to compute distances. Can be an EPSG code
(e.g., 4326) or a CRS object compatible with |
Neighbor selection follows a Vecchia-type ordering. For each location i,
neighbors are chosen from the set of previously ordered locations 1, \dots, i-1.
Distances are computed using sf::st_distance and depend on the CRS.
The first location has no neighbors. For the first k+1 locations, all previous
locations are used as neighbors. For subsequent locations, the k nearest
neighbors among previously ordered points are selected.
A list with components:
Matrix of coordinates sorted by x-coordinate
Matrix (M \times M) of pairwise distances between sorted coordinates
Binary matrix (M \times M) indicating neighbor relationships
Matrix (M \times k) of neighbor indices for each location
Matrix (M \times k) of distances to neighbors
Fabian Ketwaroo
st_distance
coords <- matrix(runif(40), ncol = 2)
res <- computeNeighbors(coords, k = 5, proj = 4326)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.