Compute commute flow statistics from LODES OD data
Source:R/compute_commute_stats.R
compute_commute_stats.RdDerives three key commute flow metrics from an OD tibble: inflow, outflow, net flow, and the self-containment ratio. These metrics are widely used in transportation planning and economic geography to characterize labor market catchment areas and job/housing balance.
Self-containment is defined as the proportion of workers who both live and work within the same geographic unit, relative to all employed residents. A value close to 1 indicates a highly self-contained labor market; values near 0 indicate heavy out-commuting.
Net flow is defined as inbound workers minus outbound workers (including internal flows as both in and out). This is an unsigned flow balance indicator: positive values signal net job importers (more workers arrive than leave); negative values signal net exporters.
Cross-state commuters: When state_part = "main" is used in
grab_lodes(), only workers who live and work in the same state are
included. Workers who cross state lines (e.g., Maryland residents working
in DC) appear only in state_part = "aux" files for the workplace
state. To capture full commute flows for border counties, retrieve both
"main" and "aux" files and bind the rows before calling
compute_commute_stats().
Arguments
- od_df
A data frame (tibble) of LODES origin-destination data returned by
grab_lodes()withlodes_type = "od". Must include columnsh_{agg_geo}(home geography),w_{agg_geo}(work geography), andS000(total job count). The data frame may be at any aggregation level supported byagg_geo.Note on row structure: LODES OD files are a flow matrix. A call to
grab_lodes()withlodes_type = "od"returns one row per origin-destination pair, not one row per geography – even after aggregation viaagg_geo. For example, a county-level OD pull for West Virginia returns ~2,800 rows (one per observed county-county flow pair), not 55 (the number of counties). Pass the result directly tocompute_commute_stats()to reduce the pair table to one row per geography with inflow, outflow, net flow, and self-containment.- agg_geo
The geographic level of the OD data. Must match the level at which
od_dfwas retrieved or aggregated. One of"block","bg","tract","county", or"state". Defaults to"tract".
Value
A tibble with one row per geography, containing:
{agg_geo}The geographic identifier.
yearYear of the data (if present in
od_df).stateState FIPS abbreviation (if present in
od_df).workers_inTotal workers arriving (working in this geography).
workers_outTotal workers departing (living here, working elsewhere).
workers_internalWorkers whose home and work are both in this geography (internal flows).
net_flowNet worker flow:
workers_in - workers_out. Positive values indicate net job importers.self_containmentShare of resident workers who also work in this geography:
workers_internal / workers_out_total, whereworkers_out_totalincludes internal flows.
Examples
if (FALSE) { # \dontrun{
od <- grab_lodes(
state = "md", year = 2019,
lodes_type = "od", job_type = "JT00",
segment = "S000", state_part = "main",
agg_geo = "county"
)
compute_commute_stats(od, agg_geo = "county")
} # }