Skip to contents

Allocates ACS reference counts to sample plan geographies, adjusting for year and segment overlaps. Use when preparing cleaned sample plan and ACS counts for weighting.

Usage

calc_sample_plan_counts(
  sample_plan,
  settings,
  pums_year = NULL,
  sample_plan_year = NULL,
  study_unit = NULL,
  dataset = NULL
)

Arguments

sample_plan

data.table with required columns:

  • segment_name — segment label

  • bg_geoid — block group GEOID

  • ref_count_h — reference household count (optional)

  • ref_count_p — reference person count (optional)

  • Additional columns as needed for weighting pipeline Rows: one per block group per segment. Keys: (segment_name, bg_geoid). Modified by reference: no (returns copy).

settings

list. Must include:

  • acs_year — ACS reference year

  • acs_count_vars — ACS count variable names

  • pums_year — PUMS target year (optional)

  • sample_plan_year — sample plan year (optional)

  • study_unit — 'household' or 'person' (optional)

  • acs_dataset — ACS dataset: 'acs5' or 'acs1' (optional) Additional settings as needed for allocation and crosswalk logic

pums_year

integer. PUMS target year. If NULL, uses settings.

sample_plan_year

integer. Sample plan year. If NULL, uses settings.

study_unit

character(1). 'household' or 'person'. If NULL, uses settings.

dataset

character(1). 'acs5' or 'acs1'. If NULL, uses settings.

Value

list with two data.tables:

  • cleaned_sample_plan: columns:

    • segment_name

    • bg_geoid

    • ref_count_h — allocated household count (if applicable)

    • ref_count_p — allocated person count (if applicable)

    • Additional columns as needed for weighting

  • acs_counts: columns:

    • bg_geoid

    • ref_count_h — reference household count (if applicable)

    • ref_count_p — reference person count (if applicable)

    • Additional columns as needed for reference counts Rows: one per block group per segment. Keys: (segment_name, bg_geoid).

Details

  • Fetches ACS counts for PUMS target year using sample plan block groups.

  • Creates crosswalk for overlapping block group geometries and intersection ratios.

  • Allocates reference counts to sample plan year geographies, adjusting for overlaps.

  • Aggregates and cleans sample plan for weighting pipeline.

  • Assumes sample plan and ACS years may differ; handles crosswalk logic.

  • Returns a copy; does not modify by reference.

Settings

  • acs_year (direct): ACS reference year. Default from settings.

  • acs_count_vars (direct): ACS count variable names. Default from settings.

  • pums_year, sample_plan_year, study_unit, acs_dataset

Examples

## Not run:
sample_plan <- data.table(segment_name = "A", bg_geoid = "12345")
settings <- list(acs_year = 2020, acs_count_vars = c("h_total", "p_total"))
result <- calc_sample_plan_counts(sample_plan, settings)
#> Error in get("pums_year", settings): object 'pums_year' not found
## End(Not run)