Skip to content

About

Reproducible R/Python pipeline linking the built environment — street networks, tree canopy, heat, pollution — to census-tract health outcomes, with honest cross-place external-validity testing.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

BEHI — Built Environment Health Index

A reproducible pipeline for modeling how the built environment shapes tract-level population health — and for honestly testing whether those relationships generalize across places.

R Python License: MIT Status

BEHI links neighborhood physical characteristics — street-network form, tree canopy, impervious surface, greenness, urban heat, and pollution burden — to census-tract health outcomes from the CDC, and distills them into a per-tract Built Environment Health Index. It ships with the modeling code and the external-validity checks that tell you when the index does and does not travel between places.

It runs in two geographies:

  • Regional mode — every tract in a set of states (originally New England).
  • Dense-cities mode — the census tracts of selected dense US cities nationwide. (This is the recommended mode; see Findings for why.)

Findings so far

1. New England, and why a whole-region sample fell short

The first build modeled six built-environment feature families → six CDC PLACES outcomes across all six New England states (~3,682 tracts), built-environment only (no socioeconomic confounders).

A leave-one-state-out test (03b_state_validation.R) — train on five states, predict the sixth — showed the model does not generalize: every outcome had a negative out-of-state R² (it did worse than predicting the held-out state's own mean). The failure was structural: predicting urban Massachusetts from the five smaller/more-rural states was catastrophic (mental-health R² = −11.6), because MA's neighborhoods lie outside anything the rural states teach the model.

The misstep, stated plainly: a whole region mixes one dense-urban state with mostly low-density ones. A built-environment→health relationship fit on rural tracts does not transfer to urban tracts. Density heterogeneity, not the method, broke external validity.

Full write-up: docs/cross_state_validation.md.

2. The pivot — sample dense US cities instead

The fix implied by that result: don't sample a rural-dominated region; sample dense urban cores nationwide, so the tracts are comparable and cross-city generalization is a fair test. urban_cities.R selects 28 cities / 32 counties / 22 states / 4 regions, density-ranked, each resolved to and verified against Census county FIPS. Selection: docs/ + scripts/urban_cities.R.

3. Dense-cities pull works — and the signal is cleaner

An end-to-end 4-city test (Boston, Chicago, Miami, San Francisco; 2,509 tracts) pulled street-network features + health outcomes and joined them cleanly. The walkability–obesity link appears in the right direction and stronger than in New England:

Feature Obesity High BP Sleep
intersection density −0.25 −0.10 −0.10
node density −0.26 −0.10 −0.11
mean block length (sprawl) +0.16 +0.12 +0.10

Denser, more-connected streets track lower obesity; longer blocks track higher obesity — the classic finding. Full write-up: docs/urban_feature_pull.md, docs/urban_smoke_test.md.

Caveat: a county is city core + suburbs. Cook County (Chicago) reaches far past the grid into low-density suburbs, halving its mean density vs. the city-core counties. For a strict "dense city" study, restrict to the central place or a density threshold.


Quickstart

git clone https://github.com/<your-username>/behi.git
cd behi
pip install -r scripts/requirements.txt      # Python deps (incl. osmnx, geopandas)
Rscript scripts/install_r_packages.R          # R deps

Setting environment variables — examples below use VAR=value cmd (bash). On Windows PowerShell use $env:VAR='value'; cmd instead.

Mode A — Dense US cities (recommended)

Run from inside scripts/:

# 1. Pick your cities: edit the tribble in urban_cities.R (add/remove rows),
#    then resolve + verify their county FIPS against the Census registry.
Rscript urban_cities.R

# 2. (optional) Confirm health data exists for your cities — fast, no downloads.
Rscript smoke_test_cities.R

# 3. Pull tract geometry + CDC PLACES outcomes for the cities you want.
#    Default is a 4-city test set; use "all" for every city in urban_cities.csv.
URBAN_CITIES="Boston,Chicago,Miami,San Francisco" Rscript 00_data_pull_urban.R

# 4. Street-network features from OpenStreetMap.
python 01_street_network.py
#    If a large county runs out of memory, extract it in tiles, then re-combine:
COUNTY_FIPS=17031 GRID=3 python 01b_street_tiled.py
python 01_street_network.py       # re-run: reads caches, writes the combined CSV

# 5. Join built environment (X) + health (Y) into a modeling-ready dataset.
Rscript urban_build_dataset.R     # -> output/urban_analysis_dataset.csv

No Census API key is required for this mode (built-environment-only analysis).

Mode B — Regional / states (original New England pipeline)

cd scripts
# (optional) real ACS covariates — copy .env.example to .env and set CENSUS_API_KEY
Rscript 00_data_pull.R                        # tracts, CDC PLACES, EPA walkability, ACS
python  01_street_network.py                  # + the 00b–00h feature scripts
ANALYSIS_STATE_FIPS="25,09,44,50,33,23" Rscript 02_imputation.R   # MICE (default: all 6 NE)
Rscript 03_modeling.R                         # GAM + SuperLearner ensemble + HAL
Rscript 03b_state_validation.R                # leave-one-state-out external validity

Configuration reference

Every geography/behavior toggle is an environment variable — no code edits needed for the common cases.

Variable Used by Default Purpose
URBAN_CITIES 00_data_pull_urban.R Boston,Chicago,Miami,San Francisco Which cities to pull (comma list, or all)
COUNTY_FIPS, GRID 01b_street_tiled.py 17031, 3 Tiled street extraction for a large county (raise GRID if OOM)
ANALYSIS_STATE_FIPS 02_imputation.R all 6 NE states Which states enter the regional model
RUN_ENSEMBLE_LOSO 03b_state_validation.R FALSE Also validate the nadir SuperLearner ensemble (slower)
CENSUS_API_KEY 00_data_pull.R (none → synthetic ACS) Free key from api.census.gov

Repository structure

behi/
├── scripts/
│   ├── urban_cities.R           # A1: select + verify dense cities -> urban_cities.csv
│   ├── 00_data_pull_urban.R     # A2: county-based tracts + CDC PLACES outcomes
│   ├── smoke_test_cities.R      # A2: quick health-data coverage check (no downloads)
│   ├── 00_data_pull.R           # B1: state-based pull (tracts/PLACES/SLD/ACS)
│   ├── 00b_*.py … 00h_*.py      # B: feature engineering (NLCD, EJScreen, heat, …)
│   ├── 01_street_network.py     # OSM street morphology per tract  (both modes)
│   ├── 01b_street_tiled.py      # memory-bounded street extraction for big counties
│   ├── 02_imputation.R          # MICE multiple imputation (regional mode)
│   ├── 03_modeling.R            # GAM + SuperLearner ensemble + HAL
│   ├── 03b_state_validation.R   # leave-one-state-out external validity
│   ├── urban_build_dataset.R    # join X + Y for the dense-cities dataset
│   ├── requirements.txt         # Python deps
│   └── install_r_packages.R     # R deps
├── docs/
│   ├── cross_state_validation.md  # New England leave-one-state-out results
│   ├── urban_smoke_test.md        # dense-cities health-data smoke test
│   └── urban_feature_pull.md      # 4-city end-to-end feature pull results
├── data/     # generated datasets            (gitignored)
├── cache/    # cached API / OSM responses    (gitignored)
├── output/   # figures, logs, index scores   (gitignored)
├── .env.example · LICENSE · README.md

Methods

  • Multiple imputation (MICE, PMM) for missing covariates
  • Generalized additive models (mgcv; bam() for fast fitting) with smooth terms over built-environment features
  • SuperLearner ensemble via nadir (lnr_gam, lnr_glmnet, …) plus the highly adaptive LASSO (hal9001)
  • Spatial cross-validation (spatialsample) and spatial-lag diagnostics (spdep, spatialreg)
  • Leave-one-place-out external validation with predictions bounded to the training outcome range (so GAM extrapolation can't manufacture nonsense)

Data sources

All open and public: CDC PLACES (tract health outcomes), U.S. Census TIGER/Line & ACS (tigris, tidycensus), OpenStreetMap (osmnx), EPA Smart Location Database & EJScreen, MRLC/NLCD land cover, plus satellite NDVI and land-surface temperature.

Status & caveats

An exploratory research prototype, not a validated public-health instrument.

  • Cross-place external validity is weak-to-negative in the rural-mixed regional mode (see Findings) — read the index as methodological, not causal.
  • In dense-cities mode, a county includes suburbs; density-strict studies should subset further.
  • The dense-cities mode currently wires street-network features + outcomes; the remaining feature layers (NLCD, EJScreen, greenness, heat) are the next step.
  • Without a Census key the regional mode uses synthetic ACS covariates (the CDC PLACES outcomes and OSM geometry are always real).

Acknowledgements

Methodological guidance and the nadir SuperLearner package — Dr. Christian Testa. Data from CDC PLACES, the U.S. Census Bureau, OpenStreetMap contributors, the U.S. EPA, and MRLC/NLCD.

License

MIT © 2026 Laksh Agarwal.

About

Reproducible R/Python pipeline linking the built environment — street networks, tree canopy, heat, pollution — to census-tract health outcomes, with honest cross-place external-validity testing.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages