Skip to content

Lennox7384/data318-modeling

Repository files navigation

Predicting County-Level Small Business Formation

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:

Question

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?

Data

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.

How to reproduce

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):

  1. Open 01_data_pull.Rmd in 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 to data/panel_clean.csv.

  2. Open 02_analysis.Rmd and knit it. It reads data/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.

  3. Open 03_report.Rmd and knit it. It reads the same modeling table and produces the rendered final report (Word and HTML outputs).

Models compared

  • 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.

Headline findings

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.

Files

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).

R package dependencies

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"))

License

MIT. See LICENSE.

About

A reproducible R analysis predicting the rate of new business formation across United States counties from six demographic and economic predictors.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages