-
Notifications
You must be signed in to change notification settings - Fork 167
/
12-practical.qmd
168 lines (129 loc) · 3.38 KB
/
12-practical.qmd
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
---
title: "ETC3550/ETC5550 Applied forecasting"
author: "Ch12. Some practical issues"
institute: "OTexts.org/fpp3/"
pdf-engine: pdflatex
fig-width: 7.5
fig-height: 3.5
format:
beamer:
theme: monash
aspectratio: 169
fontsize: 14pt
section-titles: false
knitr:
opts_chunk:
dev: "cairo_pdf"
include-in-header: header.tex
execute:
echo: false
message: false
warning: false
---
```{r setup, include=FALSE}
source("setup.R")
```
# Models for different frequencies
## Models for different frequencies
### Models for annual data
* ETS, ARIMA, Dynamic regression
\pause
### Models for quarterly data
* ETS, ARIMA/SARIMA, Dynamic regression, Dynamic harmonic regression, STL+ETS, STL+ARIMA
\pause
### Models for monthly data
* ETS, ARIMA/SARIMA, Dynamic regression, Dynamic harmonic regression, STL+ETS, STL+ARIMA
## Models for different frequencies
### Models for weekly data
* ARIMA/SARIMA, Dynamic regression, Dynamic harmonic regression, STL+ETS, STL+ARIMA, TBATS
\pause
### Models for daily, hourly and other sub-daily data
* ARIMA/SARIMA, Dynamic regression, Dynamic harmonic regression, STL+ETS, STL+ARIMA, TBATS
# Ensuring forecasts stay within limits
## Positive forecasts
\fontsize{9}{9}\sf
```{r, fig.height=3.8}
recent_prices <- prices |> filter(!is.na(eggs))
recent_prices |>
model(ETS(log(eggs) ~ error("A") + trend("A") + season("N"))) |>
forecast(h = 50) |>
autoplot(recent_prices)
```
# Forecast combinations
## Forecast combinations
### Clemen (1989)
"The results have been virtually unanimous: combining multiple forecasts leads to increased forecast accuracy. \dots In many cases one can make dramatic performance improvements by simply averaging the forecasts."
## Forecast combinations
\fontsize{9}{10}\sf\vspace*{-0.2cm}
```{r}
aus_cafe <- aus_retail |>
filter(Industry == "Cafes, restaurants and catering services") |>
summarise(Turnover = sum(Turnover))
fc <- aus_cafe |>
filter(Month <= yearmonth("2013 Sep")) |>
model(
ETS = ETS(Turnover),
ARIMA = ARIMA(Turnover)
) |>
mutate(
Combination = (ETS + ARIMA) / 2
) |>
forecast(h = "5 years")
```
## Forecast combinations
\fontsize{10}{10}\sf\vspace*{-0.2cm}
```{r combineplot, echo=TRUE, fig.height=4.2}
fc |> autoplot(aus_cafe, level = NULL) +
labs(
x = "Year", y = "$ billion",
title = "Australian monthly expenditure on eating out"
)
```
## Forecast combinations
\fontsize{10}{15}\sf
```{r combineaccuracy, dependson="combine1"}
fc |> accuracy(aus_cafe)
```
# Missing values
## Missing values
\fontsize{12}{13}\sf
**Functions which can handle missing values**
* `ARIMA()`
* `TSLM()`
* `NNETAR()`
* `VAR()`
* `FASSTER()`
**Models which cannot handle missing values**
* `ETS()`
* `STL()`
* `TBATS()`
\pause
### What to do?
1. Model section of data after last missing value.
2. Estimate missing values with `interpolate()`.
## Missing values
\fontsize{12}{12}\sf
```{r}
gold <- as_tsibble(forecast::gold)
gold |> autoplot(value)
```
## Missing values
\fontsize{12}{12}\sf
```{r, fig.height=3}
gold_complete <- gold |>
model(ARIMA(value)) |>
interpolate(gold)
gold_complete |>
autoplot(value, colour = "red") +
autolayer(gold, value)
```
# Outliers
## Outliers
\fontsize{11}{13}\sf
```{r, fig.height=3.4}
fit <- gold |>
model(ARIMA(value))
augment(fit) |>
mutate(stdres = .resid / sd(.resid, na.rm = TRUE)) |>
filter(abs(stdres) > 10)
```