0% found this document useful (0 votes)
90 views

Welcome To Forecasting Using R: Rob J. Hyndman

This document introduces forecasting using R. It will cover exploring and visualizing time series data, simple benchmark forecasting methods, exponential smoothing and ARIMA models, advanced forecasting techniques, measuring forecast accuracy, and choosing the best forecasting model. The course uses the textbook Forecasting: Principles and Practice which is available for free online. Examples will use data sets from the fpp2 R package.

Uploaded by

Nathan Gurgel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Welcome To Forecasting Using R: Rob J. Hyndman

This document introduces forecasting using R. It will cover exploring and visualizing time series data, simple benchmark forecasting methods, exponential smoothing and ARIMA models, advanced forecasting techniques, measuring forecast accuracy, and choosing the best forecasting model. The course uses the textbook Forecasting: Principles and Practice which is available for free online. Examples will use data sets from the fpp2 R package.

Uploaded by

Nathan Gurgel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Welcome to

Forecasting Using R
FORECASTING IN R

Rob J. Hyndman
Professor of Statistics at Monash
University
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

FORECASTING IN R
Course textbook
Hyndman, R. J. &
Athanasopoulos, G. (2017)

Forecasting: principles and


practice, 2nd edition

Free and online at


OTexts.org/fpp2/

Data sets in associated R


package fpp2

R code for all examples

FORECASTING IN 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.

FORECASTING IN 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?

FORECASTING IN R
Let's practice!
FORECASTING IN R
Trends, seasonality,
and cyclicity
FORECASTING IN R

Rob J. Hyndman
Professor of Statistics at Monash
University
Time series patterns

FORECASTING IN R
Time series patterns

FORECASTING IN R
Time series patterns

FORECASTING IN R
Time series patterns

FORECASTING IN R
Time series patterns

FORECASTING IN R
Time series patterns

FORECASTING IN R
Time series patterns

FORECASTING IN R
Examples of time series patterns

FORECASTING IN R
Examples of time series patterns

FORECASTING IN R
Examples of time series patterns

FORECASTING IN R
Examples of time series patterns

FORECASTING IN R
Seasonal or cyclic?
Di erences between seasonal and cyclic pa erns:

Seasonal pa ern constant length vs. cyclic pa ern variable


length

Average length of cycle longer than length of seasonal


pa ern

Magnitude of cycle more variable than magnitude of


seasonal pa ern

The timing of peaks and troughs is predictable with seasonal


data, but unpredictable in the long term with cyclic data.

FORECASTING IN R
Let's practice!
FORECASTING IN R
White noise
FORECASTING IN R

Rob J. Hyndman
Professor of Statistics at Monash
University
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

FORECASTING IN R
White noise ACF
ggAcf(wn) +
ggtitle("Sample ACF for white noise")

FORECASTING IN R
White noise ACF
ggAcf(wn) +
ggtitle("Sample ACF for white noise")

FORECASTING IN R
White noise ACF
ggAcf(wn) +
ggtitle("Sample ACF for white noise")

FORECASTING IN R
White noise ACF
ggAcf(wn) +
ggtitle("Sample ACF for white noise")

FORECASTING IN R
Example: Pigs slaughtered
autoplot(pigs/1000) +
xlab("Year") +
ylab("thousands") +
ggtitle("Monthly number of pigs slaughtered in Victoria")

FORECASTING IN R
Example: Pigs slaughtered
ggAcf(pigs) +
ggtitle("ACF of monthly pigs slaughtered
in Victoria")

FORECASTING IN R
Example: Pigs slaughtered
ggAcf(pigs) +
ggtitle("ACF of monthly pigs slaughtered
in Victoria")

FORECASTING IN R
Example: Pigs slaughtered
ggAcf(pigs) +
ggtitle("ACF of monthly pigs slaughtered
in Victoria")

FORECASTING IN R
Ljung-Box test
The Ljung-Box test considers the rst h autocorrelation values
together.

A signi cant test (small p-value) indicates the data are


probably not white noise.

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

FORECASTING IN 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 or by


doing a Ljung-Box test

FORECASTING IN R
Let's practice!
FORECASTING IN R

You might also like