Evaluates a Gaussian KDE on incident lat/long and returns summary
statistics plus the (lat, lon) of the densest observation. Prefers
MASS::kde2d when available; otherwise uses a pure
base-R Gaussian kernel evaluated at the observation points (i.e.
kernel density at each datum).
Usage
morie_tps_kde_density(
df,
bandwidth = 0.005,
ds_name = "?",
lat_col = "LAT_WGS84",
lon_col = "LONG_WGS84"
)Value
A named list with summary stats including max/mean/median density and the (lat, lon) of the densest observation.
Examples
set.seed(2026)
df <- data.frame(
LAT_WGS84 = 43.6 + rnorm(120, 0, 0.05),
LONG_WGS84 = -79.4 + rnorm(120, 0, 0.05)
)
morie_tps_kde_density(df, bandwidth = 0.01)
#> KDE -- ?
#> ========
#> Call: morie_tps_kde_density(df=<120r>, bandwidth=0.01)
#>
#> Geocoded incidents 95
#> Dropped (no / out-of-Toronto location) 25
#> Bandwidth 0.01
#> Max density (at obs) 545.38
#> Mean density 228.65
#> Median density 210.47
#> Lat at max-density obs 43.585
#> Lon at max-density obs -79.349
#> Backend morie_kde2d
#>
#> Across 95 geocoded incident(s), peak kernel density is 545.3835 (mean 228.6471, median 210.4698; backend: morie_kde2d). The densest cluster centre is at (lat=43.5854, lon=-79.3493). Smaller bandwidth exposes finer local clusters; larger bandwidth oversmooths.
