
MetricGraph: A Statistical Framework for Modeling Gaussian Fields on Metric Graphs
Overview
MetricGraph (https://davidbolin.github.io/MetricGraph/), is an R package developed to enable advanced statistical modeling on metric graphs, which are geometric networks such as road systems, river basins, or neural pathways. It offers a rigorous yet computationally efficient framework for analyzing data constrained to these networks, supporting the construction of random fields and stochastic partial differential equations (SPDEs) directly on graph domains.
At the core of the package lies the metric_graph class, which provides tools for building and manipulating network representations, associating observational data with vertices and locations on edges, and performing spatial statistical modeling tailored to network-like non-Euclidean structures. A key feature of the package is the implementation of Gaussian random fields, in particular the Whittle–Matérn fields which are defined as solutions to fractional-order SPDEs, on graphs. These fields are well-defined for any compact metric graph and can possess differentiable sample paths, addressing limitations of covariance-based approaches in network settings.
The theoretical foundations of MetricGraph are drawn from a series of recent research papers. The formulation of Gaussian Whittle–Matérn fields on metric graphs was introduced by Bolin, Simas, and Wallin (2024, Bernoulli) ( https://projecteuclid.org/journals/bernoulli/volume-30/issue-2/Gaussian-WhittleMat%c3%a9rn-fields-on-metric-graphs/10.3150/23-BEJ1647.full), who established existence, uniqueness, and regularity of the processes as solutions to fractional SPDEs under appropriate boundary conditions. This work was extended by Bolin, Kovács, Kumar, and Simas (2024, Mathematics of Computation) (https://www.ams.org/journals/mcom/2024-93-349/S0025-5718-2023-03929-1/), who developed a numerical framework for solving fractional elliptic equations on graphs, including convergence guarantees and efficient discretization strategies based on rational approximations and finite element methods.
A particularly important contribution concerns the characterization of Markov properties for these Gaussian fields. In a separate work, Bolin, Simas, and Wallin (2025, Bernoulli, in press.) (https://arxiv.org/abs/2304.03190) rigorously demonstrated that the generalized Whittle–Matérn field is Markov if and only if the fractional exponent of the governing SPDE is an integer. This result establishes a direct and explicit connection between the smoothness of the field and its conditional independence structure, which is crucial for achieving exact and scalable inference. For integer exponents, the resulting fields possess sparse precision matrices, allowing likelihood evaluation and spatial prediction to be carried out exactly and efficiently, even on large and complex graphs.
These developments are fully integrated into the MetricGraph package. Users can construct networks from spatial data, such as OpenStreetMap, incorporate sensor or observational measurements, and fit spatial random field models directly on the graph. The package provides efficient implementations of maximum likelihood estimation, prediction, and simulation for Whittle–Matérn fields. In the Markovian case, it exploits the naturally sparse precision structure, while in the non-Markovian case, sparsity is achieved through finite element discretizations and rational approximations. For full Bayesian inference, MetricGraph interfaces with R-INLA (https://www.r-inla.org/) and inlabru (https://sites.google.com/inlabru.org/inlabru), enabling users to specify latent Gaussian models with graph-based random fields and perform posterior inference using INLA’s fast approximation methods. The package also supports extensions to spatio-temporal modeling, point processes on networks, and linear mixed models with network-constrained random effects.
While MetricGraph is a research-driven software, its design and capabilities are clearly aligned with applied needs. Through examples such as modeling traffic intensity on Madrid’s road network using real sensor data and OpenStreetMap-derived graphs, the package demonstrates readiness for applications in urban analytics, environmental monitoring, and infrastructure modeling. Its ability to combine theoretical rigor with scalable computation positions it as a valuable tool for future applied work in transportation science, epidemiology, and neuroscience.
To support learning and dissemination, the developers of MetricGraph created a Short Course on MetricGraph (https://github.com/davidbolin/MetricGraphCourse2025), initially presented at the INLA: Past, Present, and Future (https://inla-workshop.github.io/INLA-PastPresentFuture/) workshop at the University of Glasgow (https://www.gla.ac.uk/). This open-access course provides a step-by-step introduction to modeling and inference with MetricGraph, including real-world datasets, detailed R code, and reproducible case studies. The materials, including lecture slides, scripts, and data, are freely available online and designed to equip researchers with the tools needed to apply modern spatial statistics to network-constrained data.
MetricGraph is available on CRAN (https://cloud.r-project.org/web/packages/MetricGraph/index.html) via install.packages("MetricGraph") and on GitHub (https://github.com/davidbolin/MetricGraph) for access to the latest development versions. A detailed overview of the package, along with short course materials and illustrative examples, is available in the news article published by the Stochastic Processes and Applied Statistics group (https://stochproc.kaust.edu.sa/articles/2025/05/24/mastering-network-spatial-statistics-metricgraph-r-package).
By bridging deep theoretical developments with practical software tools, MetricGraph opens new possibilities for rigorous, efficient, and reproducible statistical modeling on complex networks. Its integration of SPDE-based methods, sparse matrix computation, and Bayesian inference establishes it as a state-of-the-art framework for spatial statistics on metric graphs.