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
knearneighfunction for -nearest neighbours returns aknnobject, converted to annbobject usingknn2nb - Computation speed boost through
dbscanpackage - The
nbdistsfunction 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