2017_2021

library(data.table)
library(DT)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.1.3
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:data.table':
## 
##     between, first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
setwd("C:/Users/s-das/OneDrive - Texas A&M Transportation Institute/Desktop/SD_Datasets/Crash_Data/TX/2017_2021")
dat1= fread("2017_2021_LimitedCat.csv")
dat1= dat1[, -c(1, 7, 20)]

dat1$Nbr_Of_Lane =as.factor(dat1$Nbr_Of_Lane)
dat1$Cnty_ID =as.factor(dat1$Cnty_ID)
dat1$Crash_Speed_Limit =as.factor(dat1$Crash_Speed_Limit)


library(summarytools)
## Warning: package 'summarytools' was built under R version 4.1.3
dfSummary(dat1, style='grid', plain.ascii = FALSE, graph.col = FALSE)
## ### Data Frame Summary  
## #### dat1  
## **Dimensions:** 2753345 x 38  
## **Duplicates:** 0  
## 
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | No | Variable             | Stats / Values                  | Freqs (% of Valid)      | Valid    | Missing  |
## +====+======================+=================================+=========================+==========+==========+
## | 1  | TTI_ID1\             | 1\. TX_2017_1.6e+07\            | 1 (  0.0%)\             | 2753345\ | 0\       |
## |    | [character]          | 2\. TX_2017_14572044\           | 1 (  0.0%)\             | (100.0%) | (0.0%)   |
## |    |                      | 3\. TX_2017_14883282\           | 1 (  0.0%)\             |          |          |
## |    |                      | 4\. TX_2017_14965664\           | 1 (  0.0%)\             |          |          |
## |    |                      | 5\. TX_2017_14965900\           | 1 (  0.0%)\             |          |          |
## |    |                      | 6\. TX_2017_14992432\           | 1 (  0.0%)\             |          |          |
## |    |                      | 7\. TX_2017_15140309\           | 1 (  0.0%)\             |          |          |
## |    |                      | 8\. TX_2017_15318911\           | 1 (  0.0%)\             |          |          |
## |    |                      | 9\. TX_2017_15427755\           | 1 (  0.0%)\             |          |          |
## |    |                      | 10\. TX_2017_15506552\          | 1 (  0.0%)\             |          |          |
## |    |                      | [ 2753335 others ]              | 2753335 (100.0%)        |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 2  | Year\                | Mean (sd) : 2019 (1.4)\         | 2017 : 538739 (19.6%)\  | 2753345\ | 0\       |
## |    | [integer]            | min < med < max:\               | 2018 : 626514 (22.8%)\  | (100.0%) | (0.0%)   |
## |    |                      | 2017 < 2019 < 2021\             | 2019 : 560835 (20.4%)\  |          |          |
## |    |                      | IQR (CV) : 2 (0)                | 2020 : 475132 (17.3%)\  |          |          |
## |    |                      |                                 | 2021 : 552125 (20.1%)   |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 3  | Crash_Date\          | 1\. 12/07/2018\                 | 3045 ( 0.1%)\           | 2753345\ | 0\       |
## |    | [character]          | 2\. 05/04/2018\                 | 2550 ( 0.1%)\           | (100.0%) | (0.0%)   |
## |    |                      | 3\. 02/11/2021\                 | 2532 ( 0.1%)\           |          |          |
## |    |                      | 4\. 12/20/2019\                 | 2518 ( 0.1%)\           |          |          |
## |    |                      | 5\. 10/31/2018\                 | 2482 ( 0.1%)\           |          |          |
## |    |                      | 6\. 11/16/2018\                 | 2463 ( 0.1%)\           |          |          |
## |    |                      | 7\. 10/19/2018\                 | 2434 ( 0.1%)\           |          |          |
## |    |                      | 8\. 01/16/2018\                 | 2356 ( 0.1%)\           |          |          |
## |    |                      | 9\. 12/21/2018\                 | 2355 ( 0.1%)\           |          |          |
## |    |                      | 10\. 12/06/2018\                | 2316 ( 0.1%)\           |          |          |
## |    |                      | [ 1816 others ]                 | 2728294 (99.1%)         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 4  | Crash_Time\          | 1\. 05:00 PM\                   | 14779 ( 0.5%)\          | 2753345\ | 0\       |
## |    | [character]          | 2\. 04:00 PM\                   | 14224 ( 0.5%)\          | (100.0%) | (0.0%)   |
## |    |                      | 3\. 06:00 PM\                   | 14089 ( 0.5%)\          |          |          |
## |    |                      | 4\. 03:00 PM\                   | 12785 ( 0.5%)\          |          |          |
## |    |                      | 5\. 05:30 PM\                   | 12414 ( 0.5%)\          |          |          |
## |    |                      | 6\. 08:00 AM\                   | 12062 ( 0.4%)\          |          |          |
## |    |                      | 7\. 04:30 PM\                   | 11547 ( 0.4%)\          |          |          |
## |    |                      | 8\. 02:00 PM\                   | 11403 ( 0.4%)\          |          |          |
## |    |                      | 9\. 01:00 PM\                   | 11346 ( 0.4%)\          |          |          |
## |    |                      | 10\. 03:30 PM\                  | 10814 ( 0.4%)\          |          |          |
## |    |                      | [ 1430 others ]                 | 2627882 (95.4%)         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 5  | Crash_Speed_Limit\   | 1\. -1\                         | 122437 ( 4.4%)\         | 2753345\ | 0\       |
## |    | [factor]             | 2\. 5\                          | 11358 ( 0.4%)\          | (100.0%) | (0.0%)   |
## |    |                      | 3\. 6\                          | 27 ( 0.0%)\             |          |          |
## |    |                      | 4\. 7\                          | 12 ( 0.0%)\             |          |          |
## |    |                      | 5\. 8\                          | 2 ( 0.0%)\              |          |          |
## |    |                      | 6\. 10\                         | 8069 ( 0.3%)\           |          |          |
## |    |                      | 7\. 11\                         | 1 ( 0.0%)\              |          |          |
## |    |                      | 8\. 12\                         | 2 ( 0.0%)\              |          |          |
## |    |                      | 9\. 13\                         | 2 ( 0.0%)\              |          |          |
## |    |                      | 10\. 14\                        | 17 ( 0.0%)\             |          |          |
## |    |                      | [ 52 others ]                   | 2611418 (94.8%)         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 6  | Wthr_Cond_ID\        | 1\. Blowing sand/snow\          | 898 ( 0.0%)\            | 2753345\ | 0\       |
## |    | [character]          | 2\. Clear\                      | 2035950 (73.9%)\        | (100.0%) | (0.0%)   |
## |    |                      | 3\. Cloudy\                     | 419237 (15.2%)\         |          |          |
## |    |                      | 4\. Fog\                        | 15332 ( 0.6%)\          |          |          |
## |    |                      | 5\. Other (explain in narrati\  | 1627 ( 0.1%)\           |          |          |
## |    |                      | 6\. Rain\                       | 250632 ( 9.1%)\         |          |          |
## |    |                      | 7\. Severe crosswinds\          | 2221 ( 0.1%)\           |          |          |
## |    |                      | 8\. Sleet/hail\                 | 5886 ( 0.2%)\           |          |          |
## |    |                      | 9\. Snow\                       | 6506 ( 0.2%)\           |          |          |
## |    |                      | 10\. Unknown                    | 15056 ( 0.5%)           |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 7  | Light_Cond_ID\       | 1\. Dark, lighted\              | 523981 (19.0%)\         | 2753345\ | 0\       |
## |    | [character]          | 2\. Dark, not lighted\          | 266768 ( 9.7%)\         | (100.0%) | (0.0%)   |
## |    |                      | 3\. Dark, unknown lighting\     | 23247 ( 0.8%)\          |          |          |
## |    |                      | 4\. Dawn\                       | 28894 ( 1.0%)\          |          |          |
## |    |                      | 5\. Daylight\                   | 1863648 (67.7%)\        |          |          |
## |    |                      | 6\. Dusk\                       | 31940 ( 1.2%)\          |          |          |
## |    |                      | 7\. Other (explain in narrati\  | 2213 ( 0.1%)\           |          |          |
## |    |                      | 8\. Unknown                     | 12654 ( 0.5%)           |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 8  | Road_Algn_ID\        | 1\. Curve, grade\               | 62054 ( 2.3%)\          | 2753345\ | 0\       |
## |    | [character]          | 2\. Curve, hillcrest\           | 13183 ( 0.5%)\          | (100.0%) | (0.0%)   |
## |    |                      | 3\. Curve, level\               | 141316 ( 5.1%)\         |          |          |
## |    |                      | 4\. Other (explain in narrati\  | 15465 ( 0.6%)\          |          |          |
## |    |                      | 5\. Straight, grade\            | 194777 ( 7.1%)\         |          |          |
## |    |                      | 6\. Straight, hillcrest\        | 54337 ( 2.0%)\          |          |          |
## |    |                      | 7\. Straight, level\            | 2266401 (82.3%)\        |          |          |
## |    |                      | 8\. Unknown                     | 5812 ( 0.2%)            |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 9  | Road_Type_ID\        | 1\. 2 lane, 2 way\              | 257945 (18.5%)\         | 1391326\ | 1362019\ |
## |    | [character]          | 2\. 4 or more lanes, divided\   | 846880 (60.9%)\         | (50.5%)  | (49.5%)  |
## |    |                      | 3\. 4 or more lanes, undivide\  | 279011 (20.1%)\         |          |          |
## |    |                      | 4\. Other road type             | 7490 ( 0.5%)            |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 10 | Surf_Cond_ID\        | 1\. Dry\                        | 2340411 (85.0%)\        | 2753345\ | 0\       |
## |    | [character]          | 2\. Ice\                        | 14931 ( 0.5%)\          | (100.0%) | (0.0%)   |
## |    |                      | 3\. Other (explain in narrati\  | 4165 ( 0.2%)\           |          |          |
## |    |                      | 4\. Sand, mud, dirt\            | 7166 ( 0.3%)\           |          |          |
## |    |                      | 5\. Slush\                      | 1591 ( 0.1%)\           |          |          |
## |    |                      | 6\. Snow\                       | 3199 ( 0.1%)\           |          |          |
## |    |                      | 7\. Standing water\             | 15041 ( 0.5%)\          |          |          |
## |    |                      | 8\. Unknown\                    | 13766 ( 0.5%)\          |          |          |
## |    |                      | 9\. Wet                         | 353075 (12.8%)          |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 11 | Traffic_Cntl_ID\     | 1\. Marked lanes\               | 1120775 (40.7%)\        | 2753345\ | 0\       |
## |    | [character]          | 2\. None\                       | 494983 (18.0%)\         | (100.0%) | (0.0%)   |
## |    |                      | 3\. Signal light\               | 479698 (17.4%)\         |          |          |
## |    |                      | 4\. Stop sign\                  | 289482 (10.5%)\         |          |          |
## |    |                      | 5\. Center stripe/divider\      | 183274 ( 6.7%)\         |          |          |
## |    |                      | 6\. Other (explain in narrati\  | 48847 ( 1.8%)\          |          |          |
## |    |                      | 7\. Yield sign\                 | 44508 ( 1.6%)\          |          |          |
## |    |                      | 8\. No passing zone\            | 37853 ( 1.4%)\          |          |          |
## |    |                      | 9\. Signal light with red lig\  | 9827 ( 0.4%)\           |          |          |
## |    |                      | 10\. Warning sign\              | 9111 ( 0.3%)\           |          |          |
## |    |                      | [ 8 others ]                    | 34987 ( 1.3%)           |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 12 | Intrsct_Relat_ID\    | 1\. Driveway access\            | 256954 ( 9.3%)\         | 2753337\ | 8\       |
## |    | [character]          | 2\. Intersection\               | 613164 (22.3%)\         | (100.0%) | (0.0%)   |
## |    |                      | 3\. Intersection related\       | 440737 (16.0%)\         |          |          |
## |    |                      | 4\. Non intersection            | 1442482 (52.4%)         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 13 | FHE_Collsn_ID\       | 1\. Omv vehicle going straigh\  | 635570 (23.1%)\         | 2753345\ | 0\       |
## |    | [character]          | 2\. Sd both going straight-re\  | 388245 (14.1%)\         | (100.0%) | (0.0%)   |
## |    |                      | 3\. Sd one straight-one stopp\  | 357222 (13.0%)\         |          |          |
## |    |                      | 4\. Angle - both going straig\  | 342412 (12.4%)\         |          |          |
## |    |                      | 5\. Sd both going straight-si\  | 278128 (10.1%)\         |          |          |
## |    |                      | 6\. Od one straight-one left \  | 192260 ( 7.0%)\         |          |          |
## |    |                      | 7\. Angle - one straight-one \  | 128845 ( 4.7%)\         |          |          |
## |    |                      | 8\. Sd one straight-one left \  | 61986 ( 2.3%)\          |          |          |
## |    |                      | 9\. Angle - one straight-one \  | 58591 ( 2.1%)\          |          |          |
## |    |                      | 10\. Sd one straight-one right\ | 39352 ( 1.4%)\          |          |          |
## |    |                      | [ 32 others ]                   | 270734 ( 9.8%)          |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 14 | Othr_Factr_ID\       | 1\. Not applicable\             | 1152511 (41.9%)\        | 2753343\ | 2\       |
## |    | [character]          | 2\. Attention diverted from d\  | 294700 (10.7%)\         | (100.0%) | (0.0%)   |
## |    |                      | 3\. Slowing/stopping-for traf\  | 200999 ( 7.3%)\         |          |          |
## |    |                      | 4\. Vehicle changing lanes\     | 186095 ( 6.8%)\         |          |          |
## |    |                      | 5\. Slowing/stopping - for of\  | 184318 ( 6.7%)\         |          |          |
## |    |                      | 6\. One vehicle leaving drive\  | 161446 ( 5.9%)\         |          |          |
## |    |                      | 7\. Construction - within pos\  | 108910 ( 4.0%)\         |          |          |
## |    |                      | 8\. Lost control or skidded (\  | 79874 ( 2.9%)\          |          |          |
## |    |                      | 9\. One vehicle entering driv\  | 76746 ( 2.8%)\          |          |          |
## |    |                      | 10\. Slowing/stopping-to make \ | 37708 ( 1.4%)\          |          |          |
## |    |                      | [ 43 others ]                   | 270036 ( 9.8%)          |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 15 | Road_Part_Adj_ID\    | 1\. Connector/flyover\          | 10336 ( 0.4%)\          | 2489586\ | 263759\  |
## |    | [character]          | 2\. Entrance/on ramp\           | 23182 ( 0.9%)\          | (90.4%)  | (9.6%)   |
## |    |                      | 3\. Exit/off ramp\              | 30534 ( 1.2%)\          |          |          |
## |    |                      | 4\. Main/proper lane\           | 2374927 (95.4%)\        |          |          |
## |    |                      | 5\. Other (explain in narrati   | 50607 ( 2.0%)           |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 16 | Cnty_ID\             | 1\. 1\                          | 3929 ( 0.1%)\           | 2753345\ | 0\       |
## |    | [factor]             | 2\. 2\                          | 1654 ( 0.1%)\           | (100.0%) | (0.0%)   |
## |    |                      | 3\. 3\                          | 8915 ( 0.3%)\           |          |          |
## |    |                      | 4\. 4\                          | 1603 ( 0.1%)\           |          |          |
## |    |                      | 5\. 5\                          | 759 ( 0.0%)\            |          |          |
## |    |                      | 6\. 6\                          | 249 ( 0.0%)\            |          |          |
## |    |                      | 7\. 7\                          | 4492 ( 0.2%)\           |          |          |
## |    |                      | 8\. 8\                          | 3058 ( 0.1%)\           |          |          |
## |    |                      | 9\. 9\                          | 614 ( 0.0%)\            |          |          |
## |    |                      | 10\. 10\                        | 1446 ( 0.1%)\           |          |          |
## |    |                      | [ 244 others ]                  | 2726626 (99.0%)         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 17 | City_ID\             | 1\. Houston\                    | 330575 (13.7%)\         | 2406391\ | 346954\  |
## |    | [character]          | 2\. San antonio\                | 210356 ( 8.7%)\         | (87.4%)  | (12.6%)  |
## |    |                      | 3\. Dallas\                     | 171519 ( 7.1%)\         |          |          |
## |    |                      | 4\. El paso\                    | 81731 ( 3.4%)\          |          |          |
## |    |                      | 5\. Fort worth\                 | 78382 ( 3.3%)\          |          |          |
## |    |                      | 6\. Rural harris county\        | 74928 ( 3.1%)\          |          |          |
## |    |                      | 7\. Austin\                     | 71898 ( 3.0%)\          |          |          |
## |    |                      | 8\. Corpus christi\             | 41153 ( 1.7%)\          |          |          |
## |    |                      | 9\. Lubbock\                    | 34976 ( 1.5%)\          |          |          |
## |    |                      | 10\. Arlington\                 | 33935 ( 1.4%)\          |          |          |
## |    |                      | [ 1565 others ]                 | 1276938 (53.1%)         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 18 | Latitude\            | Mean (sd) : 30.8 (1.9)\         | 1010078 distinct values | 2582754\ | 170591\  |
## |    | [numeric]            | min < med < max:\               |                         | (93.8%)  | (6.2%)   |
## |    |                      | 25.9 < 30.3 < 36.5\             |                         |          |          |
## |    |                      | IQR (CV) : 3 (0.1)              |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 19 | Longitude\           | Mean (sd) : -97.4 (2.5)\        | 998471 distinct values  | 2582754\ | 170591\  |
## |    | [numeric]            | min < med < max:\               |                         | (93.8%)  | (6.2%)   |
## |    |                      | -106.6 < -96.9 < -93.5\         |                         |          |          |
## |    |                      | IQR (CV) : 2.7 (0)              |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 20 | Day_of_Week\         | 1\. FRI\                        | 463470 (16.8%)\         | 2753345\ | 0\       |
## |    | [character]          | 2\. MON\                        | 385599 (14.0%)\         | (100.0%) | (0.0%)   |
## |    |                      | 3\. SAT\                        | 379677 (13.8%)\         |          |          |
## |    |                      | 4\. SUN\                        | 313892 (11.4%)\         |          |          |
## |    |                      | 5\. THU\                        | 407692 (14.8%)\         |          |          |
## |    |                      | 6\. TUE\                        | 397889 (14.5%)\         |          |          |
## |    |                      | 7\. WED                         | 405126 (14.7%)          |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 21 | Hwy_Dsgn_Lane_ID\    | 1\. Boulevard\                  | 210118 (15.2%)\         | 1385904\ | 1367441\ |
## |    | [character]          | 2\. Expressway\                 | 39854 ( 2.9%)\          | (50.3%)  | (49.7%)  |
## |    |                      | 3\. Freeway\                    | 598976 (43.2%)\         |          |          |
## |    |                      | 4\. One-way\                    | 12803 ( 0.9%)\          |          |          |
## |    |                      | 5\. One-way pair\               | 12842 ( 0.9%)\          |          |          |
## |    |                      | 6\. Two-way                     | 511311 (36.9%)          |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 22 | Crash_Sev_ID\        | 1\. Fatal\                      | 17584 ( 0.6%)\          | 2753345\ | 0\       |
## |    | [character]          | 2\. Incapacitating injury\      | 67555 ( 2.5%)\          | (100.0%) | (0.0%)   |
## |    |                      | 3\. Non-incapacitating\         | 275187 (10.0%)\         |          |          |
## |    |                      | 4\. Not injured\                | 1783164 (64.8%)\        |          |          |
## |    |                      | 5\. Possible injury\            | 477726 (17.4%)\         |          |          |
## |    |                      | 6\. Unknown                     | 132129 ( 4.8%)          |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 23 | Pop_Group_ID\        | 1\. 10,000 - 24,999 pop\        | 172671 ( 6.3%)\         | 2746000\ | 7345\    |
## |    | [character]          | 2\. 100,000 - 249,999 pop.\     | 373522 (13.6%)\         | (99.7%)  | (0.3%)   |
## |    |                      | 3\. 2,500 - 4,999 pop\          | 44132 ( 1.6%)\          |          |          |
## |    |                      | 4\. 25,000 - 49,999 pop\        | 158797 ( 5.8%)\         |          |          |
## |    |                      | 5\. 250,000 pop. And over\      | 1063168 (38.7%)\        |          |          |
## |    |                      | 6\. 5,000 - 9,999 pop\          | 80515 ( 2.9%)\          |          |          |
## |    |                      | 7\. 50,000 - 99,999 pop\        | 210244 ( 7.7%)\         |          |          |
## |    |                      | 8\. Rural\                      | 603129 (22.0%)\         |          |          |
## |    |                      | 9\. Town under 2,499 pop.       | 39822 ( 1.5%)           |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 24 | Nbr_Of_Lane\         | 1\. 1\                          | 60 ( 0.0%)\             | 1386387\ | 1366958\ |
## |    | [factor]             | 2\. 2\                          | 244114 (17.6%)\         | (50.4%)  | (49.6%)  |
## |    |                      | 3\. 3\                          | 15820 ( 1.1%)\          |          |          |
## |    |                      | 4\. 4\                          | 544220 (39.3%)\         |          |          |
## |    |                      | 5\. 5\                          | 18535 ( 1.3%)\          |          |          |
## |    |                      | 6\. 6\                          | 330074 (23.8%)\         |          |          |
## |    |                      | 7\. 7\                          | 14047 ( 1.0%)\          |          |          |
## |    |                      | 8\. 8\                          | 154163 (11.1%)\         |          |          |
## |    |                      | 9\. 9\                          | 11218 ( 0.8%)\          |          |          |
## |    |                      | 10\. 10\                        | 44349 ( 3.2%)\          |          |          |
## |    |                      | [ 4 others ]                    | 9787 ( 0.7%)            |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 25 | Surf_Type_ID\        | 1\. High type composite\        | 156153 (12.6%)\         | 1235740\ | 1517605\ |
## |    | [character]          | 2\. High type flexible\         | 582605 (47.1%)\         | (44.9%)  | (55.1%)  |
## |    |                      | 3\. High type rigid\            | 254629 (20.6%)\         |          |          |
## |    |                      | 4\. Intermediate type mixed\    | 16733 ( 1.4%)\          |          |          |
## |    |                      | 5\. Low type bituminous surfa\  | 96415 ( 7.8%)\          |          |          |
## |    |                      | 6\. Road is unpaved             | 129205 (10.5%)          |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 26 | Rural_Urban_Type_ID\ | Mean (sd) : 3.1 (1.2)\          | 1 : 266364 (19.1%)\     | 1391326\ | 1362019\ |
## |    | [integer]            | min < med < max:\               | 2 : 121546 ( 8.7%)\     | (50.5%)  | (49.5%)  |
## |    |                      | 1 < 4 < 4\                      | 3 : 169311 (12.2%)\     |          |          |
## |    |                      | IQR (CV) : 2 (0.4)              | 4 : 834105 (60.0%)      |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 27 | Func_Sys_ID\         | 1\. Urban prin arterial (othe\  | 253301 (23.3%)\         | 1085902\ | 1667443\ |
## |    | [character]          | 2\. Urban prin arterial (ih)\   | 229196 (21.1%)\         | (39.4%)  | (60.6%)  |
## |    |                      | 3\. Rural interstate\           | 208502 (19.2%)\         |          |          |
## |    |                      | 4\. Rural prin arterial\        | 117331 (10.8%)\         |          |          |
## |    |                      | 5\. Urban prin arterial (othe\  | 117201 (10.8%)\         |          |          |
## |    |                      | 6\. Urban minor arterial\       | 60646 ( 5.6%)\          |          |          |
## |    |                      | 7\. Rural major coll\           | 40716 ( 3.7%)\          |          |          |
## |    |                      | 8\. Rural minor arterial\       | 34761 ( 3.2%)\          |          |          |
## |    |                      | 9\. Urban collector\            | 19880 ( 1.8%)\          |          |          |
## |    |                      | 10\. Rural minor coll\          | 4315 ( 0.4%)\           |          |          |
## |    |                      | [ 2 others ]                    | 53 ( 0.0%)              |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 28 | Adt_Adj_Curnt_Amt\   | Mean (sd) : 65217 (70626.6)\    | 19105 distinct values   | 1385884\ | 1367461\ |
## |    | [integer]            | min < med < max:\               |                         | (50.3%)  | (49.7%)  |
## |    |                      | 6 < 32639 < 341309\             |                         |          |          |
## |    |                      | IQR (CV) : 90340 (1.1)          |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 29 | Adt_Curnt_Amt\       | Mean (sd) : 65217 (70626.6)\    | 19105 distinct values   | 1385884\ | 1367461\ |
## |    | [integer]            | min < med < max:\               |                         | (50.3%)  | (49.7%)  |
## |    |                      | 6 < 32639 < 341309\             |                         |          |          |
## |    |                      | IQR (CV) : 90340 (1.1)          |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 30 | Pct_Single_Trk_Adt\  | Mean (sd) : 3.6 (2.1)\          | 319 distinct values     | 1385884\ | 1367461\ |
## |    | [numeric]            | min < med < max:\               |                         | (50.3%)  | (49.7%)  |
## |    |                      | 0 < 3.1 < 41.9\                 |                         |          |          |
## |    |                      | IQR (CV) : 2 (0.6)              |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 31 | Tot_Injry_Cnt\       | Mean (sd) : 0.4 (0.8)\          | 37 distinct values      | 2753345\ | 0\       |
## |    | [integer]            | min < med < max:\               |                         | (100.0%) | (0.0%)   |
## |    |                      | 0 < 0 < 86\                     |                         |          |          |
## |    |                      | IQR (CV) : 1 (1.9)              |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 32 | Death_Cnt\           | 1\. *\                          | 1 ( 0.0%)\              | 2753345\ | 0\       |
## |    | [character]          | 2\. 0\                          | 2735761 (99.4%)\        | (100.0%) | (0.0%)   |
## |    |                      | 3\. 1\                          | 16161 ( 0.6%)\          |          |          |
## |    |                      | 4\. 10\                         | 1 ( 0.0%)\              |          |          |
## |    |                      | 5\. 2\                          | 1151 ( 0.0%)\           |          |          |
## |    |                      | 6\. 3\                          | 196 ( 0.0%)\            |          |          |
## |    |                      | 7\. 4\                          | 49 ( 0.0%)\             |          |          |
## |    |                      | 8\. 5\                          | 19 ( 0.0%)\             |          |          |
## |    |                      | 9\. 6\                          | 4 ( 0.0%)\              |          |          |
## |    |                      | 10\. 7\                         | 1 ( 0.0%)\              |          |          |
## |    |                      | 11\. 8                          | 1 ( 0.0%)               |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 33 | Trk_Aadt_Pct\        | Mean (sd) : 10.3 (8.7)\         | 672 distinct values     | 1385884\ | 1367461\ |
## |    | [numeric]            | min < med < max:\               |                         | (50.3%)  | (49.7%)  |
## |    |                      | 0 < 7.5 < 99.9\                 |                         |          |          |
## |    |                      | IQR (CV) : 7.8 (0.8)            |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 34 | Median_Width\        | Mean (sd) : 17.5 (30.4)\        | 180 distinct values     | 1385885\ | 1367460\ |
## |    | [integer]            | min < med < max:\               |                         | (50.3%)  | (49.7%)  |
## |    |                      | 0 < 4 < 770\                    |                         |          |          |
## |    |                      | IQR (CV) : 27 (1.7)             |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 35 | Shldr_Width_Right\   | Mean (sd) : 12.3 (8.8)\         | 42 distinct values      | 1385795\ | 1367550\ |
## |    | [integer]            | min < med < max:\               |                         | (50.3%)  | (49.7%)  |
## |    |                      | 0 < 13 < 53\                    |                         |          |          |
## |    |                      | IQR (CV) : 16 (0.7)             |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 36 | Shldr_Width_Left\    | Mean (sd) : 9.2 (7.9)\          | 47 distinct values      | 1385885\ | 1367460\ |
## |    | [integer]            | min < med < max:\               |                         | (50.3%)  | (49.7%)  |
## |    |                      | 0 < 8 < 60\                     |                         |          |          |
## |    |                      | IQR (CV) : 12 (0.9)             |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 37 | Roadbed_Width\       | Mean (sd) : 84.6 (37.6)\        | 200 distinct values     | 1385885\ | 1367460\ |
## |    | [integer]            | min < med < max:\               |                         | (50.3%)  | (49.7%)  |
## |    |                      | 14 < 80 < 318\                  |                         |          |          |
## |    |                      | IQR (CV) : 52 (0.4)             |                         |          |          |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
## | 38 | Onsys_Fl\            | All NA's                        |                         | 0\       | 2753345\ |
## |    | [logical]            |                                 |                         | (0.0%)   | (100.0%) |
## +----+----------------------+---------------------------------+-------------------------+----------+----------+
library(compareGroups)
## Warning: package 'compareGroups' was built under R version 4.1.3
res <- compareGroups(Year ~ Light_Cond_ID + Wthr_Cond_ID + Road_Algn_ID + Crash_Sev_ID+
                       Othr_Factr_ID+ FHE_Collsn_ID+ Intrsct_Relat_ID+ Surf_Type_ID+
                       Nbr_Of_Lane+Traffic_Cntl_ID,
                     data = dat1)
