Skip to contents

Creates a crosswalk assigning zones to groups for weighting, using manual specification or clustering. Use to prepare zone group mapping for populationSim.

Usage

prepare_zone_groups(
  seed,
  targets,
  settings,
  show_plot = FALSE,
  replace = FALSE
)

Arguments

seed

data.table. Survey seed data.

targets

data.table. PUMS targets data.

settings

list. Must include:

  • zone_groups — manual group specification

  • puma_clustering — clustering method and parameters

  • zone_type — grouping unit type Additional settings as needed for grouping and clustering

show_plot

logical. If TRUE, shows plot of zone groups in console.

replace

logical. If TRUE, replaces cached crosswalk if exists.

Value

data.table with columns:

  • client_zone_id — client zone identifier

  • zone_group — zone group label

  • zone_group_label — descriptive label for zone group

  • geometry — geometry column (optional) Additional columns as needed for diagnostics Rows: one per zone. Keys: (client_zone_id).

Details

  • Uses manual group specification or k-means clustering (optimal K or user-defined).

  • Handles client zones and PUMA zones as grouping units.

  • Adds geometry if available and saves output to working directory.

  • Optionally visualizes grouping in console.

  • Returns a copy; does not modify by reference.

Settings

  • zone_groups (direct): Manual group specification. Default from settings.

  • puma_clustering (direct): Clustering method and parameters. Default from settings.

  • zone_type (direct): Grouping unit type. Default from settings.

Examples

## Not run:
seed <- data.table(client_zone_id = "Z1")
targets <- data.table(client_zone_id = "Z1")
settings <- list(zone_groups = list(), puma_clustering = list(), zone_type = "client_zones")
prepare_zone_groups(seed, targets, settings)
#> Error in if (!dir.exists(dirname(table_path))) {    stop("Parent folder does not exist. Did you run load_settings()?")}: argument is of length zero
## End(Not run)