Skip to contents

Remove missing data for summary variables

Usage

hts_remove_missing_data(
  hts_data,
  variables_dt,
  summarize_var,
  ids = c("hh_id", "person_id", "day_id", "trip_id", "vehicle_id"),
  summarize_by = NULL,
  missing_values = c("Missing Response", "995"),
  not_imputable = -1
)

Arguments

hts_data

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

variables_dt

A variable list with descriptions and table locations of variables.

summarize_var

Variable to be summarized that has it's missing data removed.

ids

names of unique identifiers for each table in hts_data

summarize_by

Variable being summarized by that has it's missing data removed. Default is NULL.

missing_values

Missing values that will be removed. Defaults are 995 and 'Missing Response'.

not_imputable

Value meaning not_imputable that will be removed. Default is -1.

Value

Inputted list of datasets without missing values for specified variables.

Examples


require(data.table)
hts_remove_missing_data(
  hts_data = list(
    "hh" = hh,
    "person" = person,
    "day" = day,
    "trip" = trip,
    "vehicle" = vehicle
  ),
  variables_dt = variable_list,
  summarize_var = "speed_mph",
  summarize_by = "mode_type"
)
#> $hh
#>       hh_id sample_segment income_detailed income_followup  home_lon home_lat
#>    1:     1             13               7             995 -86.30631 38.48649
#>    2:     2             16               5             995 -85.72573 39.71972
#>    3:     3              2               9             995 -83.36336 39.12412
#>    4:     4              4               8             995 -98.43844 36.68569
#>    5:     5              1               8             995 -92.89289 34.96897
#>   ---                                                                        
#>  996:   996             10               9             995 -86.72673 34.93393
#>  997:   997             16               5             995 -84.30430 39.09610
#>  998:   998             13               2             995 -85.66567 35.24224
#>  999:   999              6               9             995 -98.75876 37.89089
#> 1000:  1000              2               5             995 -90.67067 36.41942
#>       home_county residence_type num_people num_trips hh_weight
#>    1:           1              4          0         0        54
#>    2:           3            995          4        21       478
#>    3:           3            995          2        17       760
#>    4:           3              1          1         0       754
#>    5:           3              2          1         4       839
#>   ---                                                          
#>  996:           1              5          2        18       118
#>  997:           3              4          3        11        14
#>  998:           1            995          2        15       546
#>  999:           2              4          1        16       745
#> 1000:           3              4          1        10       133
#> 
#> $person
#>       person_id ethnicity_1 ethnicity_2 ethnicity_3 ethnicity_4 ethnicity_997
#>    1:         1           0           1           1           0             1
#>    2:         2           1           0           0           1             1
#>    3:         3           0           0           0           0             0
#>    4:         4           0           0           0           0             0
#>    5:         5           0           1           1           0             1
#>   ---                                                                        
#> 2043:      2043           1           0           0           0             1
#> 2044:      2044           1           0           0           1             1
#> 2045:      2045           0           0           0           0             0
#> 2046:      2046           0           0           0           0             1
#> 2047:      2047           0           0           0           0             0
#>       ethnicity_999 race_1 race_2 race_3 race_4 race_5 race_997 race_999 hh_id
#>    1:             0      0      0      0      0      0        0        1   356
#>    2:             0      1      1      0      0      0        1        0   724
#>    3:             1      0      1      0      1      1        1        0   681
#>    4:             1      0      0      0      0      0        0        1   114
#>    5:             0      0      0      0      0      0        0        1   165
#>   ---                                                                         
#> 2043:             0      0      0      1      1      0        0        0   931
#> 2044:             0      0      0      0      0      0        0        1   667
#> 2045:             1      0      0      0      0      0        0        1   543
#> 2046:             0      0      0      0      0      0        0        1   749
#> 2047:             1      0      0      0      0      0        0        1   364
#>       age gender employment job_type education num_trips person_weight
#>    1:  10      2          1        1         6        12           229
#>    2:  11      2          3      995         2         0           128
#>    3:   7      2        995      995         3        10           888
#>    4:   2    999        995      995         6         8           350
#>    5:  10    995          2        1         4         4           825
#>   ---                                                                 
#> 2043:   7    995          1        1       995         8           116
#> 2044:   1    995          1        1       995        12           122
#> 2045:   3      1          1        5         3         0           494
#> 2046:  11      2          1        5         6        11           874
#> 2047:  11    995          5      995         3         0           393
#> 
#> $day
#>       day_id person_id delivery_2 delivery_3 delivery_4 delivery_5 delivery_6
#>    1:      1       820        995        995        995        995        995
#>    2:      2        24          0          0          0          0          0
#>    3:      3      1866          0          0          0          0          0
#>    4:      4      1915        995        995        995        995        995
#>    5:      5       415          0          0          0          1          0
#>   ---                                                                        
#> 4121:   4121      1321          0          1          0          1          0
#> 4122:   4122      1619          0          0          0          0          0
#> 4123:   4123       886        995        995        995        995        995
#> 4124:   4124       964          0          0          0          0          0
#> 4125:   4125      1684          0          0          0          0          0
#>       delivery_7 delivery_8 delivery_996 travel_date begin_day end_day hh_id
#>    1:        995        995          995  2023-05-28         1       1   642
#>    2:          0          0            1  2023-05-23         1       1    24
#>    3:          0          0            1  2023-05-25         1       1   888
#>    4:        995        995          995  2023-04-17         1       1   875
#>    5:          0          0            0  2023-05-26         1       1   976
#>   ---                                                                       
#> 4121:          0          0            0  2023-05-20         1       1   595
#> 4122:          0          0            1  2023-04-09         1       1    47
#> 4123:        995        995          995  2023-04-12       995     995   474
#> 4124:          0          0            1  2023-04-22         1       1   764
#> 4125:          0          0            1  2023-05-30         1       1   876
#>       num_trips day_weight
#>    1:         5        583
#>    2:         5        220
#>    3:         2         73
#>    4:         6         63
#>    5:         3        139
#>   ---                     
#> 4121:         1        755
#> 4122:         5        996
#> 4123:         5        818
#> 4124:         2        460
#> 4125:         5        762
#> 
#> $trip
#>        day_id trip_id  speed_mph distance_miles mode_type mode_1 mode_2
#>     1:      1    6848  0.3570582     0.07736261         8      6    995
#>     2:      1    6099  3.8030030     0.31691692         8     34    995
#>     3:      1   15759  9.2827577     0.16244826         1      1    995
#>     4:      1   13883 10.7289440    10.72894403        13      2     23
#>     5:      1    9240  1.3936891     0.47308002         2      2    995
#>    ---                                                                 
#> 15449:   4125    4505 16.3377147     3.23577517         8      6    995
#> 15450:   4125    7897 42.9297111    22.65734754         8      6    995
#> 15451:   4125     719  1.5648402     7.77203953         1      1    995
#> 15452:   4125   14260 10.5795319     1.76325532         8      7    995
#> 15453:   4125    4397  8.5320851     1.42201419         8     34    995
#>        num_travelers d_purpose_category hh_id person_id travel_date trip_weight
#>     1:             1                  7   642       820  2023-05-28         957
#>     2:             2                  7   642       820  2023-05-28         237
#>     3:             1                  9   642       820  2023-05-28         287
#>     4:             1                 11   642       820  2023-05-28         361
#>     5:             1                  1   642       820  2023-05-28         578
#>    ---                                                                         
#> 15449:             1                 12   876      1684  2023-05-30         999
#> 15450:             1                  2   876      1684  2023-05-30         167
#> 15451:             1                 12   876      1684  2023-05-30         954
#> 15452:             1                  2   876      1684  2023-05-30         841
#> 15453:             2                  7   876      1684  2023-05-30         977
#> 
#> $vehicle
#>       hh_id vehicle_id fuel_type hh_weight
#>    1:     1       1103         1        54
#>    2:     2        521         1       478
#>    3:     2       1356         1       478
#>    4:     3       1210         1       760
#>    5:     6       1394         1       987
#>   ---                                     
#> 1430:   998        520         1       546
#> 1431:   998       1141         1       546
#> 1432:   999        659         1       745
#> 1433:   999        108         1       745
#> 1434:  1000       1031         1       133
#>