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.
Returns (y, gdfs) where y[i, t] ∈ {0..4} encodes LISA_STATES.
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.
Returns dict with chi2, p_value, dof,
significant (bool).
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
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |