Crandore Hub

sfclust

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. (2024) <doi:10.48550/arXiv.2407.12633>, extending the approach of Zhang, B., Sang, H., Luo, Z. T., and Huang, H. (2023) <doi:10.1214/22-AOAS1643>. The package includes tools for model fitting, convergence diagnostics, visualization, and summarization of clustering results.

README

<!-- badges: start -->
  [![R-CMD-check](https://github.com/ErickChacon/sfclust/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ErickChacon/sfclust/actions/workflows/R-CMD-check.yaml)
 <!-- badges: end -->

# 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"*, available at
[arXiv:2407.12633](https://arxiv.org/abs/2407.12633). In addition to the core
clustering algorithm, `sfclust` offers tools for model diagnostics, visualization,
and result summarization.

## Installation

`sfclust` relies on the [`INLA`](https://www.r-inla.org/download-install) package for
efficient Bayesian inference. Install it with:

```r
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 the development version of `sfclust` from
GitHub:

```r
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:

```r
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](https://doi.org/10.1214/22-AOAS1643), *Annals of Applied
Statistics*, 2023), for making their supplementary code publicly available
([DOI:10.1214/22-AOAS1643SUPPB](https://doi.org/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.

Versions across snapshots

VersionRepositoryFileSize
1.0.1 rolling linux/jammy R-4.5 sfclust_1.0.1.tar.gz 3.5 MiB
1.0.1 rolling linux/noble R-4.5 sfclust_1.0.1.tar.gz 3.5 MiB
1.0.1 rolling source/ R- sfclust_1.0.1.tar.gz 3.5 MiB
1.0.1 latest linux/jammy R-4.5 sfclust_1.0.1.tar.gz 3.5 MiB
1.0.1 latest linux/noble R-4.5 sfclust_1.0.1.tar.gz 3.5 MiB
1.0.1 latest source/ R- sfclust_1.0.1.tar.gz 3.5 MiB
1.0.1 2026-04-26 source/ R- sfclust_1.0.1.tar.gz 3.5 MiB
1.0.1 2026-04-23 source/ R- sfclust_1.0.1.tar.gz 3.5 MiB
1.0.1 2026-04-09 windows/windows R-4.5 sfclust_1.0.1.zip 3.6 MiB

Dependencies (latest)

Imports

Suggests