Update day pattern model targets with predicted probabilities
update_daypat_targets.RdUpdates client zone targets for the day pattern model using predicted probabilities, scaling to match total persons and adjusting by household weights. Use to harmonize day pattern targets for weighting and reporting.
Usage
update_daypat_targets(
probs_dt,
seed,
targets,
households,
hh_weights,
settings,
integerize = TRUE
)Arguments
- probs_dt
data.table. Predicted probabilities from day pattern model. Required columns:
hh_id: household ID person_id: person ID day_group: day-of-week group prob_made_*: predicted probabilities for each day pattern is_adult<logical/numeric>: adult flag Rows: one per person-day. Modified by reference: no (returns copy).
- seed
data.table. Seed data for day pattern model. Required columns:
hh_id,day_group,hh_id_dow,client_zone_id,p_total,h_total, etc. Rows: one per household-day. Modified by reference: no (returns copy).
- targets
data.table. Input targets by client zone. Required columns:
client_zone_id,p_total,h_total, etc. Rows: one per client zone. Modified by reference: no (returns copy).
- households
data.table. Household data. Required columns:
hh_id,num_kids,num_people, etc. Rows: one per household. Modified by reference: no (returns copy).
- hh_weights
data.table. Household weights. Required columns:
hh_id,day_group,hh_weightRows: one per household-day. Modified by reference: no (returns copy).
- settings
list. Project settings; must include relevant pipeline settings.
- integerize
logical(1). If TRUE, integerizes output values (TODO: not currently implemented).
Value
data.table. Updated client zone targets. Columns:
client_zone_id: client zone ID Household and person target columns (e.g.,
h_total,p_total,p_made_*)All columns from input targets and predicted probabilities
Row order: by client zone
Details
Asserts that
probs_dtcontains only adults (no children).Aggregates predicted probabilities by person and household, using regex pattern
prob_made_for columns.Checks that row sums of probabilities equal 1 for each person.
Sums probabilities by household and adds child column from
households.Renames columns for consistency (
prob_made_→p_made_).Casts to wide format by
day_group.Merges with seed data by household and day group.
Checks that merged data matches seed row count and IDs.
Scales probabilities by ratio of persons to participants in each household to match
p_total.Uses regex pattern
^p_made_to select columns for scaling and checks.Validates group sums with
check_group_sum().Merges household weights and calculates weighted sums by client zone.
Merges predicted targets with input targets by client zone.
Checks that regional sum matches
p_total(not guaranteed at zone level).Scales client zone targets to match
p_totalexactly.Validates group sums after adjustment.
Sets column order for output table.
Returns updated targets as a data.table.
Error handling: stops if input tables are inconsistent or sums do not match.
TODO: Consider integerization logic for final output (currently controlled by
integerizeargument, but not implemented in this function).
See also
update_daypat_seed, check_group_sum
Other weighting pipeline:
aggregate_targets(),
calc_day_weights(),
calc_linked_trip_weights(),
calc_person_weights(),
calc_sample_plan_counts(),
calc_tour_weights(),
calc_trip_weights(),
create_ie_adjustment_data(),
create_target_update_table(),
format_income_bins(),
get_day_groups(),
get_income_broad(),
get_income_broad_xwalk(),
prepare_zone_groups(),
update_daypat_seed(),
update_income_broad_labels(),
update_rate_report(),
update_targets()