Calculate target confidence intervals by zone group and region
calc_target_ci.RdCalculates confidence intervals for target (reference) data by zone group and region, joining PUMS data and crosswalks, summarizing by group, and saving outputs. Use for reporting fit and uncertainty of reference targets in weighting workflows.
Usage
calc_target_ci(
pums_tabbed,
zone_group_crosswalk,
puma_client_zone_xwalk,
ci_level = 0.9,
run_label,
settings
)Arguments
- pums_tabbed
data.table. Tabulated PUMS data. Required columns:
zone_group <character/integer> — zone group identifier
variable
— variable name total
— total value Other columns as needed for summarization. Rows: one per group-variable. Keys: none required. Modified by reference: no (returns copy).
- zone_group_crosswalk
data.table. Zone group crosswalk. Required columns:
client_zone_id <character/integer> — client zone identifier
zone_group <character/integer> — zone group identifier
zone_group_label
— zone group label Rows: one per client zone. Keys: none required. Modified by reference: no (read-only).
- puma_client_zone_xwalk
data.table. PUMA to client zone crosswalk. Required columns:
puma <character/integer> — PUMA code
client_zone_id <character/integer> — client zone identifier Rows: one per PUMA-client zone. Keys: none required. Modified by reference: no (read-only).
- ci_level
numeric(1). Confidence interval level (e.g., 0.9). Default: 0.9.
- run_label
character(1). Run label for output files.
- settings
list. Must include:
outputs_dir
— output directory working_dir
— working directory targets
- — named list of target variables
weight_dow_groups
- — day-of-week groups
transit_target_moe
— margin of error for transit targets (optional)
Value
list with two data.tables:
zone_group: target confidence intervals by zone group. Columns:
variable
— variable name day_group
— day group label lower
— lower confidence bound total
— total value upper
— upper confidence bound Additional columns as needed for reporting
region: target confidence intervals by region. Same columns as above.
Details
Checks if outputs are up-to-date; re-runs if needed.
Creates PUMA-to-zone group crosswalk using client zone and zone group crosswalks.
Summarizes PUMS data by zone group and region using helper functions.
Drops outside-region zone groups and transit boardings at zone group level.
Adds external transit targets to region summary if available.
Replicates total targets for each day group, creating dummy DOW targets.
Saves outputs as CSV files in the specified output directory.
Returns a list of data.tables for zone group and region.
Settings
outputs_dir (direct): Output directory. Default from settings.
working_dir (direct): Working directory. Default from settings.
targets (direct): Named list of target variables. Default from settings.
weight_dow_groups (direct): Day-of-week groups. Default from settings.
transit_target_moe (direct): Margin of error for transit targets. Default from settings.
Examples
## Not run:
pums_tabbed <- data.table(
zone_group = 1,
variable = "h_total",
total = 100
)
zone_group_crosswalk <- data.table(
client_zone_id = 1,
zone_group = 1,
zone_group_label = "A"
)
puma_client_zone_xwalk <- data.table(
puma = "P1",
client_zone_id = 1
)
ci_level <- 0.9
run_label <- "test"
settings <- list(
outputs_dir = "out",
working_dir = "work",
targets = list(),
weight_dow_groups = list(Mon = 1),
transit_target_moe = 0.05
)
calc_target_ci(
pums_tabbed,
zone_group_crosswalk,
puma_client_zone_xwalk,
ci_level,
run_label,
settings
)
#> Re-running calc_target_ci because inputs are newer than outputs.
#> Error in summarize_pums(pums_wide = pums_tabbed, group_col = "zone_group", puma_zone_group_xwalk = puma_zone_group_xwalk, ci_level = ci_level, settings = settings): pums_wide missing columns: puma_id, hh_id, person_id, WGTP, PWGTP, h_total, p_total
## End(Not run)