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"
)Arguments
- df
Incident-level data.frame.
- bandwidth
Bandwidth multiplier passed to the 2-D KDE; see
MASS::kde2d'shargument when MASS is available. In the base-R fallback this is the Gaussian sigma (in degrees).- ds_name
Tag for the result title.
- lat_col, lon_col
WGS84 column names.
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 120
#> Bandwidth 0.01
#> Max density (at obs) 537.06
#> Mean density 139.44
#> Median density 129.81
#> Lat at max-density obs 43.563
#> Lon at max-density obs -79.427
#> Backend MASS::kde2d
#>
#> Across 120 geocoded incident(s), peak kernel density is 537.0641 (mean 139.4419, median 129.8126; backend: MASS::kde2d). The densest cluster centre is at (lat=43.5632, lon=-79.4272). Smaller bandwidth exposes finer local clusters; larger bandwidth oversmooths.