forked from robjhyndman/fpp3_slides
/
7-6-forecasting-regression.Rmd
82 lines (62 loc) · 2.19 KB
/
7-6-forecasting-regression.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
---
title: "7. Time series regression models"
author: "7.6 Forecasting with regression"
date: "OTexts.org/fpp3/"
classoption: aspectratio=169
titlepage: fpp3title.png
titlecolor: fpp3red
toc: false
output:
binb::monash:
colortheme: monashwhite
fig_width: 7.5
fig_height: 3
keep_tex: no
includes:
in_header: fpp3header.tex
---
```{r setup, include=FALSE}
source("setup.R")
```
## Ex-ante versus ex-post forecasts
* \orange{Ex ante forecasts} are made using only information available in advance.
- require forecasts of predictors
* \orange{Ex post forecasts} are made using later information on the predictors.
- useful for studying behaviour of forecasting models.
* trend, seasonal and calendar variables are all known in advance, so these don't need to be forecast.
## Beer production
\fontsize{7}{7}\sf
```{r beeryetagain, echo=TRUE}
recent_production <- aus_production |> filter(year(Quarter) >= 1992)
recent_production |> model(TSLM(Beer ~ trend() + season())) |>
forecast() |> autoplot(recent_production)
```
## Scenario based forecasting
* Assumes possible scenarios for the predictor variables
* Prediction intervals for scenario based forecasts do not include the uncertainty associated with the future values of the predictor variables.
## US Consumption
```{r usconsumptionf, echo=TRUE}
fit_consBest <- us_change |>
model(
TSLM(Consumption ~ Income + Savings + Unemployment)
)
future_scenarios <- scenarios(
Increase = new_data(us_change, 4) |>
mutate(Income = 1, Savings = 0.5, Unemployment = 0),
Decrease = new_data(us_change, 4) |>
mutate(Income = -1, Savings = -0.5, Unemployment = 0),
names_to = "Scenario"
)
fc <- forecast(fit_consBest, new_data = future_scenarios)
```
## US Consumption
```{r usconsumptionf2, echo=TRUE}
us_change |> autoplot(Consumption) +
labs(y = "% change in US consumption") +
autolayer(fc) +
labs(title = "US consumption", y = "% change")
```
## Building a predictive regression model {-}
* If getting forecasts of predictors is difficult, you can use lagged predictors instead.
$$y_{t+h}=\beta_0+\beta_1x_{1,t}+\dots+\beta_kx_{k,t}+\varepsilon_{t+h}$$
* A different model for each forecast horizon $h$.