A reproducible R analysis predicting the rate of new business formation across United States counties from six demographic and economic predictors.
Read the rendered work directly:
- Read the report: full narrative with findings, discussion, and a worked county-level prediction example.
- Open the analysis notebook: every EDA plot, model fit, and diagnostic, with R code visible.
What county-level demographic and economic characteristics best predict the rate of new business formation across United States counties, and how accurately can a county's startup activity be predicted from its demographic profile alone?
Two primary sources, both pulled directly from the United States Census Bureau and joined on the 5-digit FIPS county code.
Target: estabs_entry / total_pop * 1,000, derived from the Business Dynamics Statistics (BDS) county time series, 2023 release.
Predictors (six, all from American Community Survey 5-Year Estimates 2019 to 2023):
| Variable | Source | Meaning |
|---|---|---|
median_income |
ACS B19013 | Median household income |
pct_bachelors_or_higher |
ACS B15003 | Share of adults 25 and over with a bachelor's degree or higher |
pct_foreign_born |
ACS B05002 | Share of population that is foreign-born |
lfp_rate |
ACS B23025 | Civilian labor force participation rate |
mean_commute |
ACS B08013, B08303 | Aggregate travel time divided by total workers |
pct_25_44 |
ACS B01001 | Share of population aged 25 to 44 |
Modeling sample: 3,069 United States counties after dropping rows with any missing modeling value and counties with fewer than 1,000 residents.
Two paths, pick whichever you prefer.
Fastest (no Census API needed): the data/ folder in this repository already contains the cleaned modeling table (panel_clean.csv) plus the intermediate BDS and ACS files. Skip straight to step 2.
From scratch (re-pull from Census):
-
Open
01_data_pull.Rmdin RStudio (or your preferred R IDE) and knit it. It downloads the BDS county time series (~19 MB, one-time), calls the ACS API (no key required at this query size), joins on FIPS, derives the target and the six predictors, and writes the result todata/panel_clean.csv. -
Open
02_analysis.Rmdand knit it. It readsdata/panel_clean.csv, runs exploratory analysis, fits three regression models (LASSO, Random Forest, kNN), evaluates them on a held-out test split, and produces the diagnostic figures. -
Open
03_report.Rmdand knit it. It reads the same modeling table and produces the rendered final report (Word and HTML outputs).
- LASSO regression (via
glmnet): linear baseline with L1 regularization for variable selection. - Random Forest (via
randomForest): captures nonlinear interactions and the J-shape and U-shape relationships visible in the EDA. - k-Nearest Neighbors (via
caret): nonparametric reference model.
All three are fit on the same 80/20 train/test split with seed-stabilized partitioning.
Random Forest produced the lowest held-out test RMSE among the three models compared. Bachelor's-degree share emerged as the strongest single predictor of county-level startup rate, with a clear positive relationship; foreign-born share and prime-age share (25 to 44) also contributed meaningfully. LASSO compressed predictions toward the mean, which is expected behavior for a linear model fit to a right-skewed target distribution. See 03_report.Rmd for the full discussion, including a sample county-level prediction comparison for Travis County, Texas.
Rendered outputs (read these first; no R install needed):
| File | Purpose |
|---|---|
03_report.html |
Start here. Rendered final report: introduction, methods, EDA highlights, model comparison, headline findings, worked county-level prediction example, limitations, and future work. |
03_report.docx |
Word version of the same report, for readers who prefer a downloadable document. |
02_analysis.html |
Full analytical notebook: every EDA plot, model fit, diagnostic, and partial-dependence curve, with the underlying R code visible. For readers who want the workings, not just the conclusions. |
Source notebooks:
| File | Purpose |
|---|---|
01_data_pull.Rmd |
Data acquisition: pulls BDS and ACS, joins on FIPS, derives the target and six predictors, writes outputs into data/. Run once. |
02_analysis.Rmd |
Source for the main analysis (produces 02_analysis.html). |
03_report.Rmd |
Source for the final report (produces 03_report.html and 03_report.docx). |
Data:
| File | Purpose |
|---|---|
data/bds_raw.csv |
Raw BDS county time-series download. |
data/bds_county.csv |
BDS filtered to the modeling year. |
data/acs_raw.json |
Raw ACS API response. |
data/acs_county.csv |
ACS cleaned and column-named. |
data/panel_clean.csv |
Joined and derived modeling table (the input every model reads). |
tidyverse, caret, glmnet, randomForest, skimr, naniar, visdat, knitr, pdp, usmap, httr, jsonlite.
Install with:
install.packages(c("tidyverse", "caret", "glmnet", "randomForest",
"skimr", "naniar", "visdat", "knitr", "pdp",
"usmap", "httr", "jsonlite"))MIT. See LICENSE.