hotspot_dbscan: Identify hotspots using DBSCAN

View source: R/hotspot_dbscan.R

hotspot_dbscanR Documentation

Identify hotspots using DBSCAN

Description

Identify clusters of points using density-based spatial clustering and represent each cluster as a buffered convex or concave hull. Clusters are ranked by the number of points they contain.

Usage

hotspot_dbscan(
  data,
  eps = NULL,
  min_pts = NULL,
  density_adjust = 2,
  hull = c("concave", "convex"),
  hull_ratio = 0.75,
  transform = TRUE,
  quiet = FALSE,
  ...
)

Arguments

data

An sf::sf object containing point geometries.

eps

A single positive number specifying the DBSCAN neighbourhood radius in the units of the analysis co-ordinate reference system (CRS). If NULL, the radius is calculated automatically from nearest-neighbour distances. See Automatic parameter selection.

min_pts

A single integer specifying the minimum number of points in an eps neighbourhood, including the point itself, for a point to be a core point. If NULL, the value is calculated automatically from the number of point coordinates in data. See Automatic parameter selection.

density_adjust

A single positive number controlling automatic selection of eps. Ignored unless eps = NULL. A value of 1 (the reference neighbourhood density) uses the median nearest-neighbour distance; the default of 2 requires approximately twice that density.

hull

The type of hull used to represent each cluster: "convex" or "concave" (the default).

hull_ratio

For concave hulls, a number from zero to one specifying the fraction convex. Zero produces a maximally concave hull and one produces a convex hull. The default is 0.75. Ignored when hull = "convex".

transform

DBSCAN uses Euclidean distances and therefore requires a projected CRS. If TRUE (the default), geographic input is transformed automatically with st_transform_auto() before analysis and the result is transformed back afterwards. If FALSE, geographic input produces an error.

quiet

If TRUE, suppress informative messages about automatically selected parameters and geometry preparation.

...

Further arguments passed to dbscan::dbscan(), such as borderPoints and nearest-neighbour search controls. The arguments x, eps, minPts, and weights cannot be supplied through ....

Details

MULTIPOINT geometries are cast to individual points before analysis. The output n column counts all input point coordinates intersecting each final cluster polygon, not only points assigned to that DBSCAN cluster. DBSCAN includes border points in clusters by default; supplying borderPoints = FALSE through ... instead performs DBSCAN* and excludes border points from the points used to construct the hull.

Each cluster geometry is the selected hull of all assigned points, buffered by eps and clipped to the convex hull of all input points. Different cluster polygons may overlap after hull construction and buffering.

Value

An sf tibble with class hspt_s and one row per non-noise cluster. It contains cluster, the original DBSCAN cluster identifier; rank, the priority rank; n, the number of input point coordinates intersecting the polygon; prop, n as a proportion of all input point coordinates; prop_area, the polygon area as a proportion of the area covered by a hull of the complete dataset; and geometry. The complete-dataset hull uses the same hull, hull_ratio, buffering and clipping rules as the cluster hulls. Since cluster polygons may overlap, the sums of prop and prop_area can exceed one. Ranking is by decreasing n, then increasing polygon area, then increasing cluster identifier.

Automatic parameter selection

When min_pts = NULL, it is calculated as

min(n, 50, max(5, ceiling(sqrt(n)))),

where n is the number of point coordinates after empty geometries have been removed and MULTIPOINT geometries have been expanded. For datasets with two to four coordinates, all coordinates are required. At least two coordinates are needed for automatic selection. This rule increases the evidence required to identify a hotspot in larger datasets, while the upper limit prevents the required number of neighbours becoming excessively large.

When eps = NULL, the function calculates the distance from every point to its (min_pts - 1)th nearest other point. The median of those distances is a typical local neighbourhood radius. The value used for clustering is

eps = median_neighbour_distance / sqrt(density_adjust).

min_pts - 1 other points are used because DBSCAN counts the focal point itself. Since circular area is proportional to the square of its radius, the default density_adjust = 2 searches for the required number of points in approximately half the typical neighbourhood area, corresponding to approximately twice the typical local point density. Larger values identify denser concentrations; values below one allow less-dense concentrations.

Automatic values provide a starting point for exploratory analysis. DBSCAN results can be sensitive to both parameters, so users should consider whether the resulting neighbourhood size and minimum density are meaningful for their application.

Examples


# The default concave hulls require GEOS 3.11 or later.
if (utils::compareVersion(sf::sf_extSoftVersion()[["GEOS"]], "3.11.0") >= 0) {
  hotspot_dbscan(memphis_robberies_jan)
}

hotspot_dbscan(
  memphis_robberies_jan,
  density_adjust = 3,
  hull = "convex"
)



sfhotspot documentation built on Oct. 1, 2026, 1:06 a.m.