AccidentR Info

The AccidentR package includes a set of functions to Import, Summarize and Plot US Traffic Accident Data for the years of 2013, 2014 and 2015. The package will be using data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System. This platform is a US nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.

The AccidentR package exports two functions that facilitate the Import, Summarize and Plot US Traffic Accident Data. These functions are:

Installing AccidentR

devtools::install_github("joaocunha1991/AccidentR")

Raw Data

The AccidentR package includes 3 files (csv.bz2) for running examples. The files are located on inst/extdata inside the package directory. The following raw data files are provided:

Function fars_summarize_years()

This function takes a character vector of years to create an R tibble dataframe consisting of the respective files combined (for each year passed in years).It then combines together these dataframes into one to perform aggregations on the level of accidents per year/month.

To run fars_summarize_years() use:

years <- c("2013","2014","2015")
fars_summarize_years(years)

This will return a R tibble (wide format) dataframe with 'Years' on the rows and 'Months' as columns with the volume of accidents as values. The return format is as per below:

library(magrittr)
library(AccidentR)

years <- c("2013","2014","2015")
AccidentR::fars_summarize_years(years)

Function fars_map_state()

This function takes a character value representing a State Number (state.num) and a Year (year) to import a file (based on the year parsed) as a R tibble dataframe.

After filtering the dataframe based on State Number (state.num), the function outputs a geo-plot of the filtered State Number (state.num) with the volume of accidents.

The function uses AccidentR::fars_read() function and AccidentR::make_filename() to execute the described process.

To run fars_map_state() use:

fars_map_state(state.num = "6", year = "2015")

If state.num doesn't exist on the dataframe, an error is returned (i.e. invalid STATE number: 324). If the filtered dataframe has zero records - the function returns a message 'no accidents to plot'.

Longitudes higher than 900 and Latitudes > than 90 are treated as NAs for plotting purposes. This might affect the some of the borders of the plotted US States.

Please see an example of the output of fars_map_state(state.num = "6", year = "2015"):

library(magrittr)
library(maps)
library(AccidentR)

AccidentR::fars_map_state(state.num = "6", year = "2015")


joaocunha1991/AccidentR documentation built on May 27, 2019, 7:45 a.m.