-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.rmd
179 lines (161 loc) · 7.33 KB
/
README.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---
title: TimeSeries.OBeu <img src="okfgr2.png" align="right" />
author: "Kleanthis Koupidis, Charalampos Bratsas"
output:
github_document:
fig_width: 8
fig_height: 8
dev: png
html_preview: no
number_sections: yes
---
[![R-CMD-check](https://github.com/okgreece/TimeSeries.OBeu/workflows/R-CMD-check/badge.svg)](https://github.com/okgreece/TimeSeries.OBeu/actions)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/TimeSeries.OBeu)](https://cran.r-project.org/package=TimeSeries.OBeu)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![](http://cranlogs.r-pkg.org/badges/grand-total/TimeSeries.OBeu)](http://cran.rstudio.com/web/packages/TimeSeries.OBeu/index.html)
[![Licence](https://img.shields.io/badge/licence-GPL--2-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
[![DOI](https://zenodo.org/badge/69395698.svg)](https://zenodo.org/badge/latestdoi/69395698)
#[TimeSeries.OBeu ](https://okgreece.github.io/TimeSeries.OBeu/)
Εstimate and return the necessary parameters for time series visualizations, used in [OpenBudgets.eu](http://openbudgets.eu/). It includes functions to test stationarity (with ACF, PACF, Phillips Perron test, Augmented Dickey Fuller (ADF) test, Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test, Mann Kendall Test For Monotonic Trend and Cox and Stuart trend test), decompose, model and forecast Budget time series data of municipalities across Europe, according to the [OpenBudgets.eu data model](https://github.com/openbudgets/data-model).
This package can generally be used to extract visualization parameters convert them to JSON format and use them as input in a different graphical interface. Most functions can have general use out of the [OpenBudgets.eu data model](https://github.com/openbudgets/data-model).
You can see detailed information [here](https://okgreece.github.io/TimeSeries.OBeu/).
```{r, eval=FALSE, include=TRUE}
# install TimeSeries.OBeu- cran stable version
install.packages(TimeSeries.OBeu)
# or
# alternatively install the development version from github
devtools::install_github("okgreece/TimeSeries.OBeu")
```
Load library `TimeSeries.OBeu` <img src="obeu_logo.png" align="right" />
```{r}
library(TimeSeries.OBeu)
```
#Time Series analysis in a call
`ts.analysis` is used to estimate *autocorrelation and partial autocorrelation* of input time series data, *autocorrelation and partial autocorrelation* of the model residuals, *trend*, *seasonal* (if exists) and *remainder* components, model parameters such as arima order, arima coefficients etc. and the desired *forecasts* with their corresponding confidence intervals.
`ts.analysis` returns by default a json object, if `tojson` parameter is `FALSE` returns a list object and the default forecast step is set to 1.
```{r}
results = ts.analysis(Athens_executed_ts, prediction.steps = 2, tojson=TRUE) # json string format
jsonlite::prettify(results) # use prettify of jsonlite library to add indentation to the returned JSON string
```
`ts.analysis` uses internally the functions `ts.stationary.test`,`ts.acf`,`ts.non.seas.decomp`,`ts.seasonal.decomp`, `ts.seasonal.model`, `ts.non.seas.model` and `ts.forecast`. However, these functions can be used independently and depends on the user requirements (see package manual or vignettes).
#Time series analysis on OpenBudgets.eu platform
`open_spending.ts` is designed to estimate and return the autocorrelation parameters, time series model parameters and the forecast parameters of [OpenBudgets.eu](http://openbudgets.eu/) time series datasets.
The input data must be a JSON link according to the [OpenBudgets.eu data model](https://github.com/openbudgets/data-model). The user should specify the amount and time variables, future steps to be predicted (default is 1 step forward) and the arima order (if not specified the most appropriate model will be selected according to AIC value).
`open_spending.ts` estimates and returns the json data (that are described with the [OpenBudgets.eu data model](https://github.com/openbudgets/data-model)), using `ts.analysis` function.
```{r}
#example openbudgets.eu time series data
sample.ts.data =
'{"page":0,
"page_size": 30,
"total_cell_count": 15,
"cell": [],
"status": "ok",
"cells": [{
"global__fiscalPeriod__28951.notation": "2002",
"global__amount__0397f.sum": 290501420.64,
"global__amount__0397f__CZK.sum": 9210928544.2325,
"_count": 4805
},
{
"global__fiscalPeriod__28951.notation": "2003",
"global__amount__0397f.sum": 311242291.07,
"global__amount__0397f__CZK.sum": 9832143974.9013,
"_count": 4988
},
{
"global__fiscalPeriod__28951.notation": "2004",
"global__amount__0397f.sum": 5268500701.1,
"global__amount__0397f__CZK.sum": 170688885714.24,
"_count": 10055
},
{
"global__fiscalPeriod__28951.notation": "2005",
"global__amount__0397f.sum": 2542887761.01,
"global__amount__0397f__CZK.sum": 77204615312.025,
"_count": 2032
},
{
"global__fiscalPeriod__28951.notation": "2006",
"global__amount__0397f.sum": 14803951786.68,
"global__amount__0397f__CZK.sum": 429758720367.32,
"_count": 13632
},
{
"global__fiscalPeriod__28951.notation": "2007",
"global__amount__0397f.sum": 16188514346.44,
"global__amount__0397f__CZK.sum": 445588857385.76,
"_count": 22798
},
{
"global__fiscalPeriod__28951.notation": "2008",
"global__amount__0397f.sum": 18231035815.89,
"global__amount__0397f__CZK.sum": 480643028250.12,
"_count": 24176
},
{
"global__fiscalPeriod__28951.notation": "2009",
"global__amount__0397f.sum": 19079541164.68,
"global__amount__0397f__CZK.sum": 511808691742.54,
"_count": 26250
},
{
"global__fiscalPeriod__28951.notation": "2010",
"global__amount__0397f.sum": 22738650575.01,
"global__amount__0397f__CZK.sum": 597685430364.14,
"_count": 87667
},
{
"global__fiscalPeriod__28951.notation": "2011",
"global__amount__0397f.sum": 24961375670.57,
"global__amount__0397f__CZK.sum": 626230992823.26,
"_count": 134352
},
{
"global__fiscalPeriod__28951.notation": "2012",
"global__amount__0397f.sum": 261513607691.41,
"global__amount__0397f__CZK.sum": 7030666436872.5,
"_count": 147556
},
{
"global__fiscalPeriod__28951.notation": "2013",
"global__amount__0397f.sum": 268946402299.09,
"global__amount__0397f__CZK.sum": 7226220232913.8,
"_count": 150079
},
{
"global__fiscalPeriod__28951.notation": "2014",
"global__amount__0397f.sum": 255222816704.9,
"global__amount__0397f__CZK.sum": 6907598086283.4,
"_count": 176019
},
{
"global__fiscalPeriod__28951.notation": "2015",
"global__amount__0397f.sum": 22976062973.62,
"global__amount__0397f__CZK.sum": 636276111928.46,
"_count": 213777
},
{
"global__fiscalPeriod__28951.notation": "2016",
"global__amount__0397f.sum": 12051686541.16,
"global__amount__0397f__CZK.sum": 325672725401.77,
"_count": 161797
}
],
"order": [
["global__fiscalPeriod__28951.fiscalPeriod", "asc"]
],
"aggregates": ["", "_count"],
"summary": {
"global__amount__0397f.sum": 945126777743.27,
"global__amount__0397f__CZK.sum": 25485085887878
},
"attributes": [""]
}'
result = open_spending.ts(
json_data = sample.ts.data,
time ="global__fiscalPeriod__28951.notation",
amount = "global__amount__0397f.sum"
)
# Pretty output using prettify of jsonlite library
jsonlite::prettify(result,indent = 2)
```