Summarize a numeric variable
Usage
hts_summary_num(
prepped_dt,
summarize_var = NULL,
summarize_by = NULL,
weighted = TRUE,
se = FALSE,
wtname = NULL,
strataname = NULL
)
Arguments
- prepped_dt
A prepared dataset in data.table format with the variable to summarize, the variable to summarize by, and the weights, if used.
- summarize_var
Name of the variable to summarize. Default is NULL.
- summarize_by
Name of the variable to summarize the summarize_var by. Default is NULL.
- weighted
Whether the data is weighted. Default is TRUE.
- se
Whether to calculate standard error. Default is FALSE. Will be set to FALSE if weighted is FALSE.
- wtname
Name of the weight column to use. Default is NULL. Must be specified when weighted = TRUE.
- strataname
Name of strata name to bring in. Default is NULL.
Value
List of unweighted and weighted numeric summaries including count, min, max, mean, se, and median.
Examples
require(data.table)
require(stringr)
require(dplyr)
require(srvyr)
DT = hts_prep_variable(
summarize_var = "speed_mph",
variables_dt = variable_list,
data = list(
"hh" = hh,
"person" = person,
"day" = day,
"trip" = trip,
"vehicle" = vehicle
)
)$num
#> Warning: 378 outliers were removed based on the threshold of 0.975.
hts_summary_num(
prepped_dt = DT,
summarize_var = "speed_mph",
wtname = "trip_weight"
)
#> $unwtd
#> count min max mean median
#> 1: 14722 0 112.5371 12.27017 8.914392
#>
#> $wtd
#> count min max mean median
#> 1: 14722 0 112.5371 12.18441 8.877364
#>
#> $weight_name
#> [1] "trip_weight"
#>
DT = hts_prep_variable(
summarize_var = "speed_mph",
summarize_by = "age",
variables_dt = variable_list,
data = list(
"hh" = hh,
"person" = person,
"day" = day,
"trip" = trip,
"vehicle" = vehicle
)
)$num
#> Warning: 378 outliers were removed based on the threshold of 0.975.
hts_summary_num(
prepped_dt = DT,
summarize_var = "speed_mph",
summarize_by = "age",
wtname = "trip_weight"
)
#> $unwtd
#> age count min max mean median
#> 1: 1 1330 0.052703535 99.66345 12.77219 9.043035
#> 2: 2 1034 0.013607390 101.97575 11.79746 8.642971
#> 3: 3 1175 0.000000000 106.33820 11.80088 8.762973
#> 4: 4 1322 0.000000000 100.93678 12.17496 8.960005
#> 5: 5 1342 0.020070228 108.02176 11.98645 8.380280
#> 6: 6 1220 0.008117147 108.05151 11.61808 8.787320
#> 7: 7 1310 0.000000000 105.12236 12.13324 9.233571
#> 8: 8 1164 0.000000000 88.06935 12.65997 8.917070
#> 9: 9 1095 0.000000000 111.79519 12.08160 8.305877
#> 10: 10 1190 0.108733750 112.53715 12.67014 9.687523
#> 11: 11 1283 0.000000000 110.65782 12.52175 8.745631
#> 12: 12 1257 0.000000000 109.20438 12.91303 9.876124
#>
#> $wtd
#> age count min max mean median
#> 1: 1 1330 0.052703535 99.66345 12.45417 8.955092
#> 2: 2 1034 0.013607390 101.97575 11.86040 8.807183
#> 3: 3 1175 0.000000000 106.33820 11.63899 8.625382
#> 4: 4 1322 0.000000000 100.93678 12.17959 8.890321
#> 5: 5 1342 0.020070228 108.02176 11.50444 8.031314
#> 6: 6 1220 0.008117147 108.05151 11.48691 8.788419
#> 7: 7 1310 0.000000000 105.12236 12.57005 9.480196
#> 8: 8 1164 0.000000000 88.06935 12.72844 8.925704
#> 9: 9 1095 0.000000000 111.79519 11.78338 7.904890
#> 10: 10 1190 0.108733750 112.53715 12.82312 9.744795
#> 11: 11 1283 0.000000000 110.65782 12.22370 8.451265
#> 12: 12 1257 0.000000000 109.20438 12.83858 9.863703
#>
#> $weight_name
#> [1] "trip_weight"
#>