14.9 Distance-Based Neighbors
- Distance-based neighbours can be constructed using
dnearneigh
, with a distance band with lowerd1=
and upperd2=
bounds controlled by thebounds=
argument - The
knearneigh
function for -nearest neighbours returns aknn
object, converted to annb
object usingknn2nb
- Computation speed boost through
dbscan
package - The
nbdists
function returns the length of neighbour relationship edges
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 246.5 6663.4 8538.0 8275.1 10123.9 17978.8
Here the largest first nearest neighbour distance is just under 18 km, so using this as the upper threshold gives certainty that all units will have at least one neighbour.
# maybe no neighbors
coords |> dnearneigh(0, 16000) -> nb_d16
# at least one neighbor
coords |> dnearneigh(0, 18000) -> nb_d18
- Adding 300 m to the threshold gives us a neighbour object with no no-neighbour units, and all units can be reached from all others across the graph.
It is possible to control the numbers of neighbours directly using -nearest neighbours, either accepting asymmetric neighbours