class: center, middle, inverse, title-slide .title[ # Time Series: Practical Issues ] .subtitle[ ## FPP3, Chapter 13 ] .author[ ### Robert W. Walker ] .institute[ ### AGSM ] .date[ ### 2022-12-05 ] --- --- # Practical Issues in Forecasting ## Models for different frequencies --- ### Models for annual data * ETS, ARIMA, Dynamic regression --- ### Models for quarterly data * ETS, ARIMA/SARIMA, Dynamic regression, Dynamic harmonic regression, STL+ETS, STL+ARIMA --- ### Models for monthly data * ETS, ARIMA/SARIMA, Dynamic regression, Dynamic harmonic regression, STL+ETS, STL+ARIMA --- ### Models for weekly data * ARIMA/SARIMA, Dynamic regression, Dynamic harmonic regression, STL+ETS, STL+ARIMA, TBATS --- ### 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: Use logs ```r library(fpp3) recent_prices <- fpp3::prices %>% filter(!is.na(eggs)) %>% as_tsibble(index=year) %>% select(year, eggs) recent_prices %>% model(ETS(log(eggs) ~ error("A") + trend("A") + season("N"))) %>% forecast(h=50) %>% autoplot(eggs) ``` --- # Combining Forecasts ## 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 ```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 = 60) ``` --- ## Forecast combinations ```r fc %>% autoplot(aus_cafe, level = NULL) + labs(x = "Year", y = "$ billion", title = "Australian monthly expenditure on eating out") ``` --- ## Forecast combinations ```r fc %>% accuracy(aus_cafe) ``` --- # Missing Values **Functions which can handle missing values** * `ARIMA()` * `TSLM()` * `NNETAR()` * `VAR()` * `FASSTER()` **Models which cannot handle missing values** * `ETS()` * `STL()` * `TBATS()` --- ### What to do? 1. Model section of data after last missing value. 2. Estimate missing values with `interpolate()`. --- ## Missing values ```r gold <- as_tsibble(forecast::gold) gold %>% autoplot(value) ``` <img src="index_files/figure-html/unnamed-chunk-3-1.png" width="576" /> --- ## Missing values ```r gold_complete <- gold %>% model(ARIMA(value)) %>% interpolate(gold) gold_complete %>% autoplot(value, colour = "red") + autolayer(gold, value) ``` <img src="index_files/figure-html/unnamed-chunk-4-1.png" width="576" /> --- ## Outliers ```r fit <- gold %>% model(ARIMA(value)) augment(fit) %>% mutate(stdres = .resid/sd(.resid, na.rm=TRUE)) %>% filter(abs(stdres) > 10) ``` ``` # A tsibble: 2 x 7 [1] # Key: .model [1] .model index value .fitted .resid .innov stdres <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 ARIMA(value) 770 594. 499. 94.7 94.7 16.4 2 ARIMA(value) 771 487. 562. -74.8 -74.8 -12.9 ```