Skip to contents

Converts ACS count columns to proportions for each geography, normalizing by total population. Use to prepare ACS reference data for ethnicity imputation or other proportional analyses.

Usage

calculate_acs_proportions(acs_wide)

Arguments

acs_wide

data.table. Wide-format ACS table with columns:

  • GEOID — geographic identifier

  • n_total — total population

  • n_* — counts for each ethnicity level Rows: one per geography. Keys: (GEOID). Modified by reference: no (returns copy).

Value

data.table. ACS proportions by geography. Columns:

  • GEOID — geographic identifier

  • f_* — fraction of population for each ethnicity level Rows: one per geography. Keys: (GEOID).

Details

  • Identifies count columns prefixed with n_ (excluding n_total).

  • Computes fraction columns (f_*) as count divided by n_total for each row.

  • Fills missing fractions with zero.

  • Checks that fractions sum to 1 (within tolerance); drops rows failing this check.

  • Removes count columns, returning only fraction columns and identifiers.

  • Assumes input is a wide-format ACS data.table with n_total and ethnicity counts.

Settings

None.

Examples

## Not run:
acs_wide <- data.table(GEOID = "12345", n_total = 100, n_hispanic = 20, n_not_hispanic = 80)
calculate_acs_proportions(acs_wide)
#> Error in calculate_acs_proportions(acs_wide): could not find function "calculate_acs_proportions"
## End(Not run)