Data Preparation And Analysis Scripts
The scripts/ directory contains two related workflows:
scripts
0through6prepare the files stored indata/<STATE>/;scripts
7aand7bingest and explore completed simulation outputs.
The repository-level scripts/README.md is the working provenance record.
Update it when a source dataset, release year, assumption, or generated
filename changes.
State Input Pipeline
Open scripts/scripts.Rproj in RStudio and run
0_generate_US-State_inputs.R to orchestrate the input pipeline. Some source
datasets are large, require credentials, or live outside this repository, so
the scripts can also be run individually.
Step |
Script |
Primary result |
|---|---|---|
1 |
|
State directories, county population-by-age files, and initial-exposure candidates. |
2 |
|
State age-contact matrices from Epydemix/Mistry data. |
3a |
|
Geography crosswalks for Connecticut and Alaska boundary changes. |
3b |
|
County mobility time series, quarterly matrices, and connectivity rankings. |
4a |
|
State-and-age influenza high-risk proportions from BRFSS and NSCH. |
4b |
|
County high-risk ratios using state estimates and CDC PLACES burden; see County-Age High-Risk Ratio Derivation. |
5 |
|
State weekly vaccination stockpile schedules. |
6 |
|
State-specific JSON inputs and parallel simulator commands. |
6b |
|
All-state and DC initial-exposure initializer deriving county-age low-risk exposures and generated |
The resulting state directory normally contains:
data/<STATE>/
├── INPUT_*.json
├── contact_matrix_<STATE>_Mistry2021_all.csv
├── county_pop_by_age_<STATE>_2019-2023ACS.csv
├── state_<STATE>_high-risk-ratios-flu-only.csv
├── county_<STATE>_high-risk-ratios-flu-only.csv
├── <STATE>_Q1-2019_mobility-matrix.csv
├── <STATE>_Q2-2019_mobility-matrix.csv
├── <STATE>_Q3-2019_mobility-matrix.csv
├── <STATE>_Q4-2019_mobility-matrix.csv
├── <STATE>_quarterly-2019_mobility.csv
└── <STATE>_quarterly-2019_county-connection-ranking.csv
Age-group order must agree across population, contact, risk-ratio, disease, vaccine, and antiviral inputs. County order in each mobility matrix must agree with the population file.
Data Sources And Assumptions
Dataset |
Use |
Important assumptions |
|---|---|---|
County population by the five simulator age groups |
Uses 2023 five-year ACS estimates and modern county FIPS. |
|
Epydemix data using Mistry 2021 contacts |
State-specific age contact matrices |
Uses the |
2019 county-to-county mobility |
Keeps within-state flows, translates Alaska and Connecticut geography, normalizes outflow using population-based processing, and writes quarterly matrices. Missing county pairs are treated as zero flow. |
|
Adult state/age influenza high-risk estimates and vaccination survey fields |
Primarily 2024 data, with 2023 Tennessee data where 2024 submission was unavailable. |
|
Pediatric state/age influenza high-risk estimates |
Uses survey weights and pediatric conditions associated with severe influenza risk. |
|
Defines adult and pediatric conditions included in high-risk estimates |
In this simulator, “risk” means risk of hospitalization or death, not risk of becoming infected. |
|
Adjusts state/age high-risk estimates to county comorbidity burden |
Uses the latest available nonmissing county measures from the 2024 and 2025 releases. |
|
Comparison for county risk adjustment |
Retained as a comparison; current county risk construction is based primarily on PLACES comorbidities. |
|
Pediatric seasonal vaccine schedule |
Coverage is combined with pediatric effectiveness and state population. |
|
Adult seasonal vaccine schedule |
Adult and pediatric schedules are combined into weekly stockpile releases relative to October 1, 2024. |
|
Effectiveness assumptions used by the vaccine-preparation script |
The current script uses separate pediatric and adult inpatient-effectiveness assumptions. |
These source files are preparation inputs, not all committed repository data. Survey microdata, API keys, and the full daily mobility archive remain outside version control.
Output ETL
After simulations finish, configure SEARCH_ROOT near the top of
scripts/7a_process_output_to_db.R and run the script from the repository
working directory. It discovers metadata_batch-*.json, then:
Creates or updates
metadata_master.csvConverts network, node, and timing CSVs to compressed Parquet
Partitions Parquet as
sim_data/<scenario_hash>/<batch_num>/Optionally upserts metadata into MongoDB
Skips an already ingested
(scenario_hash, batch_num)pair
The source simulation directories remain the reproducibility record. Confirm
that the expected scenario/batch pairs are present in metadata_master.csv
before cleaning their larger CSV outputs.
Dashboard
Configure REPO_ROOT, MASTER_CSV, and PARQUET_ROOT near the top of
scripts/7b_sim_dashboard_app.R, then open the file in RStudio and select
Run App. The dashboard reads the metadata index and Parquet partitions to:
Filter scenarios by geography, model, and intervention
Inspect completion and run-time information by batch
Compare all batches sharing a scenario hash
Plot compartment trajectories
Export selected Parquet data back to CSV
The scenario hash represents the modeled configuration. The batch UUID represents one execution of that configuration. Keeping both identifiers is what makes repeated runs, partial batches, cleanup, and visualization compatible.