gw_get_nearby: Nearby observations

View source: R/gw_core_functions.R

gw_get_nearbyR Documentation

Nearby observations

Description

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').

Usage

gw_get_nearby(adaptive)

Arguments

adative

A logical value TRUE or FALSE to indicate whether an adaptive or fixed bandwidth distance is being used.

Value

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').

Examples

# 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") 

gwverse/gw documentation built on May 4, 2022, 1:46 a.m.