Sovereign 8s.is mirror of standardgalactic/spatial_sldr
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-08 14:20:14 +08:00
Code/spatial_sldr Update code, README, and figures 2026-09-04 23:54:55 +08:00
Data Update data and figures 2026-07-11 00:04:28 +08:00
Figure/spatial_sldr Add main figures 2026-09-08 14:20:14 +08:00
.gitignore Initial commit: add Code, Figure, and README 2025-09-19 21:06:54 +08:00
LICENSE Create LICENSE 2025-09-25 13:19:50 +08:00
README.md Update code, README, and figures 2026-09-04 23:54:55 +08:00
README.Rmd Update README wording 2026-07-28 03:12:47 +08:00

Software and code

All analyses were conducted in R version 4.5.1. The code used for data analysis was custom developed in R and is publicly available at https://github.com/weiyli/spatial_sldr. The following R packages were used: broom v1.0.11, car v3.1.3, cowplot v1.2.0, data.table v1.18.4, doParallel v1.0.17, dplyr v1.1.4, foreach v1.5.2, geosphere v1.5.20, ggh4x v0.3.1, ggplot2 v4.0.0, ggraph v2.2.2, ggrepel v0.9.6, ggsignif v0.6.4, ggstar v1.0.6, ggtext v0.1.2, ggthemes v5.1.0, gridExtra v2.3, igraph v2.1.4, knitr v1.50, latex2exp v0.9.6, lme4 v1.1.37, lmerTest v3.2.0, MuMIn v1.48.11, patchwork v1.3.2, plyr v1.8.9, RColorBrewer v1.1.3, relaimpo v2.2.7, scales v1.4.0, sf v1.0.21, spdep v1.4.1, stringr v1.6.0, tidycensus v1.7.3, tidygraph v1.3.1 and tigris v2.2.1.

This repository contains the analysis workflow for the spatial range exponent, \rho, a system-level measure of spatial mobility coherence. The workflow estimates how mobility-driven spatial correlations decay across adjacency-based urban networks, compares empirical estimates with distance-based null flow models, evaluates changes during disruptions, and links \rho to spatially correlated epidemic dynamics.

This repository provides the code and documentation for "The spatial reach of mobility interactions in urban systems". Main figure scripts are named by manuscript figure number (fig1--fig4). Supplementary figure scripts use the fig_SI_ prefix. Scripts with the reply_ prefix are analyses used during the response to reviewers and retained to document the revision-round checks.

Repository structure

Global configuration

  • sldr_global_vars_funs.R: Defines shared paths, study regions, MSA and disaster metadata, dates, labels, plotting palettes, error functions, and helper functions used across the workflow.

Data preparation

  • download_geodata.R: Downloads or prepares geographic inputs used to define spatial units.
  • select_region.R: Maps counties to each MSA, extracts CBGs or tracts within study boundaries, and joins demographic and geometric attributes.
  • od_flow.R: Processes SafeGraph origin-destination mobility records into daily CBG-level flows and degree summaries.
  • od_dist.R: Computes origin-destination travel-distance summaries used in mobility-structure analyses.

Typical processed inputs and outputs include:

  • <MSA>.geojson: spatial-unit geometries and attributes for each region.
  • selected_msa_county.csv: county rosters for the study MSAs.
  • Intra_Flow_<date>.csv: daily intra-region OD flows.
  • Intra_Degree_<date>.csv: daily in-degree and out-degree summaries.

SLDR estimation

  • sldr_fit_msa.R: Fits the Spatial Lag Decay Autoregressive (SLDR) model for each MSA and day. The script builds multi-lag adjacency matrices, estimates \rho under no-decay, power-law, and exponential-decay specifications, generates fitted outflows, and reports model-performance metrics.
  • sldr_fit_county.R: Repeats the SLDR workflow at county scale.
  • sldr_fit_msa_error.R: Evaluates model-fitting sensitivity to alternative loss functions and performance metrics.
  • sldr_fit_msa_half_year.R: Supports extended-window COVID-19 analyses.
  • sldr_fit_MAUP.R: Re-estimates \rho under alternative spatial representations, including CBG-to-tract aggregation and rook versus queen contiguity.
  • sldr_fit_japan.R: Applies the SLDR framework to YJMob100K Japanese metropolitan mobility data at multiple grid resolutions.

Main SLDR outputs include:

  • *_SLDR_params_*.csv: estimated model parameters, including \rho.
  • *_SLDR_fit_*.csv: empirical versus fitted outflows.
  • SLDR_r2_*.csv, SLDR_rank_cor_*.csv, and related metric files: model-performance summaries.

