-
Notifications
You must be signed in to change notification settings - Fork 36
/
README.Rmd
119 lines (95 loc) · 3.4 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
---
output:
github_document:
html_preview: false
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.path = "man/figures/")
```
# hts <img src="man/figures/logo.png" align="right" />
[![R build status](https://github.com/earowang/hts/workflows/R-CMD-check/badge.svg)](https://github.com/earowang/hts/actions?workflow=R-CMD-check)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/hts)](https://cran.r-project.org/package=hts)
[![Downloads](http://cranlogs.r-pkg.org/badges/hts)](https://cran.r-project.org/package=hts)
[![Lifecycle: retired](https://img.shields.io/badge/lifecycle-retired-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
**hts** is retired, with minimum maintenance to keep it on CRAN. We recommend using the [fable](http://fable.tidyverts.org) package instead.
The R package *hts* presents functions to create, plot and forecast hierarchical and grouped time series.
## Installation
You can install the **stable** version on
[R CRAN](https://cran.r-project.org/package=hts).
```r
install.packages('hts', dependencies = TRUE)
```
You can also install the **development** version from
[Github](https://github.com/earowang/hts)
```r
# install.packages("devtools")
devtools::install_github("earowang/hts")
```
## Usage
### Example 1: hierarchical time series
```{r hts-eg1, echo = TRUE}
library(hts)
# hts example 1
print(htseg1)
summary(htseg1)
aggts1 <- aggts(htseg1)
aggts2 <- aggts(htseg1, levels = 1)
aggts3 <- aggts(htseg1, levels = c(0, 2))
plot(htseg1, levels = 1)
smatrix(htseg1) # Return the dense mode
# Forecasts
fcasts1.bu <- forecast(
htseg1, h = 4, method = "bu", fmethod = "ets", parallel = TRUE
)
aggts4 <- aggts(fcasts1.bu)
summary(fcasts1.bu)
fcasts1.td <- forecast(
htseg1, h = 4, method = "tdfp", fmethod = "arima", keep.fitted = TRUE
)
summary(fcasts1.td) # When keep.fitted = TRUE, return in-sample accuracy
fcasts1.comb <- forecast(
htseg1, h = 4, method = "comb", fmethod = "ets", keep.fitted = TRUE
)
aggts4 <- aggts(fcasts1.comb)
plot(fcasts1.comb, levels = 2)
plot(fcasts1.comb, include = 5, levels = c(1, 2))
```
### Example 2: hierarchical time series
```{r hts-eg2, echo = TRUE}
# hts example 2
data <- window(htseg2, start = 1992, end = 2002)
test <- window(htseg2, start = 2003)
fcasts2.mo <- forecast(
data, h = 5, method = "mo", fmethod = "ets", level = 1,
keep.fitted = TRUE, keep.resid = TRUE
)
accuracy.gts(fcasts2.mo, test)
accuracy.gts(fcasts2.mo, test, levels = 1)
fcasts2.td <- forecast(
data, h = 5, method = "tdgsa", fmethod = "ets",
keep.fitted = TRUE, keep.resid = TRUE
)
plot(fcasts2.td, include = 5)
plot(fcasts2.td, include = 5, levels = c(0, 2))
```
### Example 3: grouped time series
```{r gts-eg, echo = TRUE}
# gts example
plot(infantgts, levels = 1)
fcasts3.comb <- forecast(infantgts, h = 4, method = "comb", fmethod = "ets")
agg_gts1 <- aggts(fcasts3.comb, levels = 1)
agg_gts2 <- aggts(fcasts3.comb, levels = 1, forecasts = FALSE)
plot(fcasts3.comb)
plot(fcasts3.comb, include = 5, levels = c(1, 2))
fcasts3.combsd <- forecast(
infantgts, h = 4, method = "comb", fmethod = "ets",
weights = "sd", keep.fitted = TRUE
)
fcasts3.combn <- forecast(
infantgts, h = 4, method = "comb", fmethod = "ets",
weights = "nseries", keep.resid = TRUE
)
```
## License
This package is free and open source software, licensed under GPL (>= 2).