View source: R/gw_core_functions.R
| gw_get_nearby | R Documentation |
Returns a function for determining an index of nearby observations for a specific location and for a given bandwidth. The returned function is expected to be used within a 'function factory' approach. The returned function requires the following inputs: a distance matrix ('dist_mat'), an adaptive or fixed bandwidth, 'bw', and a location for which the index is calculated ('obs_index').
gw_get_nearby(adaptive)
adative |
A logical value TRUE or FALSE to indicate whether an adaptive or fixed bandwidth distance is being used. |
A function that returns an index of nearby observations, given an observation, ('obs_index'), a distance matrix ('dist_mat'), within the specified bandwidth, 'bw', for a given location ('obs_index').
# load some packages and data
library(tmap)
data(georgia)
# define a distance matrix, a location and an adaptive bandwidth
dist_mat = as.matrix(dist(st_coordinates(st_centroid(georgia)), upper = T, diag = T))
obs_index = 30
bw = 30
# create the function
nearby_func = gw_get_nearby(adaptive = TRUE)
# apply to get an index of locations
index = nearby_func(obs_index, dist_mat, bw)
# map the result
tm_shape(georgia)+tm_polygons()+
tm_shape(georgia[index,])+tm_fill("red", alpha = 0.5)+
tm_shape(georgia[obs_index,])+tm_fill("black")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.