compute_distance_matrix()
is a small helper function to help you compute a distance matrix.
For the geographically method to work, is is important that distances between points are not zero. This function allows to add a small random noise to avoid zero distances.
Arguments
- data
A dataframe or matrix containing at least two numerical columns.
- method
method to compute the distance matrix. Ultimately passed to
stats::dist()
. Can beeuclidean
,maximum
,manhattan
,canberra
,binary
orminkowski
.- add.noise
TRUE/FALSE set to TRUE to add a small noise to the distance matrix. Noise \(U\) is generated as \( U \sim (1\times 10^{-6}, 5\times 10^{-6})\). Noise is added only for pairs for which distance is zero.
Value
a distance matrix, usable in gwl_bw_estimation()
Examples
coords <- data.frame("Lat" = rnorm(200), "Long" = rnorm(200))
distance_matrix <- compute_distance_matrix(coords)