trafficCAR

License: MIT Lifecycle: experimental Development status R >= 3.5

Overview

trafficCAR is an R package for constructing conditional autoregressive (CAR) precision matrices on graph and road network data. It is built for users seeking principled spatial dependence structures for linear networks (streets, paths, and segmented roadways) and end-to-end utilities for turning raw road geometries into model-ready adjacency/weight matrices.

The package is designed to support methodological, simulation-based, and applied modeling workflows with intrinsic and proper CAR models defined on network structures. It includes helpers for turning LINESTRING/MULTILINESTRING features into stable segments, for building graph objects and sparse matrices, and for scaling or constraining CAR precision matrices to align with common spatial statistics conventions.

Core functionality includes:

In addition, trafficCAR provides convenient wrappers and plotting utilities aimed at traffic and speed modeling, so you can fit CAR/ICAR models and immediately map latent effects back to a road network.

What the package offers

Typical workflow

  1. Prepare road geometries: Clean and optionally simplify input road data. Convert LINESTRING/MULTILINESTRING features into stable, length-aware segments with roads_to_segments().

  2. Build network structure: Use build_adjacency() or build_network() to produce adjacency/graph objects that encode which road segments touch or intersect.

  3. Create weights/precision matrices: Convert adjacency into binary or row-standardized weights (weights_from_adjacency()), then build ICAR or proper CAR precision matrices with car_precision() or intrinsic_car_precision().

  4. Fit models or simulate: Fit Gaussian CAR/ICAR regression models with fit_car() or fit_traffic(), or run simulations with sample_proper_car() and rmvnorm_prec() for benchmarking and model checking.

  5. Augment and visualize: Attach fitted spatial effects back to the road geometries (augment_fit() or augment_traffic_fit()) and visualize results via static or interactive plotting helpers.

Data expectations

Installation

You can install the released version of trafficCAR from CRAN:

install.packages("trafficCAR")

To install the development version from GitHub:

# install.packages("devtools")
devtools::install_github("mell00/trafficCAR")