## Warning in compareGroups.fit(X = X, y = y, include.label = include.label, :
## Variables 'Othr_Factr_ID', 'FHE_Collsn_ID', 'Nbr_Of_Lane', 'Traffic_Cntl_ID'
## have been removed since some errors occurred
createTable(res)
## 
## --------Summary descriptives table by 'Year'---------
## 
## ____________________________________________________________________________________________________________________________ 
##                                              2017           2018           2019           2020           2021      p.overall 
##                                            N=538739       N=626514       N=560835       N=475132       N=552125              
## ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 
## Light_Cond_ID:                                                                                                       0.000   
##     Dark, lighted                       100087 (18.6%) 116452 (18.6%) 104567 (18.6%) 93889 (19.8%)  108986 (19.7%)           
##     Dark, not lighted                   52890 (9.82%)  58063 (9.27%)  53139 (9.47%)  49339 (10.4%)  53337 (9.66%)            
##     Dark, unknown lighting               3763 (0.70%)   4985 (0.80%)   4680 (0.83%)   4381 (0.92%)   5438 (0.98%)            
##     Dawn                                 5724 (1.06%)   6405 (1.02%)   6229 (1.11%)   4928 (1.04%)   5608 (1.02%)            
##     Daylight                            367798 (68.3%) 428646 (68.4%) 383083 (68.3%) 314308 (66.2%) 369813 (67.0%)           
##     Dusk                                 6212 (1.15%)   7244 (1.16%)   6334 (1.13%)   5912 (1.24%)   6238 (1.13%)            
##     Other (explain in narrative)         361 (0.07%)    638 (0.10%)    435 (0.08%)    432 (0.09%)    347 (0.06%)             
##     Unknown                              1904 (0.35%)   4081 (0.65%)   2368 (0.42%)   1943 (0.41%)   2358 (0.43%)            
## Wthr_Cond_ID:                                                                                                        0.000   
##     Blowing sand/snow                    169 (0.03%)    219 (0.03%)    193 (0.03%)     81 (0.02%)    236 (0.04%)             
##     Clear                               402642 (74.7%) 450293 (71.9%) 413101 (73.7%) 352408 (74.2%) 417506 (75.6%)           
##     Cloudy                              83805 (15.6%)  102494 (16.4%) 88503 (15.8%)  66645 (14.0%)  77790 (14.1%)            
##     Fog                                  2920 (0.54%)   3011 (0.48%)   3606 (0.64%)   2664 (0.56%)   3131 (0.57%)            
##     Other (explain in narrative)         234 (0.04%)    397 (0.06%)    291 (0.05%)    261 (0.05%)    444 (0.08%)             
##     Rain                                44616 (8.28%)  62865 (10.0%)  50815 (9.06%)  48248 (10.2%)  44088 (7.99%)            
##     Severe crosswinds                    259 (0.05%)    270 (0.04%)    614 (0.11%)    571 (0.12%)    507 (0.09%)             
##     Sleet/hail                           728 (0.14%)    1734 (0.28%)   612 (0.11%)    583 (0.12%)    2229 (0.40%)            
##     Snow                                 1293 (0.24%)   651 (0.10%)    271 (0.05%)    1151 (0.24%)   3140 (0.57%)            
##     Unknown                              2073 (0.38%)   4580 (0.73%)   2829 (0.50%)   2520 (0.53%)   3054 (0.55%)            
## Road_Algn_ID:                                                                                                        0.000   
##     Curve, grade                        12360 (2.29%)  13009 (2.08%)  12264 (2.19%)  11848 (2.49%)  12573 (2.28%)            
##     Curve, hillcrest                     2468 (0.46%)   2770 (0.44%)   2618 (0.47%)   2380 (0.50%)   2947 (0.53%)            
##     Curve, level                        28220 (5.24%)  29764 (4.75%)  28368 (5.06%)  25954 (5.46%)  29010 (5.25%)            
##     Other (explain in narrative)         1695 (0.31%)   8482 (1.35%)   1634 (0.29%)   1470 (0.31%)   2184 (0.40%)            
##     Straight, grade                     39898 (7.41%)  43660 (6.97%)  39132 (6.98%)  33669 (7.09%)  38418 (6.96%)            
##     Straight, hillcrest                 10872 (2.02%)  11830 (1.89%)  10828 (1.93%)   9434 (1.99%)  11373 (2.06%)            
##     Straight, level                     442071 (82.1%) 515234 (82.2%) 465057 (82.9%) 389479 (82.0%) 454560 (82.3%)           
##     Unknown                              1155 (0.21%)   1765 (0.28%)   934 (0.17%)    898 (0.19%)    1060 (0.19%)            
## Crash_Sev_ID:                                                                                                        0.000   
##     Fatal                                3344 (0.62%)   3354 (0.54%)   3287 (0.59%)   3542 (0.75%)   4057 (0.73%)            
##     Incapacitating injury               14282 (2.65%)  12494 (1.99%)  12898 (2.30%)  12116 (2.55%)  15765 (2.86%)            
##     Non-incapacitating                  58404 (10.8%)  55847 (8.91%)  54122 (9.65%)  46247 (9.73%)  60567 (11.0%)            
##     Not injured                         341974 (63.5%) 408964 (65.3%) 363022 (64.7%) 308565 (64.9%) 360639 (65.3%)           
##     Possible injury                     97884 (18.2%)  104423 (16.7%) 105722 (18.9%) 82734 (17.4%)  86963 (15.8%)            
##     Unknown                             22851 (4.24%)  41432 (6.61%)  21784 (3.88%)  21928 (4.62%)  24134 (4.37%)            
## Intrsct_Relat_ID:                                                                                                    0.000   
##     Driveway access                     52417 (9.73%)  55278 (8.82%)  53742 (9.58%)  43446 (9.14%)  52071 (9.43%)            
##     Intersection                        120924 (22.4%) 126191 (20.1%) 127809 (22.8%) 108571 (22.9%) 129669 (23.5%)           
##     Intersection related                89680 (16.6%)  96275 (15.4%)  90165 (16.1%)  75384 (15.9%)  89233 (16.2%)            
##     Non intersection                    275713 (51.2%) 348767 (55.7%) 289119 (51.6%) 247731 (52.1%) 281152 (50.9%)           
## Surf_Type_ID:                                                                                                        0.000   
##     High type composite                 48780 (18.4%)  51281 (18.2%)  51332 (17.6%)   2243 (1.23%)   2517 (1.17%)            
##     High type flexible                  111464 (42.0%) 120291 (42.7%) 125850 (43.2%) 103000 (56.5%) 122000 (56.8%)           
##     High type rigid                     78666 (29.7%)  81811 (29.0%)  85914 (29.5%)   3830 (2.10%)   4408 (2.05%)            
##     Intermediate type mixed              3682 (1.39%)   3891 (1.38%)   3761 (1.29%)   2459 (1.35%)   2940 (1.37%)            
##     Low type bituminous surface-treated 22569 (8.51%)  24567 (8.72%)  24699 (8.47%)  11311 (6.20%)  13269 (6.18%)            
##     Road is unpaved                       0 (0.00%)      0 (0.00%)      0 (0.00%)    59464 (32.6%)  69741 (32.5%)            
## ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