Calculate trip weights for each person-trip
calc_trip_weights.RdCalculates trip weights for each person in each household, assigning weights from day weights and setting to zero for non-study days. Use to generate trip-level weights for weighting pipeline.
Arguments
- trips
data.table with required columns:
hh_id
— household ID person_id
— person ID day_id
— day ID trip_id
— trip ID linked_trip_id
— linked trip ID (optional) tour_id
— tour ID (optional) Additional columns as needed for trip diagnostics Rows: one per trip. Keys: (hh_id, person_id, day_id, trip_id). Modified by reference: no (returns copy).
- day_weights
data.table with required columns:
hh_idperson_idday_idday_groupday_weightRows: one per person-day. Keys: ( hh_id,person_id,day_id). Modified by reference: no (returns copy).
- settings
list. Pipeline settings object.
Value
data.table with columns:
hh_id
— household ID person_id
— person ID day_id
— day ID trip_id
— trip ID linked_trip_id
— linked trip ID tour_id
— tour ID day_group
— day group label trip_weight
— trip-level weight Additional columns as needed for diagnostics Rows: one per trip. Keys: (hh_id, person_id, day_id, trip_id).
Details
Adds linked_trip_id and tour_id columns if missing.
Merges trips with day weights to assign trip weights.
Sets trip weights to zero for non-study days.
Checks consistency with day weights.
Returns a copy; does not modify by reference.
See also
calc_day_weightsscripts/weighting/trip_weights.R
Other weighting pipeline:
aggregate_targets(),
calc_day_weights(),
calc_linked_trip_weights(),
calc_person_weights(),
calc_sample_plan_counts(),
calc_tour_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_daypat_targets(),
update_income_broad_labels(),
update_rate_report(),
update_targets()
Examples
## Not run:
trips <- data.table(hh_id = 1, person_id = 1, day_id = 1, trip_id = "TR1")
day_weights <- data.table(hh_id = 1, person_id = 1, day_id = 1, day_group = "weekday", day_weight = 1.2)
settings <- list()
calc_trip_weights(trips, day_weights, settings)
#> Error in get("weight_synthetic_trips", settings): object 'weight_synthetic_trips' not found
## End(Not run)