markov¶
LISA Markov and Spatial Markov transition analysis.
markov
¶
LISA Markov and Spatial Markov analysis of congestion dynamics.
Computes LISA categories per segment per time period using PySAL (esda), then fits classic Markov and Spatial Markov transition models via giddy to quantify hotspot persistence and spatial contagion.
compute_lisa
¶
Compute Local Moran's I and assign LISA categories.
Requires libpysal and esda (install with
pip install traffic-congestion-pipeline[pysal]).
Returns gdf with added columns: lisa_i, lisa_p,
lisa_q, lisa_cat.
Source code in src/trafficpipeline/markov.py
compute_global_moran
¶
Compute Global Moran's I.
Returns dict with morans_i, z_score, p_value.
Source code in src/trafficpipeline/markov.py
build_lisa_matrix
¶
Build (n_segments × n_periods) integer matrix of LISA codes.
Aligns segments across periods by stable identifier so that Markov transitions are computed on the same physical segments throughout. Segments missing in any period are dropped.
Returns (y, gdfs) where y[i, t] ∈ {0..4} encodes LISA_STATES and
each gdf is the aligned (filtered + sorted) view for that period.
Source code in src/trafficpipeline/markov.py
classic_markov
¶
Fit a classic (non-spatial) Markov chain.
Returns dict with transition_matrix, steady_state,
and persistence (diagonal probabilities).
Source code in src/trafficpipeline/markov.py
spatial_markov
¶
Fit a Spatial Markov model conditioned on neighbor states.
Reports the maximally-significant homogeneity test across lag classes: we return the maximum chi-squared statistic and its associated p-value, dof, and significance flag at the 0.05 level.
Returns dict with chi2, p_value, dof, significant,
and per_lag (list of (chi2, p, dof) tuples per lag class).
Source code in src/trafficpipeline/markov.py
persistence_statistics
¶
Compute segment-level persistence metrics.
Returns dict mapping LISA states to {ever_pct, always_pct, avg_periods}.
Source code in src/trafficpipeline/markov.py
plot_transition_matrix
¶
Heatmap of transition probability matrix.
Source code in src/trafficpipeline/markov.py
plot_persistence_comparison
¶
Bar chart comparing persistence (diagonal) across cities.
Source code in src/trafficpipeline/markov.py
plot_contagion_results
¶
Bar chart of spatial contagion chi² with significance markers.
Source code in src/trafficpipeline/markov.py
run_analysis
¶
Run LISA Markov and Spatial Markov analysis for all cities.
Source code in src/trafficpipeline/markov.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |