I'm looking to see if I can cluster geographic regions by a variable, such as losses.

For example, I have 5 regions with the following amount of losses: Region 1 with \$500,000 in losses. Region 2 with \$400,000 in losses. Region 3 with \$200,000 in losses. Region 4 with \$200,000 in losses. Region 5 with \$300,000 in losses.

Ideally I'd like to cluster them based on similar losses (for example, clustering region 3 and 4 together since they share the same amount of total losses). However, I need to ensure that the regions are spatially adjacent to each other. So if region 3 is not right next to region 4, I would not allow them to be clustered together.

I have a shapefile of all the regions, which includes the centroid latitude and longitude of each region.

My idea for doing this is taking a distance matrix (derived by the latitude and longitude coordinates) and combining it with another distance matrix (derived from losses). Would this sort of approach work?If so, what would the R code look like for this sort of merge?

If not, what sort of approach would be recommended?

  • 1
    $\begingroup$ I'd think that you want a clustering based on losses, using spatial adjacency of clusters as a side condition (i.e., you look for the optimal loss clustering among only those clusterings that have adjacent regions together). This would not amount to "combining two distance matrices" but rather to constrained optimisation. Unfortunately I cannot tell you where such a constrained clustering is implemented, although I'd expect that somebody had this problem before and something exists somewhere (for example constrained k-means). $\endgroup$ Commented Feb 11, 2020 at 14:21
  • $\begingroup$ Appreciate the advice! With your help I managed to find a paper that may serve my purpose. @Lewian $\endgroup$
    – platypus17
    Commented Feb 12, 2020 at 5:12

1 Answer 1


The following article (link found here: https://arxiv.org/pdf/1707.03897.pdf) provides a way to cluster with spatial constraints. In particular, one could specify strict neighborhood boundaries for the clusters.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.