kern_xy | R Documentation |
Given a base X/Y dataset, calculates guassian kernel density for nearby points in feat dataset
kern_xy(base, feat, bandwidth, weight = 1)
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 |
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.
A vector of densities (or weighted densities)
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.
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
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.