Skip to contents

Calculates linked trip weights for each person by averaging unlinked trip weights within linked trip groups. Use to generate linked trip weights for downstream analysis in travel survey expansion.

Usage

calc_linked_trip_weights(
  linked_trips,
  unlinked_trips,
  unlinked_trip_weights,
  day_weights,
  settings,
  ignore_checks = FALSE
)

Arguments

linked_trips

data.table with required columns:

  • linked_trip_id — unique linked trip identifier

  • hh_id — household ID

  • person_id — person ID

  • day_id — day ID

  • tour_id — tour identifier

  • day_group — day group label Rows: one per linked trip. Keys: (linked_trip_id). Modified by reference: no (returns copy).

unlinked_trips

data.table with required columns:

  • trip_id — unique trip identifier

  • linked_trip_id — linked trip identifier

  • tour_id — tour identifier Rows: one per trip. Keys: (trip_id). Modified by reference: no (returns copy).

unlinked_trip_weights

data.table with required columns:

  • trip_id — unique trip identifier

  • trip_weight — unlinked trip weight Rows: one per trip. Keys: (trip_id). Modified by reference: no (returns copy).

day_weights

data.table with required columns:

  • day_id — day ID

  • day_weight — day-level weight Rows: one per day. Keys: (day_id). Modified by reference: no (returns copy).

settings

list. Pipeline settings object. Not used directly.

ignore_checks

logical(1). If TRUE, skips consistency checks. Default: FALSE.

Value

data.table with columns:

  • hh_id

  • person_id

  • day_id

  • linked_trip_id

  • tour_id

  • day_group

  • linked_trip_weight Rows: one per linked trip. Keys: (linked_trip_id).

Details

  • Joins linked trip IDs to unlinked trip weights using trip_id.

  • Averages unlinked trip weights by linked_trip_id, hh_id, person_id, day_id, tour_id, and day_group.

  • Checks consistency with day weights unless ignore_checks is TRUE.

  • Returns a copy; does not modify by reference.

Settings

None.

Examples

## Not run:
library(data.table)
linked_trips <- data.table(
  linked_trip_id = "L1",
  hh_id = 1L,
  person_id = 1L,
  day_id = 1L,
  tour_id = "T1",
  day_group = "weekday"
)
unlinked_trips <- data.table(
  trip_id = "T1",
  linked_trip_id = "L1",
  tour_id = "T1"
)
unlinked_trip_weights <- data.table(
  trip_id = "T1",
  trip_weight = 1.5
)
day_weights <- data.table(
  day_id = 1L,
  day_weight = 1.5
)
settings <- list()
calc_linked_trip_weights(
  linked_trips,
  unlinked_trips,
  unlinked_trip_weights,
  day_weights,
  settings
)
#> Error in eval(bysub, x, parent.frame()): object 'hh_id' not found
## End(Not run)