Forecasting: principles and practice Rob J Hyndman 3.2 Forecasting with multiple seasonality 1
Outline 1 Time series with complex seasonality 2 STL with multiple seasonal periods 3 Dynamic harmonic regression 4 TBATS model 5 Lab session 21 2
Examples autoplot(gasoline) + xlab("year") + ylab("thousands of barrels per day") + ggtitle("weekly US finished motor gasoline products") Weekly US finished motor gasoline products Thousands of barrels per day 9 8 7 1990 1995 2000 2005 2010 2015 3
Examples 5 minute call volume at North American bank 400 Call volume 300 200 100 0 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 Weeks 400 Call volume 300 200 100 1 2 3 4 Weeks 4
Examples Turkish daily electricity demand 25 Electricity Demand (GW) 20 15 10 2000 2002 2004 2006 2008 Year 5
Outline 1 Time series with complex seasonality 2 STL with multiple seasonal periods 3 Dynamic harmonic regression 4 TBATS model 5 Lab session 21 6
STL with multiple seasonal periods calls %>% mstl() %>% autoplot() + xlab("week") 400 300 200 100 0 220 210 200 190 180 100 50 0 50 100 150 60 40 20 0 20 40 100 50 0 50 100 0 10 20 30 Week Data Trend Seasonal169 Seasonal845 Remainder 7
. STL with multiple seasonal periods calls %>% stlf() %>% autoplot() + xlab("week") Forecasts from STL + ETS(M,N,N) 400 300 200 100 level 80 95 0 100 0 10 20 30 Week 8
. STL with multiple seasonal periods calls %>% stlf() %>% autoplot(include=5*169) + xlab("week") Forecasts from STL + ETS(M,N,N) 400 300 200 100 level 80 95 0 100 33 34 35 Week 9
Outline 1 Time series with complex seasonality 2 STL with multiple seasonal periods 3 Dynamic harmonic regression 4 TBATS model 5 Lab session 21 10
Dynamic harmonic regression fit <- auto.arima(calls, seasonal=false, lambda=0, xreg=fourier(calls, K=c(10,10))) fit %>% forecast(xreg=fourier(calls, K=c(10,10), h=2*169)) %>% autoplot(include=5*169) + ylab("call volume") + xlab("weeks") 400 Forecasts from Regression with ARIMA(3,1,4) errors Call volume 300 200 level 80 95 100 32.8 33.2 33.6 34.0 Weeks 11
Outline 1 Time series with complex seasonality 2 STL with multiple seasonal periods 3 Dynamic harmonic regression 4 TBATS model 5 Lab session 21 12
TBATS model TBATS Trigonometric terms for seasonality Box-Cox transformations for heterogeneity ARMA errors for short-term dynamics Trend (possibly damped) Seasonal (including multiple and non-integer periods) 13
TBATS model y observation at time t (y ω t 1)/ω if ω 0; log y t if ω = 0. l t 1 + φb t 1 + M i=1 l l t 1 + φb t 1 + αd t t m i + d t b (1 φ)b + φb t 1 + βd t d p i=1 k i φ i d t i + j,t q θ j ε t j + ε t j, s(i) j,t 1 cos λ(i) j + s (i) j,t 1 sin λ(i) j + γ 1 (i) d t j, s(i) j,t 1 sin λ(i) j + s (i) j,t 1 cos λ(i) j + γ (i) 2 d t 14
TBATS model y observation at time t (y ω t 1)/ω if ω 0; log y t if ω = 0. l t 1 + φb t 1 + M i=1 l l t 1 + φb t 1 + αd t t m i + d t Box-Cox transformation b (1 φ)b + φb t 1 + βd t d p i=1 k i φ i d t i + j,t q θ j ε t j + ε t j, s(i) j,t 1 cos λ(i) j + s (i) j,t 1 sin λ(i) j + γ 1 (i) d t j, s(i) j,t 1 sin λ(i) j + s (i) j,t 1 cos λ(i) j + γ (i) 2 d t 14
TBATS model y observation at time t (y ω t 1)/ω if ω 0; log y t if ω = 0. l t 1 + φb t 1 + M i=1 l l t 1 + φb t 1 + αd t t m i + d t Box-Cox transformation M seasonal periods b (1 φ)b + φb t 1 + βd t d p i=1 k i φ i d t i + j,t q θ j ε t j + ε t j, s(i) j,t 1 cos λ(i) j + s (i) j,t 1 sin λ(i) j + γ 1 (i) d t j, s(i) j,t 1 sin λ(i) j + s (i) j,t 1 cos λ(i) j + γ (i) 2 d t 14
TBATS model y observation at time t (y ω t 1)/ω if ω 0; log y t if ω = 0. l t 1 + φb t 1 + M i=1 l l t 1 + φb t 1 + αd t t m i + d t b (1 φ)b + φb t 1 + βd t d p i=1 k i φ i d t i + j,t q θ j ε t j + ε t j, Box-Cox transformation M seasonal periods global and local trend s(i) j,t 1 cos λ(i) j + s (i) j,t 1 sin λ(i) j + γ 1 (i) d t j, s(i) j,t 1 sin λ(i) j + s (i) j,t 1 cos λ(i) j + γ (i) 2 d t 14
TBATS model y observation at time t (y ω t 1)/ω if ω 0; log y t if ω = 0. l t 1 + φb t 1 + M i=1 l l t 1 + φb t 1 + αd t t m i + d t b (1 φ)b + φb t 1 + βd t d p i=1 k i φ i d t i + j,t q θ j ε t j + ε t j, Box-Cox transformation M seasonal periods global and local trend ARMA error s(i) j,t 1 cos λ(i) j + s (i) j,t 1 sin λ(i) j + γ 1 (i) d t j, s(i) j,t 1 sin λ(i) j + s (i) j,t 1 cos λ(i) j + γ (i) 2 d t 14
TBATS model y observation at time t (y ω t 1)/ω if ω 0; log y t if ω = 0. l t 1 + φb t 1 + M i=1 l l t 1 + φb t 1 + αd t t m i + d t b (1 φ)b + φb t 1 + βd t d p i=1 k i φ i d t i + j,t q θ j ε t j + ε t j, s(i) j,t 1 Box-Cox transformation M seasonal periods global and local trend ARMA error Fourier-like seasonal terms + s (i) j,t 1 sin λ(i) j + γ 1 (i) d t cos λ(i) j j, s(i) j,t 1 sin λ(i) j + s (i) j,t 1 cos λ(i) j + γ (i) 2 d t 14
TBATS model y observation at time t (yt ω 1)/ω if ω 0; log TBATS y t if ω = 0. l t 1 + φb t 1 + M i=1 l l t 1 + φb t 1 + αd t t m i + d t b (1 φ)b + φb t 1 + βd t d p q φ i d t i + i=1seasonal k i Trigonometric Box-Cox ARMA Trend j,t θ j ε t j + ε t j, s(i) j,t 1 Box-Cox transformation M seasonal periods global and local trend ARMA error Fourier-like seasonal terms + s (i) j,t 1 sin λ(i) j + γ 1 (i) d t cos λ(i) j j, s(i) j,t 1 sin λ(i) j + s (i) j,t 1 cos λ(i) j + γ (i) 2 d t 14
. Complex seasonality gasoline %>% tbats() %>% forecast() %>% autoplot() Forecasts from TBATS(1, {0,0},, {<52.18,12>}) 10 9 level 8 80 95 7 1990 2000 2010 2020 Time 15
. Complex seasonality calls %>% tbats() %>% forecast() %>% autoplot() Forecasts from TBATS(0.555, {0,0},, {<169,6>, <845,4>}) 800 600 level 400 80 95 200 0 0 10 20 30 Time 16
. Complex seasonality telec %>% tbats() %>% forecast() %>% autoplot() Forecasts from TBATS(0.005, {4,2},, {<7,3>, <354.37,7>, <365.25,3>}) 25 20 level 80 95 15 10 2000 2004 2008 Time 17
TBATS model TBATS Trigonometric terms for seasonality Box-Cox transformations for heterogeneity ARMA errors for short-term dynamics Trend (possibly damped) Seasonal (including multiple and non-integer periods) Handles non-integer seasonality, multiple seasonal periods. Entirely automated Prediction intervals often too wide Very slow on long series 18
Outline 1 Time series with complex seasonality 2 STL with multiple seasonal periods 3 Dynamic harmonic regression 4 TBATS model 5 Lab session 21 19
Lab Session 21 20