Skip to contents

Prepare datasets for trip rate calculations

Usage

hts_prep_triprate(
  summarize_by = NULL,
  variables_dt = variable_list,
  trip_name = "trip",
  day_name = "day",
  ids = c("hh_id", "person_id", "day_id", "trip_id", "vehicle_id"),
  wts = c("hh_weight", "person_weight", "day_weight", "trip_weight", "hh_weight"),
  remove_outliers = FALSE,
  threshold = 0.975,
  weighted = TRUE,
  hts_data = list(hh = hh, person = person, day = day, trip = trip, vehicle = vehicle)
)

Arguments

summarize_by

Name of the variable to summarize trip rates by. Default is NULL.

variables_dt

List of variable locations and descriptions in data.table format.

trip_name

Name of the trip dataset in hts_data.

day_name

Name of the day dataset in hts_data.

ids

name of unique identifier in each table in hts_data

wts

name of weight column in each table in hts_data

remove_outliers

Boolean whether or not to remove outliers from dataset. Default is TRUE.

threshold

Threshold to define outliers. Default is 0.975.

weighted

Whether the data is weighted. Default is TRUE.

hts_data

List containing household, person, day, trip, and vehicle datasets in data.table format.

Value

List of binned number of trips with key columns and summarize by variable, unbinned number of trips with key columns and summarize by variable, and a breakdown of outliers if removed.

Examples


require(data.table)
require(stringr)
hts_prep_triprate(
  variables_dt = variable_list,
  trip_name = "trip",
  day_name = "day",
  hts_data = list(
    "hh" = hh,
    "person" = person,
    "day" = day,
    "trip" = trip,
    "vehicle" = vehicle
  )
)
#> $num
#>       day_id person_id hh_id day_weight num_trips_wtd
#>    1:      1       820   642        583     4.1509434
#>    2:      2        24    24        220     3.5090909
#>    3:      3      1866   888         73     9.2465753
#>    4:      4      1915   875         63    30.0793651
#>    5:      5       415   976        139    13.2805755
#>   ---                                                
#> 4121:   4121      1321   595        755     0.6556291
#> 4122:   4122      1619    47        996     2.8945783
#> 4123:   4123       886   474        818     3.8581907
#> 4124:   4124       964   764        460     2.9608696
#> 4125:   4125      1684   876        762     5.1679790
#> 
#> $cat
#>       day_id person_id hh_id day_weight num_trips_wtd
#>    1:      1       820   642        583          0-13
#>    2:      2        24    24        220          0-13
#>    3:      3      1866   888         73          0-13
#>    4:      4      1915   875         63         26-39
#>    5:      5       415   976        139         13-26
#>   ---                                                
#> 4121:   4121      1321   595        755          0-13
#> 4122:   4122      1619    47        996          0-13
#> 4123:   4123       886   474        818          0-13
#> 4124:   4124       964   764        460          0-13
#> 4125:   4125      1684   876        762          0-13
#> 
hts_prep_triprate(
  summarize_by = "age",
  variables_dt = variable_list,
  trip_name = "trip",
  day_name = "day",
  hts_data = list(
    "hh" = hh,
    "person" = person,
    "day" = day,
    "trip" = trip,
    "vehicle" = vehicle
  )
)
#> $num
#>       hh_id person_id day_id day_weight person_weight age trip_count_wtd
#>    1:     2       425    388        613           130  12           1284
#>    2:     2       425   1320        593           130  12            233
#>    3:     2       892   1559        983           715   3           2326
#>    4:     2       973   1178        556            57   5           2293
#>    5:     2       973   3183        518            57   5           2406
#>   ---                                                                   
#> 4121:   999      1305   3055        463           836  10           2337
#> 4122:  1000       352   1165        245           883  10           1633
#> 4123:  1000       352   1222         10           883  10           1254
#> 4124:  1000       352   1663        751           883  10           1141
#> 4125:  1000       352   3389        969           883  10           1760
#>       num_trips_wtd
#>    1:     2.0946166
#>    2:     0.3929174
#>    3:     2.3662258
#>    4:     4.1241007
#>    5:     4.6447876
#>   ---              
#> 4121:     5.0475162
#> 4122:     6.6653061
#> 4123:   125.4000000
#> 4124:     1.5193076
#> 4125:     1.8163055
#> 
#> $cat
#>       hh_id person_id day_id day_weight person_weight age trip_count_wtd
#>    1:     2       425    388        613           130  12           1284
#>    2:     2       425   1320        593           130  12            233
#>    3:     2       892   1559        983           715   3           2326
#>    4:     2       973   1178        556            57   5           2293
#>    5:     2       973   3183        518            57   5           2406
#>   ---                                                                   
#> 4121:   999      1305   3055        463           836  10           2337
#> 4122:  1000       352   1165        245           883  10           1633
#> 4123:  1000       352   1222         10           883  10           1254
#> 4124:  1000       352   1663        751           883  10           1141
#> 4125:  1000       352   3389        969           883  10           1760
#>       num_trips_wtd
#>    1:          0-13
#>    2:          0-13
#>    3:          0-13
#>    4:          0-13
#>    5:          0-13
#>   ---              
#> 4121:          0-13
#> 4122:          0-13
#> 4123:    67 or more
#> 4124:          0-13
#> 4125:          0-13
#>