Package 'rurality'

Title: Classification and Scoring of U.S. County and ZIP Code Rurality
Description: Provides USDA Rural-Urban Continuum Codes (RUCC 2023), Rural-Urban Commuting Area codes (RUCA 2020), and a composite rurality score for all U.S. counties. Functions enable lookup by FIPS code, ZIP code, or county name, and easy merging with existing datasets. Data sources include the USDA Economic Research Service, U.S. Census Bureau American Community Survey, and Census TIGER/Line shapefiles.
Authors: Cameron Wimpy [aut, cre] (ORCID: <https://orcid.org/0000-0002-2049-5229>)
Maintainer: Cameron Wimpy <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0.9000
Built: 2026-05-22 09:06:38 UTC
Source: https://github.com/cwimpy/rurality

Help Index


Merge Rurality Data onto a Data Frame

Description

Joins rurality data onto an existing data frame by FIPS code.

Usage

add_rurality(
  data,
  fips_col = "fips",
  vars = c("rurality_score", "rurality_classification", "rucc_2023")
)

Arguments

data

A data frame with a FIPS code column.

fips_col

The name of the FIPS code column (default: "fips").

vars

Which rurality variables to add. Default adds score and classification. Use "all" for all variables.

Value

The input data frame with rurality columns appended.

Examples

my_data <- data.frame(fips = c("05031", "06037", "48453"), value = 1:3)
add_rurality(my_data)
add_rurality(my_data, vars = "all")

Classify a Rurality Score

Description

Converts numeric rurality scores to classification labels.

Usage

classify_rurality(score)

Arguments

score

A numeric vector of rurality scores (0-100).

Value

A character vector of classifications.

Examples

classify_rurality(c(15, 35, 55, 75, 90))

County Crosswalk with Multiple Rurality Classification Schemes

Description

A county-level crosswalk combining the four major U.S. rurality classification schemes (USDA RUCC, USDA RUCA, NCHS Urban-Rural, and OMB Metropolitan/Micropolitan), along with Census urban/rural percentage and ACS 2022 5-year demographic covariates. Used by rurality_spec() to run specification curve analyses comparing schemes.

Usage

county_crosswalk

Format

A tibble with 3,143 rows and the following columns:

fips

5-digit county FIPS code (character)

state_fips

2-digit state FIPS code (character)

county_fips

3-digit county FIPS code (character)

county_name

County name

state_abbr

Two-letter state abbreviation

rucc_2023

USDA Rural-Urban Continuum Code 2023 (1-9)

ruca_2020_county

County-level RUCA 2020 (modal ZCTA code, 1-10)

nchs_2023

NCHS Urban-Rural Classification 2023 (1-6)

omb_class

OMB class: "metro", "micro", or "noncore"

pct_urban_2020

Percent of county population in Census urban areas (2020)

pop_total

ACS 2022 5-year total population

median_inc

ACS 2022 5-year median household income

pct_ba_plus

Percent of adults 25+ with bachelor's degree or higher

pct_nh_white

Percent non-Hispanic white

log_inc

log(median household income)

log_pop

log(total population)

pop_density

Population per square mile of land area

Source

  • USDA Economic Research Service: RUCC 2023, RUCA 2020

  • NCHS Urban-Rural Classification Scheme for Counties 2023

  • U.S. Office of Management and Budget, CBSA delineations

  • U.S. Census Bureau: 2020 Decennial (urban/rural), ACS 2022 5-year

Examples

county_crosswalk

County-Level Rurality Data for the United States

Description

A dataset containing rurality scores, USDA classifications, and demographic data for all U.S. counties. Includes RUCC 2023 codes, population density, distance to metro areas, and a composite rurality score.

Usage

county_rurality

Format

A tibble with approximately 3,233 rows and 23 columns:

fips

5-digit county FIPS code (character)

state_fips

2-digit state FIPS code (character)

county_fips

3-digit county FIPS code (character)

state_abbr

Two-letter state abbreviation

county_name

County name

pop_2020

2020 Census population

acs_pop

ACS 2022 5-year population estimate

land_area_sqmi

Land area in square miles

pop_density

Population per square mile

rucc_2023

USDA Rural-Urban Continuum Code (1-9)

rucc_description

RUCC code description

omb_designation

OMB designation: Metropolitan, Micropolitan, or Nonmetro

lat

County centroid latitude

lng

County centroid longitude

dist_large_metro

Distance to nearest large metro (>1M pop) in miles

dist_medium_metro

Distance to nearest medium metro (250K-1M) in miles

dist_small_metro

Distance to nearest small metro (50K-250K) in miles

rucc_score

RUCC-derived score component (0-100)

density_score

Population density score component (0-100)

distance_score

Distance to metro score component (0-100)

rurality_score

Composite rurality score (0-100)

rurality_classification

Classification: Urban, Suburban, Mixed, Rural, Very Rural

median_income

ACS 2022 median household income

median_age

ACS 2022 median age

Details

The composite rurality score is calculated as a weighted average:

  • RUCC score: 55\

  • Population density score: 28\

  • Distance to metro score: 17\

Classifications:

  • 80-100: Very Rural

  • 60-79: Rural

  • 40-59: Mixed

  • 20-39: Suburban

  • 0-19: Urban

Source

  • USDA Economic Research Service, Rural-Urban Continuum Codes 2023

  • U.S. Census Bureau, American Community Survey 2022 5-Year Estimates

  • U.S. Census Bureau, TIGER/Line Shapefiles 2020

Examples

# View the data
county_rurality

# Filter to rural counties
library(dplyr)
county_rurality |> filter(rurality_classification == "Very Rural")

# Arkansas counties
county_rurality |> filter(state_abbr == "AR")

Look Up RUCA Code by ZIP Code

Description

Returns the USDA Rural-Urban Commuting Area code (2020) for one or more ZIP codes or ZCTAs.

Usage

get_ruca(zip)

Arguments

zip

A character vector of 5-digit ZIP codes.

Details

RUCA codes range from 1 (metropolitan core) to 10 (rural). The primary code reflects the majority commuting pattern; the secondary code captures additional commuting flows.

Value

A tibble with columns: zip, primary_ruca, secondary_ruca, state. Returns NA values for ZIPs not in the RUCA dataset.

Examples

get_ruca("72401")
get_ruca(c("72401", "90210", "59801"))

Get RUCC Code for a County

Description

Returns the USDA Rural-Urban Continuum Code (2023) for one or more counties.

Usage

get_rucc(fips)

Arguments

fips

A character vector of 5-digit county FIPS codes.

Value

An integer vector of RUCC codes (1-9), or NA for unmatched FIPS.

Examples

get_rucc("05031")
get_rucc(c("05031", "06037"))

Look Up Rurality Data by FIPS Code

Description

Returns the full rurality record for one or more county FIPS codes.

Usage

get_rurality(fips)

Arguments

fips

A character vector of 5-digit county FIPS codes.

Value

A tibble with rurality data for the matched counties.

Examples

get_rurality("05031")
get_rurality(c("05031", "06037", "48453"))

RUCA Code Data for U.S. ZIP Codes

Description

USDA Rural-Urban Commuting Area codes (2020) for approximately 41,000 ZCTAs.

Usage

ruca_codes

Format

A tibble with columns:

zip

5-digit ZIP/ZCTA code (character)

state

Two-letter state abbreviation

primary_ruca

Primary RUCA code (1-10)

secondary_ruca

Secondary RUCA code (1-10)

Source

USDA Economic Research Service, Rural-Urban Commuting Area Codes 2020


Get Rurality Score for a County

Description

Returns the composite rurality score (0-100) for one or more counties.

Usage

rurality_score(fips)

Arguments

fips

A character vector of 5-digit county FIPS codes.

Value

A numeric vector of rurality scores, or NA for unmatched FIPS.

Examples

rurality_score("05031")
rurality_score(c("05031", "06037", "48453"))

Specification Curve Analysis Across Rurality Classification Schemes

Description

Runs a specification curve across four rurality classification schemes (RUCC, RUCA, NCHS, OMB), two functional forms (ordinal and binary metro/nonmetro), and three covariate sets, for one or more user-supplied county-level outcome variables. Returns a tidy data frame of coefficient estimates suitable for plotting or further analysis.

Usage

rurality_spec(
  data,
  outcome,
  fips_col = "fips",
  covariates = NULL,
  schemes = c("rucc", "ruca", "nchs", "omb"),
  forms = c("ordinal", "binary"),
  covar_sets = c("minimal", "full", "state_fe"),
  plot = TRUE
)

Arguments

data

A data frame containing a 5-digit county FIPS column and at least one numeric outcome variable.

outcome

A character vector naming one or more outcome columns in data.

fips_col

Name of the FIPS column in data. Default "fips".

covariates

Optional character vector of additional covariate column names already present in data. These are added on top of the three built-in covariate sets (see Details). Default NULL.

schemes

Character vector of schemes to include. Any subset of c("rucc", "ruca", "nchs", "omb"). Default: all four.

forms

Character vector of functional forms. Any subset of c("ordinal", "binary"). Default: both.

covar_sets

Character vector of built-in covariate sets to use. Any subset of c("minimal", "full", "state_fe"). Default: all three. See Details.

plot

Logical. If TRUE (default), print a specification curve plot. Requires ggplot2.

Details

rurality_spec() joins the package's county_crosswalk dataset (FIPS backbone with RUCC, RUCA, NCHS, OMB, and ACS covariates) onto data by FIPS code, then fits OLS models for every combination of scheme, form, and covariate set requested.

Built-in covariate sets (using ACS 2022 variables from the crosswalk):

  • "minimal": log(population) + log(median income)

  • "full": minimal + percent BA or higher + percent non-Hispanic white

  • "state_fe": full + state fixed effects (factor(state_fips))

Ordinal predictors are standardized (mean 0, SD 1) so that coefficients are comparable across schemes with different scale lengths (RUCC: 1-9, RUCA: 1-10, NCHS: 1-6, OMB: 1-3).

Binary predictors code metropolitan = 0, nonmetropolitan = 1, using standard cutpoints: RUCC >= 4, RUCA >= 4, NCHS >= 5, OMB != "metro".

Any user-supplied covariates are appended to all three built-in covariate sets.

Value

A tibble with one row per specification per outcome, containing:

outcome

Outcome variable name

scheme

Rurality scheme (rucc, ruca, nchs, omb)

form

Functional form (ordinal or binary)

covars

Covariate set label

n

Number of observations

estimate

Coefficient on the rurality predictor

std.error

Standard error

statistic

t-statistic

p.value

p-value

conf.low

Lower 95% confidence interval

conf.high

Upper 95% confidence interval

r.squared

Model R-squared

Examples

## Not run: 
# Minimal example with a built-in outcome proxy
library(dplyr)

# Attach a synthetic outcome to the crosswalk
df <- county_rurality |>
  select(fips) |>
  mutate(y = rnorm(n()))

results <- rurality_spec(df, outcome = "y")
print(results)

## End(Not run)