forecasting: principles and practice · classical method originated in 1920s. census ii method...

28
Forecasting: principles and practice 1 Forecasting: principles and practice Rob J Hyndman 1.3 Seasonality and trends

Upload: others

Post on 18-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Forecasting: principles and practice 1

Forecasting: principlesand practice

Rob J Hyndman

1.3 Seasonality and trends

Page 2: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Outline

1 Time series components

2 STL decomposition

3 Forecasting and decomposition

4 Lab session 5

Forecasting: principles and practice Time series components 2

Page 3: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Time series patterns

Trend pattern exists when there is a long-termincrease or decrease in the data.

Seasonal pattern exists when a series is influenced byseasonal factors (e.g., the quarter of the year,the month, or day of the week).

Cyclic pattern exists when data exhibit rises and fallsthat are not of fixed period (duration usually ofat least 2 years).

Forecasting: principles and practice Time series components 3

Page 4: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Time series decomposition

Yt = f(St, Tt, Et)

where Yt = data at period tSt = seasonal component at period tTt = trend-cycle component at period tEt = remainder (or irregular or error) compo-

nent at period t

Additive decomposition: Yt = St + Tt + Et.Multiplicative decomposition: Yt = St × Tt × Et.

Forecasting: principles and practice Time series components 4

Page 5: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Time series decomposition

Yt = f(St, Tt, Et)

where Yt = data at period tSt = seasonal component at period tTt = trend-cycle component at period tEt = remainder (or irregular or error) compo-

nent at period t

Additive decomposition: Yt = St + Tt + Et.Multiplicative decomposition: Yt = St × Tt × Et.

Forecasting: principles and practice Time series components 4

Page 6: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Time series decomposition

Yt = f(St, Tt, Et)

where Yt = data at period tSt = seasonal component at period tTt = trend-cycle component at period tEt = remainder (or irregular or error) compo-

nent at period t

Additive decomposition: Yt = St + Tt + Et.Multiplicative decomposition: Yt = St × Tt × Et.

Forecasting: principles and practice Time series components 4

Page 7: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Time series decomposition

Additive model appropriate if magnitude of seasonalfluctuations does not vary with level.If seasonal are proportional to level of series, thenmultiplicative model appropriate.Multiplicative decomposition more prevalent witheconomic seriesAlternative: use a Box-Cox transformation, and thenuse additive decomposition.Logs turn multiplicative relationship into an additiverelationship:

Yt = St × Tt × Et ⇒ log Yt = log St + log Tt + log Et.Forecasting: principles and practice Time series components 5

Page 8: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Euro electrical equipment

60

80

100

120

2000 2005 2010

New

ord

ers

inde

x

series

Data

Trend

Electrical equipment manufacturing (Euro area)

Forecasting: principles and practice Time series components 6

Page 9: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Euro electrical equipmentda

tatr

end

seas

onal

rem

aind

er

2000 2005 2010

60

80

100

120

80

90

100

110

−20

−10

0

10

−8

−4

0

4

Time

Forecasting: principles and practice Time series components 7

Page 10: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Euro electrical equipment

−20

−10

0

10

Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

Month

Sea

sona

l

Forecasting: principles and practice Time series components 8

Page 11: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Seasonal adjustment

Useful by-product of decomposition: an easy way tocalculate seasonally adjusted data.Additive decomposition: seasonally adjusted datagiven by

Yt − St = Tt + EtMultiplicative decomposition: seasonally adjusteddata given by

Yt/St = Tt × Et

Forecasting: principles and practice Time series components 9

Page 12: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Euro electrical equipment

60

80

100

120

2000 2005 2010

New

ord

ers

inde

x

series

Data

SeasAdjust

Electrical equipment manufacturing

Forecasting: principles and practice Time series components 10

Page 13: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Seasonal adjustment

We use estimates of S based on past values toseasonally adjust a current value.Seasonally adjusted series reflect remainders as wellas trend. Therefore they are not “smooth” and“downturns” or “upturns” can be misleading.It is better to use the trend-cycle component to lookfor turning points.

Forecasting: principles and practice Time series components 11

Page 14: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

History of time series decomposition

