There are several useful functions contained in the fars package to help you analyze data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System.

The data comes from a nationwide census which provides the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.

In addition to useful functions, data for years 2013, 2014, and 2015 are contained in this package.

Getting familiar with the fars package

First, load the fars package..


A good way to get familiar with a package is to list all of its functions.


Next, we can check the documentation of the functions to find out what they do.


Using fars functions.

First, we need to know what data is currently available to us. The fars_read_years() function is helpful in this regard.

data_range <- fars_read_years(2011:2017)

As we can see from the warning messages above, we don't have data for 2011, 2012, 2016, and 2017.

However, now we know data sets are available for 2013, 2014, and 2015. We could call the fars_summarize_years() function on those years, which will give us a summary table of accidents observed each month, by year.

summary_table <- fars_summarize_years(2013:2015)
kable(summary_table, align = 'l')

As we can see, 2014 had the least accidents. To examine further, we can use the make_filename() helper function to produce the file name corresponding to year of the available data set we would like to call. Save the file name to the variable filename.

filename <- make_filename(2014)

Next, pass the filename variable to the fars_read() function, load the data set, and view its abbreviated tibble.

accident_2014 <- fars_read(filename)

You may have noticed, the first variable column in the fars data sets is the state where an accident observation occurred. We can use the fars_map_state() function to view accidents by state, and visualize clusters. Lets use California as an example.

fars_map_state(6, 2014)

With data and visualization helper functions outlined above, you can get to work on the more interesting analysis questions about traffic accidents in the United States.

JustinMShea/Fatality-Analysis-Reporting-System documentation built on Sept. 20, 2017, 12:01 a.m.