Package: MetricGraph 1.7.0.9000

MetricGraph: Random Fields on Metric Graphs

Facilitates creation and manipulation of metric graphs, such as street or river networks. Further facilitates operations and visualizations of data on metric graphs, and the creation of a large class of random fields and stochastic partial differential equations on such spaces. These random fields can be used for simulation, prediction and inference. In particular, linear mixed effects models including random field components can be fitted to data based on computationally efficient sparse matrix representations. Interfaces to the R packages 'INLA' and 'inlabru' are also provided, which facilitate working with Bayesian statistical models on metric graphs. The main references for the methods are Bolin, Simas and Wallin (2024) <doi:10.3150/23-BEJ1647>, Bolin, Kovacs, Kumar and Simas (2023) <doi:10.1090/mcom/3929> and Bolin, Simas and Wallin (2023) <doi:10.48550/arXiv.2304.03190> and <doi:10.48550/arXiv.2304.10372>.

Authors:David Bolin [cre, aut], Alexandre Simas [aut], Jonas Wallin [aut]

MetricGraph_1.7.0.9000.tar.gz
MetricGraph_1.7.0.9000.zip(r-4.7-x86_64)MetricGraph_1.7.0.9000.zip(r-4.7-arm64)MetricGraph_1.7.0.9000.zip(r-4.6-x86_64)MetricGraph_1.7.0.9000.zip(r-4.6-arm64)MetricGraph_1.7.0.9000.zip(r-4.5-x86_64)
MetricGraph_1.7.0.9000.tgz(r-4.6-x86_64)MetricGraph_1.7.0.9000.tgz(r-4.6-arm64)MetricGraph_1.7.0.9000.tgz(r-4.5-x86_64)MetricGraph_1.7.0.9000.tgz(r-4.5-arm64)
MetricGraph_1.7.0.9000.tar.gz(r-4.7-arm64)MetricGraph_1.7.0.9000.tar.gz(r-4.7-x86_64)MetricGraph_1.7.0.9000.tar.gz(r-4.6-arm64)MetricGraph_1.7.0.9000.tar.gz(r-4.6-x86_64)
MetricGraph_1.7.0.9000.tgz(r-4.6-emscripten)
manual.pdf |manual.html✨
DESCRIPTION |NEWS
card.svg |card.png
MetricGraph/json (API)

