| Title: | Spatially Contiguous Clustering with the 'Redcap' Algorithm |
|---|---|
| Description: | Groups spatial data into clusters of similar observations, while requiring that each cluster forms a single spatially contiguous region. Contiguity is enforced by first building a spanning tree from the spatial relationships between points, and then cutting that tree into clusters according to a matrix of distances or other measures of similarity. Trees may be built from first-order relationships only (direct neighbours), yielding a minimum spanning tree, or from full-order relationships between entire clusters, using single linkage (nearest members), average linkage (mean of all pairs), or complete linkage (furthest members). The single and average linkage methods implement the 'Redcap' algorithm ('Regionalization' with dynamically constrained agglomerative clustering and partitioning). Results can be visualised as maps of clusters, cluster hulls, or trees. |
| Authors: | Mark Padgham [aut, cre] (ORCID: <https://orcid.org/0000-0003-2172-5265>), Michael Sumner [ctb] (ORCID: <https://orcid.org/0000-0002-2471-7511>) |
| Maintainer: | Mark Padgham <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.1.009 |
| Built: | 2026-11-10 11:44:51 UTC |
| Source: | https://github.com/UrbanAnalyst/spatialcluster |
Plot dendrogram of merges for scl object with method = "full".
plot_merges(x, root_tree = FALSE)plot_merges(x, root_tree = FALSE)
x |
Object of class |
root_tree |
If |
Nothing (generates plot)
Other plot_fns:
plot.scl()
n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_full (xy, dmat, ncl = 4) plot_merges (scl)n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_full (xy, dmat, ncl = 4) plot_merges (scl)
plot.scl
## S3 method for class 'scl' plot(x, ..., hull_alpha = 1)## S3 method for class 'scl' plot(x, ..., hull_alpha = 1)
x |
object to be plotted |
... |
ignored here |
hull_alpha |
alpha value of (non-)convex hulls, with default generating a convex hull, and smaller values generating concave hulls. (See ?alphashape::ashape for details). |
A ggplot2 object.
Other plot_fns:
plot_merges()
set.seed (1) n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_redcap (xy, dmat, ncl = 4) plot (scl) # Connect clusters according to highest (\code{shortest = FALSE}) values of # \code{dmat}: scl <- scl_redcap (xy, dmat, ncl = 4, shortest = FALSE, full_order = FALSE) plot (scl)set.seed (1) n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_redcap (xy, dmat, ncl = 4) plot (scl) # Connect clusters according to highest (\code{shortest = FALSE}) values of # \code{dmat}: scl <- scl_redcap (xy, dmat, ncl = 4, shortest = FALSE, full_order = FALSE) plot (scl)
Full spatially-constrained clustering.
scl_full( xy, dmat, ncl, linkage = "single", shortest = TRUE, nnbs = 6L, boundary = NULL )scl_full( xy, dmat, ncl, linkage = "single", shortest = TRUE, nnbs = 6L, boundary = NULL )
xy |
Rectangular structure (matrix, data.frame, tibble), containing coordinates of points to be clustered. |
dmat |
Structure (matrix, data.frame, tibble) containing distances or
equivalent metrics between all points in |
ncl |
Desired number of clusters. See description of 'ncl_iterate' parameter for conditions under which actual number may be less than this value. |
linkage |
One of |
shortest |
If |
nnbs |
Number of spatially nearest neighbours to be used in calculating
clustering trees, irrespective of |
boundary |
Optional boundary of the study region. If given, spatial
neighbours are taken from a constrained Delaunay triangulation of the points
within this boundary (requires the 'cdtr' package), so that no neighbour
edges cross outside it, for example across concavities in the region. May be
a two-column matrix or data frame of the vertices of a single ring, a list of
such rings (holes are recognised by nesting), or an 'sf' polygon or
multipolygon object. All points in |
A object of class scl with tree containing the
clustering scheme, and xy the original coordinate data of the
clustered points. An additional component, tree_rest, enables the tree
to be re-cut to a different number of clusters via scl_recluster.
Other clustering_fns:
scl_recluster(),
scl_redcap()
n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_full (xy, dmat, ncl = 4)n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_full (xy, dmat, ncl = 4)
Re-cut a spatial cluster tree (scl) at a different number of clusters.
scl_recluster(scl, ncl, shortest = TRUE, quiet = FALSE)scl_recluster(scl, ncl, shortest = TRUE, quiet = FALSE)
scl |
An |
ncl |
Desired number of clusters. See description of 'ncl_iterate' parameter for conditions under which actual number may be less than this value. |
shortest |
If |
quiet |
If 'FALSE' (default), display progress information on screen. |
Modified scl object in which tree is re-cut into
ncl clusters.
Other clustering_fns:
scl_full(),
scl_redcap()
n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_redcap (xy, dmat, ncl = 4) plot (scl) scl <- scl_recluster (scl, ncl = 5) plot (scl)n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_redcap (xy, dmat, ncl = 4) plot (scl) scl <- scl_recluster (scl, ncl = 5) plot (scl)
Cluster spatial data with REDCAP (REgionalization with Dynamically Constrained Agglomerative clustering and Partitioning) routines.
scl_redcap( xy, dmat, ncl, full_order = TRUE, linkage = "single", shortest = TRUE, nnbs = 6L, boundary = NULL, iterate_ncl = FALSE, quiet = FALSE )scl_redcap( xy, dmat, ncl, full_order = TRUE, linkage = "single", shortest = TRUE, nnbs = 6L, boundary = NULL, iterate_ncl = FALSE, quiet = FALSE )
xy |
Rectangular structure (matrix, data.frame, tibble), containing coordinates of points to be clustered. |
dmat |
Structure (matrix, data.frame, tibble) containing distances or
equivalent metrics between all points in |
ncl |
Desired number of clusters. See description of 'ncl_iterate' parameter for conditions under which actual number may be less than this value. |
full_order |
If |
linkage |
One of |
shortest |
If |
nnbs |
Number of spatially nearest neighbours to be used in calculating
clustering trees, irrespective of |
boundary |
Optional boundary of the study region. If given, spatial
neighbours are taken from a constrained Delaunay triangulation of the points
within this boundary (requires the 'cdtr' package), so that no neighbour
edges cross outside it, for example across concavities in the region. May be
a two-column matrix or data frame of the vertices of a single ring, a list of
such rings (holes are recognised by nesting), or an 'sf' polygon or
multipolygon object. All points in |
iterate_ncl |
Actual numbers of clusters found may be less than the specified value of 'ncl', because clusters formed from < 3 edges are removed. If 'iterate_ncl = FALSE' (the default), the value is returned with whatever number of actual clusters is found. Setting this parameter to 'TRUE' forces the algorithm to iterate until the exact number of clusters has been found. For large data sets, this may result in considerable longer calculation times. |
quiet |
If 'FALSE' (default), display progress information on screen. |
Clustering is in two stages. First, a spanning tree is constructed from the
**spatial** relationships between points in xy alone, using the
nearest spatial neighbours (see nnbs), and independent of both
dmat and shortest. Second, that tree is cut into ncl
clusters by evaluating the values of dmat along its edges.
A object of class scl with tree containing the
clustering scheme, and xy the original coordinate data of the
clustered points. An additional component, tree_rest, enables the tree
to be re-cut to a different number of clusters via scl_recluster,
rather than calculating clusters anew.
Please refer to the original REDCAP paper ('Regionalization with
dynamically constrained agglomerative clustering and partitioning (REDCAP)',
by D. Guo (2008), Int.J.Geo.Inf.Sci 22:801-823) for details of the
full_order and linkage parameters. Note that, unlike the
original, the spanning trees constructed here (for all values of
linkage) are based on spatial distances between points in xy,
with dmat used only when cutting the trees into clusters. This paper
clearly
demonstrates the general inferiority of spanning trees constructed from
first-order relationships. It is therefore strongly recommended that the
default full_order = TRUE be used at all times.
Other clustering_fns:
scl_full(),
scl_recluster()
n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_redcap (xy, dmat, ncl = 4) # By default, the spatial tree is cut to minimise within-cluster variation # of (\code{shortest}) values of \code{dmat}. Setting \code{shortest = FALSE} # instead cuts the same tree to maximise mean within-cluster values of # \code{dmat}, as for covariances, and will generally give different # clusters: scl <- scl_redcap (xy, dmat, ncl = 4, shortest = FALSE) # using 'full_order = FALSE' constructs clusters from first-order # relationships only; not recommended, but possible nevertheless: scl <- scl_redcap (xy, dmat, ncl = 4, full_order = FALSE)n <- 100 xy <- matrix (runif (2 * n), ncol = 2) dmat <- matrix (runif (n^2), ncol = n) scl <- scl_redcap (xy, dmat, ncl = 4) # By default, the spatial tree is cut to minimise within-cluster variation # of (\code{shortest}) values of \code{dmat}. Setting \code{shortest = FALSE} # instead cuts the same tree to maximise mean within-cluster values of # \code{dmat}, as for covariances, and will generally give different # clusters: scl <- scl_redcap (xy, dmat, ncl = 4, shortest = FALSE) # using 'full_order = FALSE' constructs clusters from first-order # relationships only; not recommended, but possible nevertheless: scl <- scl_redcap (xy, dmat, ncl = 4, full_order = FALSE)
Description: Groups spatial data into clusters of similar observations, while requiring that each cluster forms a single spatially contiguous region. Contiguity is enforced by first building a spanning tree from the spatial relationships between points, and then cutting that tree into clusters according to a matrix of distances or other measures of similarity. Trees may be built from first-order relationships only (direct neighbours), yielding a minimum spanning tree, or from full-order relationships between entire clusters, using single linkage (nearest members), average linkage (mean of all pairs), or complete linkage (furthest members). The single and average linkage methods implement the 'Redcap' algorithm ('Regionalization' with dynamically constrained agglomerative clustering and partitioning). Results can be visualised as maps of clusters, cluster hulls, or trees.
Maintainer: Mark Padgham [email protected] (ORCID)
Authors:
Mark Padgham [email protected] (ORCID)
Other contributors:
Michael Sumner (ORCID) [contributor]
Useful links:
Report bugs at https://github.com/UrbanAnalyst/spatialcluster/issues