Skip to contents

Aggregates trip frequencies and weights by platform and trip type, then calculates trip rates. Use to assess trip rates and set adjustment bounds.

Usage

calculate_aggegrate_trip_rates(trips_types_complete, complete_days, settings)

Arguments

trips_types_complete

data.table with required columns:

  • diary_platform — diary platform code

  • day_group — day group label

  • trip_type — trip type label

  • trip_weight — trip weight value

  • Additional columns as needed for trip diagnostics and aggregation Rows: one per trip. Keys: (diary_platform, day_group, trip_type). Modified by reference: no (returns copy).

complete_days

data.table with required columns:

  • diary_platform — diary platform code

  • day_group — day group label

  • num_days — number of days

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

settings

list. Pipeline settings object.

Value

data.table with columns:

  • diary_platform — diary platform code

  • day_group — day group label

  • trip_type_freq — frequency count for each trip type

  • trip_type_weight — weighted count for each trip type

  • trip_type_sd — standard deviation for each trip type

  • trip_type_rate — trip rate for each trip type

  • trip_type_rate-sd — standard deviation of trip rate

  • trip_type_factor — adjustment factor for each trip type Additional columns as needed for diagnostics Rows: one per platform-day group-trip type. Keys: (diary_platform, day_group).

Details

  • Aggregates day weights by platform and day group.

  • Calculates frequency and weighted counts for each trip type.

  • Computes standard deviations and combines into a single table.

  • Fills missing combinations with zeros for diagnostics.

  • Calculates trip rates and reference rates for each type.

  • Returns a copy; does not modify by reference.

Settings

None.

See also

  • calc_trip_rate_factor

  • scripts/weighting/trip_rate_factors.R

Other trip rate modeling: calc_trip_rate_factor(), extract_trip_rate_factors(), prepare_trip_adj_model_dt(), rescale_trip_rate_factors()

Examples

## Not run:
library(data.table)
trips_types_complete <- data.table(
  diary_platform = "app",
  day_group = "weekday",
  trip_type = "auto",
  trip_weight = 1.2
)
complete_days <- data.table(
  diary_platform = "app",
  day_group = "weekday",
  num_days = 10,
  day_weight = 12
)
settings <- list()
calculate_aggegrate_trip_rates(trips_types_complete, complete_days, settings)
#> Index: <value_type>
#>    app_weekday trip_type value_type
#>         <char>    <char>     <char>
#> 1:           0       day  weight-sd
#> 2:         1.2      auto     weight
#> 3:          12       day     weight
#> 4:           0      auto         sd
#> 5:        <NA>      auto    rate-sd
#> 6:         0.1      auto       rate
#> 7:           1      auto       freq
#> 8:           1      auto     factor
## End(Not run)