This vignette provides an overview of the fars package functionality. The package contains a set of functions built for analysis of data from Fatality Analysis Reporting System (FARS). FARS is a nationwide census providing NHTSA, Congress and the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes. More information about the system can be found here.

NOTE 1: The examples in this vignettes were built on files provided with the package. These files are located in folder inst/exdata. In order to use these files the filename should be built in the following way:

file <- system.file("exdata",make_filename(year), package = "fars")

NOTE 2:

The functions read data files which are placed in the working directory.

Libraries

Libraries needed for the fars package:

library(fars)
library(magrittr)
library(maps)

Package functions

There are five exported functions available to users:

For the purposes of these examples presented in this vignette, data from FARS, for years 2013-2015 will be used. It can be found in the package directory in \extdata folder.

Reading data files

The function make_filename() takes as an argument a four-digit year and make a file name for the function fars_read(), which in turn provides means to read data from a file with path provided as an argument. It returns a tibble with loaded data:

make_filename(2013)
filename <- system.file("exdata","accident_2013.csv.bz2", package = "fars")
fars_read(filename)

Summary of accident data

The function fars_read_years() takes as an argument a four digit year (in the form 2013 or "2013"), or a vector of years (2013:2015). It returns a tibble with two columns: MONTH and year for each accident, if the data files are available. As mentioned in NOTE2, the data files need to be located in the working directory.

fars_read_years(2013:2015)

The above data can be summarized by function fars_summarize_years() which takes the same input ast fars_read_years() and if the corresponding files with data are available, it returns a summary table with number of accidents per year and month. As mentioned in NOTE2, the data files need to be located in the working directory.

fars_summarize_years(2013)

Plot accident locations

Function fars_map_state() takes as arguments state index and year and returns a plot with the contour of the state with accident locations. The state indices need to correspond to available indices from the data set. The states are numbered alphabetically and the corresponding list can be found here (page 23). As mentioned in NOTE2, the data files need to be located in the working directory.

# California example
fars_map_state(6, 2013)


kurowska/fars documentation built on May 20, 2019, 7:06 p.m.