View source: R/clustering_partition.R
clustering_partition | R Documentation |
The function takes an object of class SpatialPolygonsDataFrame
or sf
and defines a spatial partition using the DBSC algorithm described in \insertCitesantafe2021;textualbigDM.
clustering_partition(
carto,
ID.area = NULL,
var = NULL,
n.cluster = 10,
min.size = NULL,
W = NULL,
l = 1,
Wk = NULL,
distance = "euclidean",
verbose = TRUE
)
carto |
object of class |
ID.area |
character; name of the variable that contains the IDs of spatial areal units. |
var |
character; name of the variable that contains the data of interest to compute spatial clusters, usually the vector of log-SMR. |
n.cluster |
numeric; value to fix the number of cluster centers in the DBSC algorithm. Default to 10. |
min.size |
numeric (default |
W |
optional argument with the binary adjacency matrix of the spatial areal units. If |
l |
numeric value with the neighbourhood order used to assign areas to each cluster. If |
Wk |
previously computed binary adjacency matrix of l-order neighbours. If this argument is included (default |
distance |
the distance measure to be used (default |
verbose |
logical value (default |
The DBSC algorithm implemented in this function is a new spatial clustering algorithm based on the density clustering algorithm introduced by \insertCiterodriguez2014clustering;textualbigDM and the posterior modification presented by \insertCitewang2016automatic;textualbigDM. This algorithm is able to obtain a single clustering partition of the data by automatically detecting clustering centers and assigning each area to its nearest cluster centroid. The algorithm has its basis in the assumption that cluster centers are points with high local density and relatively large distance to other points with higher local densities. See \insertCitesantafe2021;textualbigDM for more details.
sf
object with the original data and a grouping variable named 'ID.group'.
rodriguez2014clusteringbigDM
\insertRefsantafe2021bigDM
\insertRefwang2016automaticbigDM
## Not run:
library(sf)
library(tmap)
## Load the Spain colorectal cancer mortality data ##
data(Carto_SpainMUN)
## Define a spatial partition using the DBSC algorithm ##
Carto_SpainMUN$logSMR <- log(Carto_SpainMUN$obs/Carto_SpainMUN$exp+0.0001)
carto.new <- clustering_partition(carto=Carto_SpainMUN, ID.area="ID", var="logSMR",
n.cluster=20, l=2, min.size=100, verbose=TRUE)
table(carto.new$ID.group)
## Plot of the grouping variable 'ID.group' ##
carto.data <- st_set_geometry(carto.new, NULL)
carto.partition <- aggregate(carto.new[,"geometry"], list(ID.group=carto.data[,"ID.group"]), head)
tmap4 <- packageVersion("tmap") >= "3.99"
if(tmap4){
tm_shape(carto.new) +
tm_polygons(fill="ID.group", fill.scale=tm_scale(values="brewer.set3")) +
tm_shape(carto.partition) +
tm_borders(col="black", lwd=2) +
tm_layout(legend.outside=TRUE, legend.frame=FALSE)
}else{
tm_shape(carto.new) +
tm_polygons(col="ID.group") +
tm_shape(carto.partition) +
tm_borders(col="black", lwd=2) +
tm_layout(legend.outside=TRUE)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.