Forecasts and potential futures Rob Hyndman Author, forecast - - PowerPoint PPT Presentation

forecasts and potential futures
SMART_READER_LITE
LIVE PREVIEW

Forecasts and potential futures Rob Hyndman Author, forecast - - PowerPoint PPT Presentation

FORECASTING USING R Forecasts and potential futures Rob Hyndman Author, forecast Forecasting Using R Sample futures Forecasting Using R Sample futures Forecasting Using R Sample futures Forecasting Using R Sample futures Forecasting


slide-1
SLIDE 1

FORECASTING USING R

Forecasts and potential futures

Rob Hyndman

Author, forecast

slide-2
SLIDE 2

Forecasting Using R

Sample futures

slide-3
SLIDE 3

Forecasting Using R

Sample futures

slide-4
SLIDE 4

Forecasting Using R

Sample futures

slide-5
SLIDE 5

Forecasting Using R

Sample futures

slide-6
SLIDE 6

Forecasting Using R

Sample futures

slide-7
SLIDE 7

Forecasting Using R

Sample futures

slide-8
SLIDE 8

Forecasting Using R

Sample futures

slide-9
SLIDE 9

Forecasting Using R

Sample futures

slide-10
SLIDE 10

Forecasting Using R

Forecast intervals

slide-11
SLIDE 11

Forecasting Using R

Forecast intervals

  • The 80% forecast intervals should contain 80% of the future observations
  • The 95% forecast intervals should contain 95% of the future observations
slide-12
SLIDE 12

FORECASTING USING R

Let’s practice!

slide-13
SLIDE 13

FORECASTING USING R

Fied values and residuals

slide-14
SLIDE 14

Forecasting Using R

Fied values and residuals

A fied value is the forecast of an observation using all previous observations

  • That is, they are one-step forecasts
  • Oen not true forecasts since parameters are estimated on all data

A residual is the difference between an observation and its fied value

  • That is, they are one-step forecast errors
slide-15
SLIDE 15

Forecasting Using R

Example: oil production

> fc <- naive(oil) > autoplot(oil, series = "Data") + xlab("Year") + autolayer(fitted(fc), series = "Fitted") + ggtitle("Oil production in Saudi Arabia")

slide-16
SLIDE 16

Forecasting Using R

Example: oil production

> autoplot(residuals(fc))

slide-17
SLIDE 17

Forecasting Using R

Residuals should look like white noise

Essential assumptions

  • They should be uncorrelated
  • They should have mean zero

Useful properties (for computing prediction intervals)

  • They should have constant variance
  • They should be normally distributed

We can test these assumptions using the checkresiduals() function.

slide-18
SLIDE 18

Forecasting Using R

checkresiduals()

> checkresiduals(fc) Ljung-Box test data: residuals Q* = 12.59, df = 10, p-value = 0.2475 Model df: 0. Total lags used: 10

slide-19
SLIDE 19

FORECASTING USING R

Let’s practice!

slide-20
SLIDE 20

FORECASTING USING R

Training and test sets

slide-21
SLIDE 21

Forecasting Using R

Training and test sets

  • The test set must not be used for any aspect of

calculating forecasts

  • Build forecasts using training set
  • A model which fits the training data well will not

necessarily forecast well

slide-22
SLIDE 22

Forecasting Using R

Example: Saudi Arabian oil production

> training <- window(oil, end = 2003) > test <- window(oil, start = 2004) > fc <- naive(training, h = 10) > autoplot(fc) + autolayer(test, series = "Test data")

slide-23
SLIDE 23

Forecasting Using R

Forecast errors

Forecast "error" = the difference between observed value and its forecast in the test set.
 
 ≠ residuals

  • which are errors on the training set (vs.

test set)

  • which are based on one-step forecasts

(vs. multi-step) Compute accuracy using forecast errors on test data

slide-24
SLIDE 24

Forecasting Using R

Measures of forecast accuracy

Definitions Observation Forecast Forecast error Accuracy measure Calculation Mean Absolute Error Mean Squared Error Mean Absolute Percentage Error Mean Absolute Scaled Error

yt ˆ yt

et = yt − ˆ yt

MAE = average(|et|) MSE = average(e2

t )

MAPE = 100 × average(|et yt |) MASE = MAE/Q

* Where Q is a scaling constant.

slide-25
SLIDE 25

Forecasting Using R

The accuracy() command

> accuracy(fc, test) ME RMSE MAE MPE MAPE MASE ACF1 Theil's U Training set 9.874 52.56 39.43 2.507 12.571 1.0000 0.1802 NA Test set 21.602 35.10 29.98 3.964 5.778 0.7603 0.4030 1.185

slide-26
SLIDE 26

FORECASTING USING R

Let’s practice!

slide-27
SLIDE 27

FORECASTING USING R

Time series cross-validation

slide-28
SLIDE 28

Forecasting Using R

Time series cross-validation

Traditional evaluation

time Training data Test data

slide-29
SLIDE 29

Forecasting Using R

Time series cross-validation

Time series cross-validation Traditional evaluation

time Training data Test data

time

slide-30
SLIDE 30

Forecasting Using R

Time series cross-validation

Time series cross-validation Traditional evaluation

time

time Training data Test data

slide-31
SLIDE 31

Forecasting Using R

Time series cross-validation

Time series cross-validation Traditional evaluation

time

time Training data Test data

slide-32
SLIDE 32

Forecasting Using R

tsCV function

MSE using time series cross-validation

> e <- tsCV (oil, forecastfunction = naive, h = 1) > mean(e^2 , na.rm = TRUE) [1] 2355.753

When there are no parameters to be estimated, tsCV with h=1 will give the same values as residuals

slide-33
SLIDE 33

Forecasting Using R

tsCV function

> sq <- function(u){u^2} > for(h in 1:10) + { + oil %>% tsCV(forecastfunction = naive, h = h) %>% + sq() %>% mean(na.rm = TRUE) %>% print() + } [1] 2355.753 [1] 5734.838 [1] 9842.239 [1] 14300 [1] 18560.89 [1] 23264.41 [1] 26932.8 [1] 30766.14 [1] 32892.2 [1] 32986.21

The MSE increases with the forecast horizon

slide-34
SLIDE 34

Forecasting Using R

tsCV function

  • Choose the model with the smallest MSE computed using

time series cross-validation

time series cross-validation.

  • Compute it at the forecast horizon of most interest to you
slide-35
SLIDE 35

FORECASTING USING R

Let’s practice!