Bayesian Spatial Functional Clustering

Bayesian clustering of spatial regions with similar functional shapes using spanning trees and latent Gaussian models. The method enforces spatial contiguity within clusters and supports a wide range of latent Gaussian models, including non-Gaussian likelihoods, via the R-INLA framework. The algorithm is based on Zhong, R., Chacón-Montalván, E. A., and Moraga, P. (2026) , extending the approach of Zhang, B., Sang, H., Luo, Z. T., and Huang, H. (2023) . The package includes tools for model fitting, convergence diagnostics, visualization, and summarization of clustering results.


CRAN status R-CMD-check pkgdown

sfclust: Bayesian Spatial Functional Clustering

Introduction

sfclust provides a Bayesian framework for clustering spatio-temporal data, supporting both Gaussian and non-Gaussian responses. The approach enforces spatial adjacency constraints, ensuring that clusters consist of neighboring regions with similar temporal dynamics.

The package implements the methodology described in "Bayesian Spatial Functional Data Clustering: Applications in Disease Surveillance" (2026), published in Statistics in Medicine at https://doi.org/10.1002/sim.70597. In addition to the core clustering algorithm, sfclust offers tools for model diagnostics, visualization, and result summarization.

Installation

sfclust relies on the INLA package for efficient Bayesian inference. Install it with:

install.packages("INLA", dependencies = TRUE,
  repos = c(getOption("repos"), INLA = "https://inla.r-inla-download.org/R/stable")
)

Once INLA is installed, you can install sfclust from CRAN with:

install.packages("sfclust")

Or you can install the development version from GitHub:

devtools::install_github("ErickChacon/sfclust")

Basic Usage

Suppose you have a spatio-temporal stars object named stars_object that contains variables such as cases and expected (the expected number of cases). The following code fits a spatial functional clustering model, where each cluster’s mean trend is modeled with a temporal random walk and an unstructured random effect:

form <- cases ~ f(idt, model = "rw1") + f(id, model = "iid")
result <- sfclust(stars_object, formula = form, family = "poisson", E = expected, niter = 1000)
result

Acknowledgments

We thank the authors of "Bayesian Clustering of Spatial Functional Data with Application to a Human Mobility Study During COVID-19", by Bohai Zhang, Huiyan Sang, Zhao Tang Luo, and Hui Huang (DOI:10.1214/22-AOAS1643, Annals of Applied Statistics, 2023), for making their supplementary code publicly available (DOI:10.1214/22-AOAS1643SUPPB). Our implementation builds upon their clustering algorithm and uses their code for generating spanning trees. We are grateful for their contributions and inspiration.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("sfclust")

1.1.1 by Erick A. Chacón-Montalván, 17 days ago


https://erickchacon.github.io/sfclust/, https://github.com/ErickChacon/sfclust


Report a bug at https://github.com/ErickChacon/sfclust/issues


Browse source code at https://github.com/cran/sfclust


Authors: Erick A. Chacón-Montalván [aut, cre] (ORCID: , Ruiman Zhong [aut] , Paula Moraga [aut]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports igraph, sf, SparseM, stars, dplyr, methods, Matrix, ggplot2, patchwork

Suggests ggraph, here, INLA, knitr, rmarkdown, testthat


See at CRAN