Null flow models and perturbation experiments

  • synthetic_flow.R: Generates gravity- and radial-style null flow models used to test whether pairwise distance and population constraints can reproduce empirical node-level spatial coherence.
  • fig2.R: Generates revised Fig. 2, including the empirical versus null-model comparison, empirical-null \rho discrepancies, the data-driven regime split, and flow-distance correlation analyses.
  • reply_fig_SI_synthetic_flow.R: Produces supplementary reviewer-response summaries and statistical evidence for the null-model comparison.
  • perturb_experiment.R: Runs controlled perturbation experiments separating uniform mobility-volume changes from spatial reorganization of flows.
  • fig3.R: Generates revised Fig. 3, including disruption-induced changes in \rho, E_{inter} and E_{normal} comparisons, and perturbation-experiment summaries.
  • reply_fig_SI_rho_comp_covid.R: Supports the revised E_{inter} and E_{normal} analyses for COVID-19.
  • reply_fig_SI_perturb_experiment.R: Supports the revised perturbation-experiment analysis.
  • reply_fig_SI_data_bias.R: Checks sensitivity to data-coverage or sampling-bias concerns.

Epidemic simulations

  • spreading_model.R: Simulates a spatially correlated SIR model in which \rho controls the decay of mobility-driven exposure across topological lags.
  • fig4.R: Generates revised Fig. 4, including COVID-19 severity versus changes in \rho, representative SIR infection trajectories under -3%, 0%, and +3% perturbations of \rho, and peak-infection changes under ±3%, ±6%, and ±9% perturbations.
  • fig_SI_SIR.R: Generates supplementary SIR sensitivity analyses, including sensitivity to \rho and simulations across infection rate \beta and recovery rate \mu.

Simulation outputs include:

  • SIR_model_as_*.csv: epidemic trajectories generated for the revised SIR analysis.

The simulations are scenario analyses rather than calibrated forecasts. They are used to test how changes in spatial coherence can reshape epidemic peak height and timing.

Figure generation

Main manuscript figures

  • fig1_a_c.R: Generates Fig. 1a-c, including conceptual panels for the spatial adjacency network, spatial lags, and exponential lag decay used to define \rho.
  • fig1_d_i.R: Generates Fig. 1d-i, including MSA and county estimates of \rho, population comparisons, and empirical-versus-model mobility snapshots for selected MSAs.
  • fig2.R: Generates Fig. 2, including edge-level distance decay versus node-level spatial coherence, null-model comparisons, empirical-null discrepancies, and the regime split.
  • fig3.R: Generates Fig. 3, including disruption-induced percentage changes in \rho, E_{inter} and E_{normal} comparisons, and perturbation-experiment summaries.
  • fig4.R: Generates Fig. 4, including COVID-19 severity associations and spatially correlated SIR simulation panels.

Supplementary figure scripts

  • fig_SI_lag_expansion.R: Generates supplementary lag-expansion results for queen-contiguity neighborhoods.
  • fig_SI_model_performance.R: Compares SLDR model performance across decay specifications and loss functions.
  • fig_SI_model_fit_maps_residuals.R: Shows empirical/model maps and residual diagnostics.
  • fig_SI_uncertainty_noise.R: Reports perturbation-based uncertainty of \rho and representative 95% confidence intervals.
  • fig_SI_MAUP.R: Tests sensitivity of \rho to spatial aggregation and contiguity definition.
  • fig_SI_cbg_area.R: Summarizes CBG and tract area distributions and their associations with \rho.
  • fig_SI_od_distance_commute.R: Generates OD travel-distance and commuting-mode analyses.
  • fig_SI_rho_geo_var.R and fig_SI_rho_geo_var_mean.R: Visualize associations between \rho and geographic, mobility, and urban-morphology covariates using median or mean CBG area.
  • fig_SI_rho_geo_var_contr.R and fig_SI_rho_geo_var_contr_mean.R: Visualize covariate-block contributions using median or mean CBG area.
  • fig_SI_rho_japan.R: Validates the SLDR framework on YJMob100K Japanese metropolitan mobility data and evaluates sensitivity to grid resolution.
  • fig_SI_SIR.R: Generates supplementary SIR analyses for \rho and epidemiological-parameter sensitivity.

Tables and uncertainty analyses

  • uncertainty_noise.R: Generates perturbation-based uncertainty estimates used by fig_SI_uncertainty_noise.R.
  • rho_CI_table.R: Produces confidence-interval tables for alternative decay kernels.
  • rho_CI.R: Computes confidence-interval inputs for the SLDR estimates.
  • CI.R: Provides confidence-interval helper routines.
  • rho_geo_var.R: Fits statistical models relating \rho to urban size, spatial-unit area, mobility structure, and urban morphology.

Data access

Raw SafeGraph mobility data are subject to access restrictions and are not redistributed in this repository. The workflow is designed around processed, results-level outputs where possible, including SLDR parameter files, model-fit files, null-model summaries, perturbation outputs, and SIR simulation outputs.

Reproducibility notes

  1. Update the path variables in sldr_global_vars_funs.R and in each script's workpath block to match your local directory layout.
  2. Run data-preparation scripts before model-fitting scripts.
  3. Run SLDR fitting scripts before figure scripts that depend on estimated \rho.
  4. Run synthetic_flow.R before fig2.R and reply_fig_SI_synthetic_flow.R.
  5. Run perturb_experiment.R before fig3.R and reply_fig_SI_perturb_experiment.R.
  6. Run spreading_model.R before fig4.R and fig_SI_SIR.R.
  7. Use a fixed spatial representation when comparing \rho across cities or over time. Cross-city comparisons are most meaningful when spatial units and adjacency definitions are held constant.