Learn R Programming

ptools (version 2.0.0)

kern_xy: Kernel density of nearby areas

Description

Given a base X/Y dataset, calculates guassian kernel density for nearby points in feat dataset

Usage

kern_xy(base, feat, bandwidth, weight = 1)

Value

A vector of densities (or weighted densities)

Arguments

base

base dataset (eg gridcells), needs to be SpatialPolygonsDataFrame or SpatialPointsDataFrame

feat

feature dataset (eg another crime generator), needs to be SpatialPointsDataFrame

bandwidth

scaler bandwidth for the normal KDE

weight

if 1 (default), does not use weights, else pass in string that is the variable name for weights in feat

Details

This generates a density of nearby features at particular control points (specified by base). Useful for risk terrain style feature engineering given nearby crime generators. Loops through all pairwise distances (and uses dnorm()). So will be slow for large base + feature datasets (although should be OK memory wise). Consider aggregating/weighting data if feat is very large.

References

Caplan, J. M., Kennedy, L. W., & Miller, J. (2011). Risk terrain modeling: Brokering criminological theory and GIS methods for crime forecasting. Justice Quarterly, 28(2), 360-381.

Wheeler, A. P., & Steenbeek, W. (2021). Mapping the risk terrain for crime using machine learning. Journal of Quantitative Criminology, 37(2), 445-480.

See Also

dist_xy() for calculating distance to nearest

count_xy() for counting points inside polygon

kern_xy() for estimating gaussian density of points for features at base polygon xy coords

bisq_xy() to estimate bi-square kernel weights of points for features at base polygon xy coords

idw_xy() to estimate inverse distance weights of points for features at base polygon xy coords

Examples

Run this code
# \donttest{
data(nyc_cafe); data(nyc_bor)
gr_nyc <- prep_grid(nyc_bor,15000)
gr_nyc$kdecafe_5k <- kern_xy(gr_nyc,nyc_cafe,8000)
head(gr_nyc@data)
sp::spplot(gr_nyc,zcol='kdecafe_5k')
# }

Run the code above in your browser using DataLab