Welcome to Forecasting Using R Rob Hyndman Author, forecast - - PowerPoint PPT Presentation

welcome to forecasting using r
SMART_READER_LITE
LIVE PREVIEW

Welcome to Forecasting Using R Rob Hyndman Author, forecast - - PowerPoint PPT Presentation

FORECASTING USING R Welcome to Forecasting Using R Rob Hyndman Author, forecast Forecasting Using R What you will learn Exploring and visualizing time series Simple benchmark methods for forecasting Exponential smoothing and


slide-1
SLIDE 1

FORECASTING USING R

Welcome to Forecasting Using R

Rob Hyndman

Author, forecast

slide-2
SLIDE 2

Forecasting Using R

What you will learn

  • Exploring and visualizing time series
  • Simple benchmark methods for forecasting
  • Exponential smoothing and ARIMA models
  • Advanced forecasting methods
  • Measuring forecast accuracy
  • Choosing the best method
slide-3
SLIDE 3

Forecasting Using R

Course textbook

  • Free and online at OTexts.org/fpp2/
  • Data sets in associated R package fpp2
  • R code for all examples

Hyndman, R. J. & Athanasopoulos,

  • G. (2017)

Forecasting: principles and practice, 2nd edition

slide-4
SLIDE 4

Forecasting Using R

Time series data

  • Series of data observed over time
  • Eg.: Daily IBM stock prices, monthly rainfall in London,…

Forecasting is estimating how the sequence of observations will continue into the future.

slide-5
SLIDE 5

Forecasting Using R

Forecasts of monthly Australian expenditure on eating out

  • What forecasting methods are available that take account of trend,

seasonality and other features of the data?

  • How to measure the accuracy of your forecasts?
  • How to choose a good forecasting model?
slide-6
SLIDE 6

FORECASTING USING R

Let’s practice!

slide-7
SLIDE 7

FORECASTING USING R

Trends, seasonality, and cyclicity

slide-8
SLIDE 8

Forecasting Using R

Time series paerns

Paern Description Trend A paern exists involving a long-term increase OR decrease in the data Seasonal A periodic paern exists due to the calendar (e.g. the quarter, month, or day of the week) Cyclic A paern exists where the data exhibits rises and falls that are not of fixed period (duration usually of at least 2 years)

slide-9
SLIDE 9

Forecasting Using R

Examples of time series paerns

slide-10
SLIDE 10

Forecasting Using R

Examples of time series paerns

slide-11
SLIDE 11

Forecasting Using R

Examples of time series paerns

slide-12
SLIDE 12

Forecasting Using R

Examples of time series paerns

slide-13
SLIDE 13

Forecasting Using R

Seasonal or cyclic?

Differences between seasonal and cyclic paerns:

  • Seasonal paern constant length vs. cyclic paern variable

length

  • Average length of cycle longer than length of seasonal paern
  • Magnitude of cycle more variable than magnitude of seasonal

paern The timing of peaks and troughs is predictable with seasonal data, but unpredictable in the long term with cyclic data.

slide-14
SLIDE 14

FORECASTING USING R

Let’s practice!

slide-15
SLIDE 15

FORECASTING USING R

White noise

slide-16
SLIDE 16

Forecasting Using R

White noise

> set.seed(3) # Reproducibility > wn <- ts(rnorm(36)) # White noise > autoplot(wn) # Plot!

"White noise" is just a time series of iid data

slide-17
SLIDE 17

Forecasting Using R

White noise ACF

> ggAcf(wn) + ggtitle("Sample ACF for white noise")

Expectation: each autocorrelation is close to zero 95% of all autocorrelations for white noise should lie within the blue lines If not: series is probably not white noise

slide-18
SLIDE 18

Forecasting Using R

Example: Pigs slaughtered

> autoplot(pigs/1000) + > xlab("Year") + > ylab("thousands") + > ggtitle("Monthly number of pigs slaughtered in Victoria")

slide-19
SLIDE 19

Forecasting Using R

Example: Pigs slaughtered

> ggAcf(pigs) + > ggtitle("ACF of monthly pigs slaughtered in Victoria")

significant autocorrelation at lags 1, 2, and 3 Not a white noise series: there is info in the data that can be used to forecast future values

slide-20
SLIDE 20

Forecasting Using R

Ljung-Box test

> Box.test(pigs, lag = 24, fitdf = 0, type = "Lj") Box-Ljung test data: pigs X-squared = 634.15, df = 24, p-value < 2.2e-16

The Ljung-Box test considers the first h autocorrelation values

  • together. 



 A significant test (small p-value) indicates the data are probably not white noise.

slide-21
SLIDE 21

Forecasting Using R

White noise summary

  • White noise is a time series that is purely random
  • We can test for white noise by looking at an ACF plot
  • r by doing a Ljung-Box test
slide-22
SLIDE 22

FORECASTING USING R

Let’s practice!