Learn R Programming

trafficCAR (version 0.1.0)

fit_traffic: Fit a Gaussian CAR traffic model (speed or travel time)

Description

This is a thin wrapper around fit_car() that: 1) preprocesses the outcome (log/per-distance options), 2) fits the Gaussian CAR model, 3) returns a traffic-flavored object that can be augmented back onto roads.

Usage

fit_traffic(
  data,
  roads = NULL,
  A = NULL,
  segment_id_col = "segment_id",
  outcome = c("speed", "travel_time"),
  outcome_col = NULL,
  distance_col = NULL,
  per_distance = FALSE,
  transform = c("log", "identity"),
  X = NULL,
  ...
)

Value

An object of class `traffic_fit` containing the underlying fit and transform metadata.

Arguments

data

data.frame with at least `segment_id` and the outcome column.

roads

optional; an sf object or similar that contains adjacency info already used by your `fit_car()` pipeline (depends on your package design).

A

adjacency matrix or object accepted by `fit_car()` (recommended explicit).

segment_id_col

character; column in `data` used to join back to roads.

outcome

character; one of "speed" or "travel_time".

outcome_col

optional character; if NULL uses `outcome`.

distance_col

optional character; used only for travel_time when per_distance=TRUE.

per_distance

logical; only for travel_time.

transform

character; "log" or "identity".

X

optional design matrix; if NULL, uses intercept-only.

...

passed to `fit_car()` (e.g., type="proper"/"icar", rho, priors, n_iter, burn, etc.)