multilevel¶
Multilevel variance decomposition using mixed-effects models.
multilevel
¶
Multilevel variance decomposition of traffic speed.
Fits nested mixed-effects models (null → temporal → full) using absolute speed (km/h) to partition within-segment (temporal) and between-segment (spatial) variance contributions. Produces ICC, temporal R², spatial ΔR², and summary tables / figures.
load_speed_panel
¶
Build a long-format panel (segment × period) with speed metrics.
Returns a dict mapping city codes to DataFrames with columns:
segment_id, period, speed_mean, free_flow_mean,
jam_factor_mean, speed_reduction.
Source code in src/trafficpipeline/multilevel.py
fit_multilevel_models
¶
Fit null → temporal → full mixed-effects models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
panel
|
DataFrame
|
Long-format panel with |
required |
Returns:
| Type | Description |
|---|---|
dict with keys: n_segments, icc, temporal_r2, spatial_delta_r2,
|
|
(beta_centrality, beta_centrality_p, null_var_segment, null_var_resid)
|
|
temporal_var_resid, full_var_segment.
|
|
Source code in src/trafficpipeline/multilevel.py
plot_variance_decomposition
¶
Grouped bar chart of ICC, temporal R², and spatial ΔR².
Source code in src/trafficpipeline/multilevel.py
run_analysis
¶
Run multilevel variance decomposition for all cities.