Classical method originated in 1920s.Census II method introduced in 1957. Basis formodern X-12-ARIMA method.STL method introduced in 1983TRAMO/SEATS introduced in 1990s.

Forecasting: principles and practice Time series components 12

Page 15: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Outline

1 Time series components

2 STL decomposition

3 Forecasting and decomposition

4 Lab session 5

Forecasting: principles and practice STL decomposition 13

Page 16: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

STL decomposition

STL: “Seasonal and Trend decomposition using Loess”,Very versatile and robust.Unlike X-12-ARIMA, STL will handle any type ofseasonality.Seasonal component allowed to change over time,and rate of change controlled by user.Smoothness of trend-cycle also controlled by user.Robust to outliersNot trading day or calendar adjustments.Only additive.

Forecasting: principles and practice STL decomposition 14

Page 17: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Euro electrical equipmentelecequip %>% stl(s.window=5) %>%

autoplot

data

tren

dse

ason

alre

mai

nder

2000 2005 2010

60

80

100

120

80

90

100

110

−20

−10

0

10

−8

−4

0

4

TimeForecasting: principles and practice STL decomposition 15

Page 18: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Euro electrical equipmentelecequip %>%

stl(t.window=15, s.window='periodic', robust=TRUE) %>%autoplot

data

tren

dse

ason

alre

mai

nder

2000 2005 2010

60

80

100

120

80

90

100

110

−10

0

10

−5

0

5

10

TimeForecasting: principles and practice STL decomposition 16

Page 19: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

STL decomposition in R

t.window controls wiggliness of trend component.s.window controls variation on seasonal component.

Forecasting: principles and practice STL decomposition 17

Page 20: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Outline

1 Time series components

2 STL decomposition

3 Forecasting and decomposition

4 Lab session 5

Forecasting: principles and practice Forecasting and decomposition 18

Page 21: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Forecasting and decomposition

Forecast seasonal component by repeating the lastyearForecast seasonally adjusted data using non-seasonaltime series method. E.g.,

Holt’s method — next topicRandom walk with drift model

Combine forecasts of seasonal component withforecasts of seasonally adjusted data to get forecastsof original data.Sometimes a decomposition is useful just forunderstanding the data before building a separateforecasting model.Forecasting: principles and practice Forecasting and decomposition 19

Page 22: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Seas adj elec equipment

70

90

110

2000 2005 2010 2015

New orders index

eead

j level

80

95

Naive forecasts of seasonally adjusted data

Forecasting: principles and practice Forecasting and decomposition 20

Page 23: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Seas adj elec equipment

40

60

80

100

120

2000 2005 2010 2015

Time

New

ord

ers

inde

x

level

80

95

Forecasts from STL + Random walk

Forecasting: principles and practice Forecasting and decomposition 21

Page 24: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

How to do this in R

fit <- stl(elecequip, t.window=15,s.window="periodic", robust=TRUE)

eeadj <- seasadj(fit)autoplot(naive(eeadj, h=24)) +

ylab("New orders index")

fcast <- forecast(fit, method="naive", h=24)autoplot(fcast) +

ylab="New orders index")

Forecasting: principles and practice Forecasting and decomposition 22

Page 25: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Decomposition and prediction intervals

It is common to take the prediction intervals from theseasonally adjusted forecasts and modify them withthe seasonal component.This ignores the uncertainty in the seasonalcomponent estimate.It also ignores the uncertainty in the future seasonalpattern.

Forecasting: principles and practice Forecasting and decomposition 23

Page 26: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Some more R functions

fcast <- stlf(elecequip, method='naive')

fcast <- stlf(elecequip, method='naive',h=36, s.window=11, robust=TRUE)

Forecasting: principles and practice Forecasting and decomposition 24

Page 27: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Outline

1 Time series components

2 STL decomposition

3 Forecasting and decomposition

4 Lab session 5

Forecasting: principles and practice Lab session 5 25

Page 28: Forecasting: principles and practice · Classical method originated in 1920s. Census II method introduced in 1957. Basis for modern X-12-ARIMA method. STL method introduced in 1983

Lab Session 5

Forecasting: principles and practice Lab session 5 26