Calculate survey confidence intervals by zone group and region
calc_survey_ci.RdCalculates confidence intervals for survey data by zone group and region, joining weights and crosswalks, and summarizing by group. Use for reporting survey fit and uncertainty.
Usage
calc_survey_ci(
seed,
weights,
zone_group_crosswalk,
puma_client_zone_xwalk,
ci_level = 0.9,
run_label,
settings
)Arguments
- seed
data.table with required columns:
hh_id_dow— household-day ID segment_nameRows: one per household-day. Keys: ( hh_id_dow). Modified by reference: no (returns copy).
- weights
data.table with required columns:
hh_id_dowzone_group_balanced_weightRows: one per household-day. Keys: ( hh_id_dow). Modified by reference: no (returns copy).
- zone_group_crosswalk
data.table. Zone group crosswalk.
- puma_client_zone_xwalk
data.table. PUMA to client zone crosswalk.
- ci_level
numeric(1). Confidence interval level (e.g., 0.9).
- run_label
character(1). Run label for output files.
- settings
list. Must include:
outputs_dir— output directory seed_wtd_path— seed weighted path
Value
list with two data.tables:
zone_group: survey confidence intervals by zone group. Columns:
variable
— variable name day_group
— day group label mean
— mean value lower
— lower confidence bound upper
— upper confidence bound Additional columns as needed for reporting
region: survey confidence intervals by region. Columns:
variable
— variable name day_group
— day group label mean
— mean value lower
— lower confidence bound upper
— upper confidence bound Additional columns as needed for reporting
Details
Checks if outputs are up-to-date; re-runs if needed.
Joins weights to seed and adds zone group via crosswalks.
Summarizes survey data by zone group and region using helper functions.
Drops transit boardings for region summary.
Returns a list of data.tables for zone group and region.
Settings
outputs_dir (direct): Output directory. Default from settings.
seed_wtd_path (direct): Seed weighted path. Default from settings.
See also
summarize_surveyscripts/weighting/survey_fit.R
Other survey analysis:
calc_max_error(),
calc_weight_fit()
Examples
## Not run:
seed <- data.table(hh_id_dow = "H1", segment_name = "A")
weights <- data.table(hh_id_dow = "H1", zone_group_balanced_weight = 1.2)
zone_group_crosswalk <- data.table()
puma_client_zone_xwalk <- data.table()
ci_level <- 0.9
run_label <- "test"
settings <- list(outputs_dir = "out", seed_wtd_path = "seed.rds")
calc_survey_ci(seed, weights, zone_group_crosswalk, puma_client_zone_xwalk, ci_level, run_label, settings)
#> Error in get("working_dir", settings): object 'working_dir' not found
## End(Not run)