Prepare household vehicles target variable for weighting
prep_target_vehicles.RdCreates a standardized household vehicles target variable for household-level weighting and expansion, using either PUMS or survey input. Use when preparing vehicles targets for synthetic population or survey analysis.
Arguments
- h_data
data.table. Household-level input. Required columns:
For PUMS: must include
SERIALNO,VEH.For survey: must include vehicle and adult columns as specified in settings. Rows: one per household. Modified by reference: no (returns copy).
- p_data
data.table. Person-level input. Required columns:
For PUMS: must include
SERIALNO,AGEP.For survey: must include age column as specified in settings. Rows: one per person. Modified by reference: no (returns copy).
- target_name
character(1). Name of the target variable to create (default: "h_vehicles").
- codebook
data.table. Codebook for variable mapping; must include age and vehicle value and label columns.
- settings
list. Project settings; must include
targets[[target_name]]withlevels,pums_input, andsurvey_input.
Value
data.table. Copy of household-level input with new target variable column (target_name).
Columns: all original plus
target_name(factor)Values: "none", "insuff", "suff"
Row order preserved
Details
Detects input type (PUMS vs. survey) by presence of
SERIALNOcolumn inh_data.For PUMS:
Uses
VEHandVEH_labelcolumns for vehicle count and label.Aggregates number of adults from person-level data (
AGEP >= 16).
For survey:
Uses codebook to identify adults using regex
str_detect(label, '16[- ]17')(default survey value: 995 for missing/work from home).Aggregates number of adults and vehicles per household.
Applies logic:
num_vehicles == 0→ "none"num_vehicles < num_adults→ "insuff"num_vehicles >= num_adults→ "suff"
Applies
cut_and_labelto bin vehicle sufficiency into target levels.Renames output column to
target_name(default:h_vehicles).Returns a copy of the input data.table with the new target variable.
Error handling: stops if levels do not match expected values.
See also
get_target_methods, prep_target_h_size, prep_target_workers
Other target preparation:
get_target_methods(),
prep_target_adults(),
prep_target_age(),
prep_target_commutemode(),
prep_target_cross(),
prep_target_edulevel(),
prep_target_employment(),
prep_target_ethnicity(),
prep_target_gender(),
prep_target_h_size(),
prep_target_income(),
prep_target_kids(),
prep_target_race(),
prep_target_univstudent(),
prep_target_workers(),
prep_transit_target(),
prepare_targets(),
run_tabulate_method()