Description Usage Arguments Details Value See Also Examples
View source: R/timeseriesanalysis.R
Function to evaluate the trend in a traffic accident time series.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
accidents |
Either an R date/time or character vector with accident dates. For character vectors, only the following date formats are allowed: '2014-04-22', '2014/04/22', '22.4.2014'. |
exposition |
Optional data frame with exposition data. The first column is the time value, the second column the exposure. If the time value is a specific date (e.g. '22.4.2014'), this is considered as the start date of this exposure. If the time value is a year (format '2010') the exposure is taken for the whole year. Exposure values are extended until a new entry is available. If necessary, the first exposure value is extended backwards. DEFAULT NULL. |
from |
From which date or year (1.1.) the time series should be considered. Optional. If not specified, the 1.1 from the year of the earliest accident is used. |
until |
Until what date or year (31.12) the time series should be considered. Optional. If not specified, the 31.12 from the year of the latest accident is used. |
pearson_line |
TRUE/FALSE, indicating if the line for Pearson residual equal 2 should be drawn or not. |
show_outliers |
FALSE/TRUE, indicating if outliers with Pearson residual greater than 2 should be highlighted in color or not. |
main |
Optional title for the plot. |
max_y |
Optional maximum value for the y-axis. |
min_y |
Optional minimum value for the y-axis, defaults to 0. |
x_axis |
Optional, points at which tick-marks are to be drawn. |
orientation_x |
Alignment of the labels of the x-axis; "v" for vertical, "h" for horizontal, by default horizontal alignment is selected for 8 years or less. |
add_exp |
Option to supplement the output plot with the exposure as an additional axis. Furthermore an additional plot of the exposure alone is produced. Only active if exposure is available. |
lang |
Language for output ("en", "fr", "de" or "it"), defaults to "en". |
The function provides methodology for analyzing general trends in a time series of accident count data. It is based on the Poisson model. However, the fit is tested for overdispersion and in case of significant overdispersion it is automatically replaced by a Negative Binomial regression. The model enables the user to quantify observed trends and assess their statistical significance (reliability of results). The time resolution for accident periods is fixed at one year to avoid potential nuisance by seasonality. However, the start date for the analysis can be freely selected.
A specific R object (class_timeseriesanalyis
) is generated as function output. The main object is the plot with a graphical analysis of the trend in the time series. The function print.class_timeseriesanalyis()
is used to extract the most important key figures of the analysis.
Specifically, the output contains a list of the following elements:
|
Output of the count regression model (Poisson or Negative Binomial family. |
|
Prepared data that were used for the analysis. |
|
Annual trend |
|
p-value for the null hypothesis that the trend equals 0. |
|
p-value of the deviance dispersion test. |
|
Plot graphical analysis (ggplot-class). |
|
Selected language. |
|
Addional plot of the exposition, if available (ggplot-class). |
earlywarning()
function for early warning, which alerts the user if the current annual accident incidence is significantly higher than in previous years.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ex1 <- timeseriesanalysis(accidents = example1_timeserie)
print(ex1)
plot(ex1)
summary(ex1)
summary(ex1$fit)
ex2 <- timeseriesanalysis(accidents = example2_timeserie, lang = "de")
ex2
ex3 <- timeseriesanalysis(accidents = example3_timeserie, lang = "it")
print(ex3)
ex4 <- timeseriesanalysis(accidents = example4_timeserie, lang = "fr")
print(ex4)
plot(ex4)
summary(ex4)
ex5 <- timeseriesanalysis(accidents = example1_timeserie, exposition=exposition_ex1)
plot(ex5)
ex6 <- timeseriesanalysis(accidents = example1_timeserie, exposition=exposition_ex2)
print(ex6)
ex7 <- timeseriesanalysis(accidents = example1_timeserie, exposition=exposition_ex3, add_exp = TRUE)
summary(ex7)
plot(ex7)
plot(ex7$plot_exposition)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.