# Install 'MetricGraph' in R:
install.packages('MetricGraph', repos = c('https://davidbolin.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/davidbolin/metricgraph/issues

Pkgdown/docs site:https://davidbolin.github.io

Uses libs:
  • c++– GNU Standard C++ Library v3
Datasets:
  • columbia_main_component - Largest connected component of the Mid-Columbia stream network
  • pems - Traffic speed data from San Jose, California
  • pems_repl - Traffic speed data with replicates from San Jose, California

On CRAN:

Conda:

cpp

8.17 score 24 stars 668 downloads 49 exports 63 dependencies

Last updated from:429bed3fe5. Checks:13 OK, 2 ERROR. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-arm64OK805
linux-devel-x86_64OK1378
source / vignettesOK3115
linux-release-arm64OK779
linux-release-x86_64OK1243
macos-release-arm64OK1294
macos-release-x86_64OK1663
macos-oldrel-arm64OK861
macos-oldrel-x86_64OK1323
windows-devel-arm64ERROR1009
windows-devel-x86_64OK2159
windows-release-arm64ERROR975
windows-release-x86_64OK1304
windows-oldrel-x86_64OK1094
wasm-releaseOK193

Exports:%>%augmentCholeskycross_validationdirectional_ou_covariancedirectional_ou_variancedrop_naexp_covariancefetch_osmfiltergg_dfglancegraph_bru_process_datagraph_componentsgraph_data_spdegraph_lgcp_simgraph_lmegraph_spdegraph_spde_basisgraph_spde_make_Agraph_starting_valueslgcp_graphlinnet.to.graphlogo_linesmake_Q_eulermake_Q_spacetimematch_mesh_datametric_graphmetric_graph_from_osmmutateposterior_crossvalidationposterior_crossvalidation_looprecompute_lgcp_graphprocess_rspde_predictionspsp.to.graphsample_spdeselectselected_invsimulate_parallelsimulate_spacetimespde_covariancespde_metric_graph_resultspde_precisionspde_variancestlpp.to.graphsummarisetupdate_graphweighted_stiffness

Dependencies:backportsbroomclassclassIntclicodetoolscpp11DBIdeldirdoParalleldplyre1071farverfmesherforeachgenericsggnewscaleggplot2gluegtableigraphisobanditeratorsKernSmoothlabelinglatticelifecyclemagrittrMatrixpillarpkgconfigpolyclipproxypurrrR6RANNRColorBrewerRcppRcppEigenrlangrSPDEs2S7scalessfspspatstat.dataspatstat.geomspatstat.univarspatstat.utilssplancsstringistringrtibbletidyrtidyselectunitsutf8vctrsviridisLitewithrwkzoo

Whittle--Matérn fields with general smoothness
Introduction | Constructing the graph and the mesh | Using the model for inference | Kriging | Further details on graph_lme | Fixing parameters | Setting starting values | Example: Fixing and setting starting values | Fitting a model with replicates | Using the R-INLA implementation | Kriging with the R-INLA implementation | Using R-INLA implementation to fit models with replicates | Using inlabru implementation | Kriging with the inlabru implementation | Using inlabru to fit models with replicates | An example with a non-stationary model | Creating the graph and adding data | Fitting the model with graph_lme | Fixing parameters in non-stationary models | Fitting the inlabru rSPDE model | References

Last update: 2026-11-10
Started: 2022-11-23

An example with multiple likelihoods in INLA and inlabru
Introduction | A toy dataset | Fitting models with multiple likelihoods in R-INLA | Fitting models with multiple likelihoods in inlabru | A toy dataset with multiple likelihoods and replicates | Fitting the model with multiple likelihoods and replicates in R-INLA | Fitting models with multiple likelihoods and replicates in inlabru

Last update: 2026-11-09
Started: 2024-12-13

INLA interface for Whittle--Matérn fields on metric graphs
Introduction | A toy dataset | R-INLA implementation | Kriging with our INLA implementation | An example with alpha = 2 | Fitting R-INLA models with replicates

Last update: 2026-11-09
Started: 2022-11-23

inlabru interface of Whittle--Matérn fields
Introduction | A toy dataset | inlabru implementation | Kriging with the inlabru implementation | An example with alpha = 2 | Fitting inlabru models with replicates | An application with real data

Last update: 2026-11-09
Started: 2022-11-23

Log-Gaussian Cox processes on metric graphs
Introduction | Constructing the graph and the mesh | Fitting LGCP models with our INLA interface | An example with replicates in our INLA interface | Fitting LGCP models without our INLA interface | An example with replicates | Using precomputed data for efficient model fitting | Example without replicates | Using manual covariates with precomputation | Performance optimization: avoiding graph cloning | Example with replicates | Using manual covariates with replicates

Last update: 2026-11-09
Started: 2023-01-30

MetricGraph: Random Fields on Metric Graphs
Introduction | The metric_graph class | Basic constructions | Understanding coordinates on graphs | Adding data to the graph | Working with functions on metric graphs | Random fields on metric graphs | Whittle--Matérn fields | Sampling | Inference | Isotropic Gaussian fields | Models based on the Graph Laplacian | The inlabru interface | Basic setup and estimation | Kriging with the inlabru implementation | References

Last update: 2026-11-09
Started: 2022-11-26

Spatio-temporal Models on Compact Metric Graphs
Introduction | Implementation Details | Simulating Observations and Estimating Parameters | inlabru Implementation | Fitting Model with Replicates in inlabru | Example: Setting bounded_rho = FALSE | Using rspde_lme() | Comparing Results | Using inlabru | Fitting the Model with inlabru | INLA Implementation (Added for Completeness) | Fitting the Model with INLA | Fitting Model with Replicates in INLA | References

Last update: 2026-11-09
Started: 2024-12-13

Comparison of different models using real data
Introduction | The dataset | The models | Comparison by cross-validation | Kriging | A quick diagnostic analysis | References

Last update: 2026-11-09
Started: 2024-02-26

An example with directional models
Introduction | Symmetric vs directional | Special boundary condition

Last update: 2026-11-08
Started: 2024-12-13

Gaussian random fields on metric graphs
Introduction | Whittle--Matérn fields | Sampling | Inference | Isotropic Gaussian processes | Models based on the Graph Laplacian | A comparison using cross-validation | A model with replicates | A model with covariates | A model with covariates and replicates | References

Last update: 2026-11-08
Started: 2022-11-23

Profile likelihood and REML for Whittle--Matérn fields
Introduction | River graph | Parameterization helpers | Simulation setup | Profile likelihood — $n = 200$, $p = 5$ | Verifying the core identity | Optimization and parameter recovery | Profile likelihood — $n = 200$, $p = 10$ | Profile likelihood — $n = 400$, $p = 5$ and $p = 10$ | Summary across scenarios | Comparison with graph_lme ($n = 400$, $p = 5$) | REML ($n = 400$, $p = 10$) | References

Last update: 2026-11-08
Started: 2026-07-13

Working with metric graphs
Introduction | Constructing metric graphs | Basic constructions and properties | Tolerances for merging vertices and edges | Edge lengths | Characteristics of the graph | Summaries of metric graphs | Vertices and edges | Understanding coordinates on graphs | Methods for working with real data | Adding data to the graph | Working with functions on metric graphs | Further details on plot_function | Note about continuity

Last update: 2026-11-08
Started: 2022-11-23

Working with disconnected metric graphs
Introduction | Constructing a disconnected metric graph | Inspecting the components | Determining the component of a spatial point | Plotting | Adding observations | Distances on disconnected graphs | SPDE models | Plotting functions on the components

Last update: 2026-04-27
Started: 2026-04-26

An example with a river graph model
Introduction | Setting up the data | Non directional models | Directional models

Last update: 2025-05-19
Started: 2024-12-13

Solving PDEs on metric graphs
Introduction | Constructing the graph and the mesh | Example with the Helmoltz equation | Example with a Poisson equation | A problem with a random diffusion coefficient | Solving a fractional-order PDE using rSPDE | References

Last update: 2025-05-19
Started: 2025-05-19

Data manipulation on metric graphs
Introduction | Adding and accessing data on metric graphs | Adding grouped data to metric graphs | More advanced grouping | Identifying data that is away from the metric graph | Merging observations when adding them | Manipulating data from metric graphs in the tidyverse style | select | filter | mutate | summarise | drop_na | Combining multiple verbs | Replacing the data in the metric graph by manipulated data | Edge Weights Manipulation in Metric Graphs | Adding Edge Weights to the Metric Graph | Selecting Specific Edge Weight Columns | Filtering Edge Weights | Creating New Columns Using mutate_weights() | Summarising Edge Weights | Removing Rows with NA Values | Combining Multiple Verbs

Last update: 2024-12-13
Started: 2023-11-06

On isotropic covariances on metric graphs with non-Euclidean edges
Introduction | A simple example

Last update: 2024-12-13
Started: 2024-02-26

Readme and manuals

Help Manual

Help pageTopics
Gaussian processes on metric graphsMetricGraph-package MetricGraph
Augment data with information from a 'graph_lme' objectaugment augment.graph_lme
Metric graph 'inlabru' mapperbru_get_mapper.inla_metric_graph_spde bru_mapper.inla_metric_graph_spde ibm_jacobian.bru_mapper_inla_metric_graph_spde ibm_n.bru_mapper_inla_metric_graph_spde ibm_values.bru_mapper_inla_metric_graph_spde
Largest connected component of the Mid-Columbia stream networkcolumbia_main_component
Perform cross-validation on a list of fitted inlabru models on metric graphs.cross_validation
Closed-form covariance of the directional OU modeldirectional_ou_covariance
Closed-form marginal variance of the directional OU modeldirectional_ou_variance
A version of 'tidyr::drop_na()' function for datasets on metric graphsdrop_na drop_na.metric_graph_data
Exponential covariance functionexp_covariance
Fetch OpenStreetMap data via the Overpass APIfetch_osm
A version of 'dplyr::filter()' function for datasets on metric graphsfilter filter.metric_graph_data
Data frame for metric_graph_spde_result objects to be used in 'ggplot2'gg_df gg_df.metric_graph_spde_result
Glance at a 'graph_lme' objectglance glance.graph_lme
Prepare data frames or data lists to be used with 'inlabru' in metric graphsgraph_bru_process_data
Data extraction for 'spde' modelsgraph_data_spde
Simulate log-Gaussian Cox processes on metric graphsgraph_lgcp_sim
Metric graph linear mixed effects modelsgraph_lme
'INLA' implementation of Whittle-Matérn fields for metric graphsgraph_spde
Deprecated - Observation/prediction matrices for 'SPDE' modelsgraph_spde_basis
Deprecated - Observation/prediction matrices for 'SPDE' modelsgraph_spde_make_A
Starting values for random field models on metric graphsgraph_starting_values
Fit log-Gaussian Cox process models on metric graphslgcp_graph
Convert a 'linnet' object to a metric graph objectlinnet.to.graph
Create lines for package namelogo_lines
Space-time precision operator Euler discretizationmake_Q_euler
Space-time precision operator discretizationmake_Q_spacetime
Match Data Frame Rows to Graph Mesh Ordermatch_mesh_data
Metric graphmetric_graph
Build a metric_graph directly from an OpenStreetMap querymetric_graph_from_osm
A version of 'dplyr::mutate()' function for datasets on metric graphsmutate mutate.metric_graph_data
Traffic speed data from San Jose, Californiapems
Traffic speed data with replicates from San Jose, Californiapems_repl
Plot of predicted values with 'inlabru'plot.graph_bru_pred
Plot of processed predicted values with 'inlabru'plot.graph_bru_proc_pred
Leave-one-out pseudo-crossvalidation for 'graph_lme' models assuming observations at the vertices of metric graphsposterior_crossvalidation_loo
Cross-validation for 'graph_lme' models assuming observations at the vertices of metric graphsposterior_crossvalidation posterior_crossvalidation.graph_lme
Precompute expensive quantities for efficient LGCP model fittingprecompute_lgcp_graph
Prediction for a mixed effects regression model on a metric graphpredict.graph_lme
Predict method for 'inlabru' fits on Metric Graphspredict.inla_metric_graph_spde
Predict method for 'inlabru' fits on Metric Graphs for 'rSPDE' modelspredict.rspde_metric_graph
Process predictions of 'rspde_metric_graph' objects obtained by using 'inlabru'process_rspde_predictions
Convert a 'psp' object to a metric graph objectpsp.to.graph
Samples a Whittle-Matérn field on a metric graphsample_spde
A version of 'dplyr::select()' function for datasets on metric graphsselect select.metric_graph_data
Selected Inverse Calculationselected_inv
Parallel simulation of a Whittle-Matérn field on a metric graphsimulate_parallel
space-time simulation based on implicit Euler discretization in timesimulate_spacetime
Simulation of models on metric graphssimulate.graph_lme
Simulate a Whittle-Matérn field on a metric graphsimulate.metric_graph
Covariance function for Whittle-Matérn fieldsspde_covariance
Metric graph SPDE result extraction from 'INLA' estimation resultsspde_metric_graph_result
Precision matrix for Whittle-Matérn fieldsspde_precision
Variancefor Whittle-Matérn fieldsspde_variance
Convert an 'stlpp' object to a metric graph objectstlpp.to.graph
A version of 'dplyr::summarise()' function for datasets on metric graphssummarise summarise.metric_graph_data
Summary Method for 'graph_lme' Objectssummary.graph_lme
Summary Method for 'metric_graph' Objectssummary.metric_graph
Summary for posteriors of field parameters for an 'inla_rspde' model from a 'rspde.result' objectsummary.metric_graph_spde_result
Update an older version metric graph to the current package versionupdate_graph
Assemble a weighted stiffness matrix on a graph meshweighted_stiffness