forecasting using - rob j hyndman · pdf fileotexts.com/fpp/2/3 forecasting using r 1 rob j...

116
Forecasting using 1. Introduction to forecasting OTexts.com/fpp/1/ OTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman

Upload: phungnhan

Post on 22-Mar-2018

224 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Forecasting using

1. Introduction to forecasting

OTexts.com/fpp/1/OTexts.com/fpp/2/3

Forecasting using R 1

Rob J Hyndman

Page 2: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Outline

1 Introduction

2 Some case studies

3 Time series data

4 Some simple forecasting methods

5 Conclusion

Forecasting using R Introduction 2

Page 3: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

The online environment

Forecasting using R Introduction 3

Page 4: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer sales

Page 5: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer sales

Page 6: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer sales

Page 7: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer sales

Page 8: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer sales

Page 9: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer sales

Page 10: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer sales

Page 11: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer sales

Page 12: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Brief bio

Forecasting using R Introduction 4

Director of Monash University’sBusiness & EconomicForecasting Unit

Editor-in-Chief, InternationalJournal of Forecasting

How my forecasting methodology is used:

Pharmaceutical Benefits Scheme

Cancer incidence and mortality

Electricity demand

Ageing population

Fertilizer salesrobjhyndman.com

Page 13: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Introductions

Please introduce yourself briefly using the chat box(be sure to send your message to everyone).

What is your name?

Where in the world are you?

What time is it there?

Why are you taking this course?

Example

Rob. Melbourne, Australia. 9am. To help me use Rfor forecasting sales for my company.

Forecasting using R Introduction 5

Page 14: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Introductions

Please introduce yourself briefly using the chat box(be sure to send your message to everyone).

What is your name?

Where in the world are you?

What time is it there?

Why are you taking this course?

Example

Rob. Melbourne, Australia. 9am. To help me use Rfor forecasting sales for my company.

Forecasting using R Introduction 5

Page 15: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Poll: How experienced are you in forecasting?

1 Guru: I wrote the book, done it for decades,now I do the conference circuit.

2 Expert: It has been my full time job for morethan a decade.

3 Skilled: I have been doing it for years.

4 Comfortable: I understand it and have done it.

5 Learner: I am still learning.

6 Beginner: I have heard of it and would like tolearn more.

7 Unknown: What is forecasting? Is that what theweather people do?

Forecasting using R Introduction 6

Page 16: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Key reference

Hyndman, R. J. & Athanasopoulos, G.

(2013) Forecasting: principles and

practice.

otexts.com/fpp/

Free and online

Data sets in associated R package

R code for examples

Forecasting using R Introduction 7

Page 17: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Key reference

Hyndman, R. J. & Athanasopoulos, G.

(2013) Forecasting: principles and

practice.

otexts.com/fpp/

Free and online

Data sets in associated R package

R code for examples

Forecasting using R Introduction 7

Page 18: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Key reference

Hyndman, R. J. & Athanasopoulos, G.

(2013) Forecasting: principles and

practice.

otexts.com/fpp/

Free and online

Data sets in associated R package

R code for examples

Forecasting using R Introduction 7

Page 19: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Key reference

Hyndman, R. J. & Athanasopoulos, G.

(2013) Forecasting: principles and

practice.

otexts.com/fpp/

Free and online

Data sets in associated R package

R code for examples

Forecasting using R Introduction 7

Page 20: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Key reference

Hyndman, R. J. & Athanasopoulos, G.

(2013) Forecasting: principles and

practice.

otexts.com/fpp/

Free and online

Data sets in associated R package

R code for examples

Forecasting using R Introduction 7

Page 21: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Book recommendation

Forecasting using R Introduction 8

If you need more supporton statistics or R, then Irecommend:

Introductory Statisticswith Rby Peter Dalgaard

Page 22: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Poll: How proficient are you in using R?

1 Guru: The R core team come to me for advice.2 Expert: I have written several packages on

CRAN.3 Skilled: I use it regularly and it is an important

part of my job.4 Comfortable: I use it often and am comfortable

with the tool.5 User: I use it sometimes, but I am often

searching around for the right function.6 Learner: I have used it a few times.7 Beginner: I’ve managed to download and install

it.8 Unknown: Why are you speaking like a pirate?

Forecasting using R Introduction 9

Page 23: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Which version of R are you using?

Version: (try getRversion() if you don’t know)

1 R 3.0.0 or higher

2 R 2.15.x

3 R 2.14.x

4 Something older.

Edition

1 Standard R (CRAN)

2 Standard R with RStudio

3 Revolution R: Community, EnterpriseWorkstation or Server

4 Something else?Forecasting using R Introduction 10

Page 24: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Install required packages

install.packages("fpp", dependencies=TRUE)

Forecasting using R Introduction 11

Page 25: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Getting help with R# Search for termshelp.search("forecasting")

# Detailed helphelp(forecast)

# Worked examplesexample("forecast.ar")

# Similar namesapropos("forecast")

#Help on packagehelp(package="fpp")

Forecasting using R Introduction 12

Page 26: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Approximate outline

Week Topic Chapter

1 The forecaster’s toolbox 1,22 Seasonality and trends 63 Exponential smoothing 74 Stationarity, transformations

and differencing2,8

5 ARIMA models 86 Time series cross-validation 26 Dynamic regression 9

Forecasting using R Introduction 13

Page 27: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Assumptions

This is not an introduction to R. I assume youare broadly comfortable with R code and the Renvironment.

This is not a statistics course. I assume you arefamiliar with concepts such as the mean,standard deviation, quantiles, regression,normal distribution, etc.

This is not a theory course. I am not going toderive anything. I will teach you forecastingtools, when to use them and how to use themmost effectively.

Forecasting using R Introduction 14

Page 28: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Assumptions

This is not an introduction to R. I assume youare broadly comfortable with R code and the Renvironment.

This is not a statistics course. I assume you arefamiliar with concepts such as the mean,standard deviation, quantiles, regression,normal distribution, etc.

This is not a theory course. I am not going toderive anything. I will teach you forecastingtools, when to use them and how to use themmost effectively.

Forecasting using R Introduction 14

Page 29: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Assumptions

This is not an introduction to R. I assume youare broadly comfortable with R code and the Renvironment.

This is not a statistics course. I assume you arefamiliar with concepts such as the mean,standard deviation, quantiles, regression,normal distribution, etc.

This is not a theory course. I am not going toderive anything. I will teach you forecastingtools, when to use them and how to use themmost effectively.

Forecasting using R Introduction 14

Page 30: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Outline

1 Introduction

2 Some case studies

3 Time series data

4 Some simple forecasting methods

5 Conclusion

Forecasting using R Some case studies 15

Page 31: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 1: Paperware company

Forecasting using R Some case studies 16

Problem: Want forecasts of each ofhundreds of items. Series can bestationary, trended or seasonal. Theycurrently have a large forecastingprogram written in-house but it doesn’tseem to produce sensible forecasts.They want me to tell them what iswrong and fix it.

Page 32: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 1: Paperware company

Forecasting using R Some case studies 16

Problem: Want forecasts of each ofhundreds of items. Series can bestationary, trended or seasonal. Theycurrently have a large forecastingprogram written in-house but it doesn’tseem to produce sensible forecasts.They want me to tell them what iswrong and fix it.

Additional informationProgram written in COBOL making numerical calculationslimited. It is not possible to do any optimisation.

Page 33: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 1: Paperware company

Forecasting using R Some case studies 16

Problem: Want forecasts of each ofhundreds of items. Series can bestationary, trended or seasonal. Theycurrently have a large forecastingprogram written in-house but it doesn’tseem to produce sensible forecasts.They want me to tell them what iswrong and fix it.

Additional informationProgram written in COBOL making numerical calculationslimited. It is not possible to do any optimisation.Their programmer has little experience in numericalcomputing.

Page 34: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 1: Paperware company

Forecasting using R Some case studies 16

Problem: Want forecasts of each ofhundreds of items. Series can bestationary, trended or seasonal. Theycurrently have a large forecastingprogram written in-house but it doesn’tseem to produce sensible forecasts.They want me to tell them what iswrong and fix it.

Additional informationProgram written in COBOL making numerical calculationslimited. It is not possible to do any optimisation.Their programmer has little experience in numericalcomputing.They employ no statisticians and want the program toproduce forecasts automatically.

Page 35: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 1: Paperware company

Methods currently used

A 12 month average

C 6 month average

E straight line regression over last 12 months

G straight line regression over last 6 months

H average slope between last year’s and thisyear’s values.(Equivalent to differencing at lag 12 andtaking mean.)

I Same as H except over 6 months.

K I couldn’t understand the explanation.

Forecasting using R Some case studies 17

Page 36: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

Forecasting using R Some case studies 18

Page 37: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

The Pharmaceutical Benefits Scheme (PBS) isthe Australian government drugs subsidy scheme.

Many drugs bought from pharmacies aresubsidised to allow more equitable access tomodern drugs.

The cost to government is determined by thenumber and types of drugs purchased.Currently nearly 1% of GDP.

The total cost is budgeted based on forecastsof drug usage.

Forecasting using R Some case studies 19

Page 38: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

The Pharmaceutical Benefits Scheme (PBS) isthe Australian government drugs subsidy scheme.

Many drugs bought from pharmacies aresubsidised to allow more equitable access tomodern drugs.

The cost to government is determined by thenumber and types of drugs purchased.Currently nearly 1% of GDP.

The total cost is budgeted based on forecastsof drug usage.

Forecasting using R Some case studies 19

Page 39: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

The Pharmaceutical Benefits Scheme (PBS) isthe Australian government drugs subsidy scheme.

Many drugs bought from pharmacies aresubsidised to allow more equitable access tomodern drugs.

The cost to government is determined by thenumber and types of drugs purchased.Currently nearly 1% of GDP.

The total cost is budgeted based on forecastsof drug usage.

Forecasting using R Some case studies 19

Page 40: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

The Pharmaceutical Benefits Scheme (PBS) isthe Australian government drugs subsidy scheme.

Many drugs bought from pharmacies aresubsidised to allow more equitable access tomodern drugs.

The cost to government is determined by thenumber and types of drugs purchased.Currently nearly 1% of GDP.

The total cost is budgeted based on forecastsof drug usage.

Forecasting using R Some case studies 19

Page 41: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

Forecasting using R Some case studies 20

Page 42: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

In 2001: $4.5 billion budget, under-forecastedby $800 million.Thousands of products. Seasonal demand.Subject to covert marketing, volatile products,uncontrollable expenditure.Although monthly data available for 10 years,data are aggregated to annual values, and onlythe first three years are used in estimating theforecasts.All forecasts being done with the FORECASTfunction in MS-Excel!

Problem: How to do the forecasting better?

Forecasting using R Some case studies 21

Page 43: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

In 2001: $4.5 billion budget, under-forecastedby $800 million.Thousands of products. Seasonal demand.Subject to covert marketing, volatile products,uncontrollable expenditure.Although monthly data available for 10 years,data are aggregated to annual values, and onlythe first three years are used in estimating theforecasts.All forecasts being done with the FORECASTfunction in MS-Excel!

Problem: How to do the forecasting better?

Forecasting using R Some case studies 21

Page 44: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

In 2001: $4.5 billion budget, under-forecastedby $800 million.Thousands of products. Seasonal demand.Subject to covert marketing, volatile products,uncontrollable expenditure.Although monthly data available for 10 years,data are aggregated to annual values, and onlythe first three years are used in estimating theforecasts.All forecasts being done with the FORECASTfunction in MS-Excel!

Problem: How to do the forecasting better?

Forecasting using R Some case studies 21

Page 45: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

In 2001: $4.5 billion budget, under-forecastedby $800 million.Thousands of products. Seasonal demand.Subject to covert marketing, volatile products,uncontrollable expenditure.Although monthly data available for 10 years,data are aggregated to annual values, and onlythe first three years are used in estimating theforecasts.All forecasts being done with the FORECASTfunction in MS-Excel!

Problem: How to do the forecasting better?

Forecasting using R Some case studies 21

Page 46: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

In 2001: $4.5 billion budget, under-forecastedby $800 million.Thousands of products. Seasonal demand.Subject to covert marketing, volatile products,uncontrollable expenditure.Although monthly data available for 10 years,data are aggregated to annual values, and onlythe first three years are used in estimating theforecasts.All forecasts being done with the FORECASTfunction in MS-Excel!

Problem: How to do the forecasting better?

Forecasting using R Some case studies 21

Page 47: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 2: PBS

In 2001: $4.5 billion budget, under-forecastedby $800 million.Thousands of products. Seasonal demand.Subject to covert marketing, volatile products,uncontrollable expenditure.Although monthly data available for 10 years,data are aggregated to annual values, and onlythe first three years are used in estimating theforecasts.All forecasts being done with the FORECASTfunction in MS-Excel!

Problem: How to do the forecasting better?

Forecasting using R Some case studies 21

Page 48: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 3: Airline

Forecasting using R Some case studies 22

Page 49: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 3: Airline

Forecasting using R Some case studies 23

First class passengers: Melbourne−Sydney

Year

1988 1989 1990 1991 1992 1993

0.0

1.0

2.0

Business class passengers: Melbourne−Sydney

Year

1988 1989 1990 1991 1992 1993

02

46

8

Economy class passengers: Melbourne−Sydney

Year

1988 1989 1990 1991 1992 1993

010

2030

Page 50: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 3: Airline

Forecasting using R Some case studies 23

First class passengers: Melbourne−Sydney

Year

1988 1989 1990 1991 1992 1993

0.0

1.0

2.0

Business class passengers: Melbourne−Sydney

Year

1988 1989 1990 1991 1992 1993

02

46

8

Economy class passengers: Melbourne−Sydney

Year

1988 1989 1990 1991 1992 1993

010

2030

Not the real data!Or is it?

Page 51: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 3: Airline

Problem: how to forecast passenger traffic onmajor routes.

Additional information

They can provide a large amount of data onprevious routes.

Traffic is affected by school holidays, specialevents such as the Grand Prix, advertisingcampaigns, competition behaviour, etc.

They have a highly capable team of people whoare able to do most of the computing.

Forecasting using R Some case studies 24

Page 52: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 3: Airline

Problem: how to forecast passenger traffic onmajor routes.

Additional information

They can provide a large amount of data onprevious routes.

Traffic is affected by school holidays, specialevents such as the Grand Prix, advertisingcampaigns, competition behaviour, etc.

They have a highly capable team of people whoare able to do most of the computing.

Forecasting using R Some case studies 24

Page 53: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 3: Airline

Problem: how to forecast passenger traffic onmajor routes.

Additional information

They can provide a large amount of data onprevious routes.

Traffic is affected by school holidays, specialevents such as the Grand Prix, advertisingcampaigns, competition behaviour, etc.

They have a highly capable team of people whoare able to do most of the computing.

Forecasting using R Some case studies 24

Page 54: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

CASE STUDY 3: Airline

Problem: how to forecast passenger traffic onmajor routes.

Additional information

They can provide a large amount of data onprevious routes.

Traffic is affected by school holidays, specialevents such as the Grand Prix, advertisingcampaigns, competition behaviour, etc.

They have a highly capable team of people whoare able to do most of the computing.

Forecasting using R Some case studies 24

Page 55: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Outline

1 Introduction

2 Some case studies

3 Time series data

4 Some simple forecasting methods

5 Conclusion

Forecasting using R Time series data 25

Page 56: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series data

Time series consist of sequences ofobservations collected over time.We will assume the time periods are equallyspaced.

Time series examples

Daily IBM stock pricesMonthly rainfallAnnual Google profitsQuarterly Australian beer production

Forecasting is estimating how the sequenceof observations will continue into the future.

Forecasting using R Time series data 26

Page 57: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series data

Time series consist of sequences ofobservations collected over time.We will assume the time periods are equallyspaced.

Time series examples

Daily IBM stock pricesMonthly rainfallAnnual Google profitsQuarterly Australian beer production

Forecasting is estimating how the sequenceof observations will continue into the future.

Forecasting using R Time series data 26

Page 58: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series data

Time series consist of sequences ofobservations collected over time.We will assume the time periods are equallyspaced.

Time series examples

Daily IBM stock pricesMonthly rainfallAnnual Google profitsQuarterly Australian beer production

Forecasting is estimating how the sequenceof observations will continue into the future.

Forecasting using R Time series data 26

Page 59: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series data

Time series consist of sequences ofobservations collected over time.We will assume the time periods are equallyspaced.

Time series examples

Daily IBM stock pricesMonthly rainfallAnnual Google profitsQuarterly Australian beer production

Forecasting is estimating how the sequenceof observations will continue into the future.

Forecasting using R Time series data 26

Page 60: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series data

Time series consist of sequences ofobservations collected over time.We will assume the time periods are equallyspaced.

Time series examples

Daily IBM stock pricesMonthly rainfallAnnual Google profitsQuarterly Australian beer production

Forecasting is estimating how the sequenceof observations will continue into the future.

Forecasting using R Time series data 26

Page 61: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series data

Time series consist of sequences ofobservations collected over time.We will assume the time periods are equallyspaced.

Time series examples

Daily IBM stock pricesMonthly rainfallAnnual Google profitsQuarterly Australian beer production

Forecasting is estimating how the sequenceof observations will continue into the future.

Forecasting using R Time series data 26

Page 62: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series data

Time series consist of sequences ofobservations collected over time.We will assume the time periods are equallyspaced.

Time series examples

Daily IBM stock pricesMonthly rainfallAnnual Google profitsQuarterly Australian beer production

Forecasting is estimating how the sequenceof observations will continue into the future.

Forecasting using R Time series data 26

Page 63: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series data

Time series consist of sequences ofobservations collected over time.We will assume the time periods are equallyspaced.

Time series examples

Daily IBM stock pricesMonthly rainfallAnnual Google profitsQuarterly Australian beer production

Forecasting is estimating how the sequenceof observations will continue into the future.

Forecasting using R Time series data 26

Page 64: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Australian beer production

Forecasting using R Time series data 27

Year

meg

alite

rs

1995 2000 2005 2010

400

450

500

Page 65: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Looking for stories

Forecasting using R Time series data 28

Page 66: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Looking for stories that make sense

Forecasting using R Time series data 29

Page 67: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Think about what you’re doing

Forecasting using R Time series data 30

Page 68: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RAustralian GDPausgdp <- ts(scan("gdp.dat"),frequency=4,

start=1971+2/4)Class: tsPrint and plotting methods available.

> ausgdpQtr1 Qtr2 Qtr3 Qtr4

1971 4612 46511972 4645 4615 4645 47221973 4780 4830 4887 49331974 4921 4875 4867 49051975 4938 4934 4942 49791976 5028 5079 5112 51271977 5130 5101 5072 50691978 5100 5166 5244 53121979 5349 5370 5388 53961980 5388 5403 5442 5482

Forecasting using R Time series data 31

Page 69: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RAustralian GDPausgdp <- ts(scan("gdp.dat"),frequency=4,

start=1971+2/4)Class: tsPrint and plotting methods available.

> ausgdpQtr1 Qtr2 Qtr3 Qtr4

1971 4612 46511972 4645 4615 4645 47221973 4780 4830 4887 49331974 4921 4875 4867 49051975 4938 4934 4942 49791976 5028 5079 5112 51271977 5130 5101 5072 50691978 5100 5166 5244 53121979 5349 5370 5388 53961980 5388 5403 5442 5482

Forecasting using R Time series data 31

Page 70: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RAustralian GDPausgdp <- ts(scan("gdp.dat"),frequency=4,

start=1971+2/4)Class: tsPrint and plotting methods available.

> ausgdpQtr1 Qtr2 Qtr3 Qtr4

1971 4612 46511972 4645 4615 4645 47221973 4780 4830 4887 49331974 4921 4875 4867 49051975 4938 4934 4942 49791976 5028 5079 5112 51271977 5130 5101 5072 50691978 5100 5166 5244 53121979 5349 5370 5388 53961980 5388 5403 5442 5482

Forecasting using R Time series data 31

Page 71: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in R

Forecasting using R Time series data 32

Time

ausg

dp

1975 1980 1985 1990 19954500

5000

5500

6000

6500

7000

7500 > plot(ausgdp)

Page 72: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in R

Residential electricity sales

> elecsalesTime Series:Start = 1989End = 2008Frequency = 1[1] 2354.34 2379.71 2318.52 2468.99 2386.09 2569.47[7] 2575.72 2762.72 2844.50 3000.70 3108.10 3357.50

[13] 3075.70 3180.60 3221.60 3176.20 3430.60 3527.48[19] 3637.89 3655.00

Forecasting using R Time series data 33

Page 73: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RMain package used in this course> library(fpp)

Forecasting using R Time series data 34

Page 74: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RMain package used in this course> library(fpp)This loads:

some data for use in examples and exercisesforecast package (for forecasting functions)tseries package (for a few time seriesfunctions)fma package (for lots of time series data)expsmooth package (for more time seriesdata)lmtest package (for some regressionfunctions)

Forecasting using R Time series data 34

Page 75: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RMain package used in this course> library(fpp)This loads:

some data for use in examples and exercisesforecast package (for forecasting functions)tseries package (for a few time seriesfunctions)fma package (for lots of time series data)expsmooth package (for more time seriesdata)lmtest package (for some regressionfunctions)

Forecasting using R Time series data 34

Page 76: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RMain package used in this course> library(fpp)This loads:

some data for use in examples and exercisesforecast package (for forecasting functions)tseries package (for a few time seriesfunctions)fma package (for lots of time series data)expsmooth package (for more time seriesdata)lmtest package (for some regressionfunctions)

Forecasting using R Time series data 34

Page 77: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RMain package used in this course> library(fpp)This loads:

some data for use in examples and exercisesforecast package (for forecasting functions)tseries package (for a few time seriesfunctions)fma package (for lots of time series data)expsmooth package (for more time seriesdata)lmtest package (for some regressionfunctions)

Forecasting using R Time series data 34

Page 78: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RMain package used in this course> library(fpp)This loads:

some data for use in examples and exercisesforecast package (for forecasting functions)tseries package (for a few time seriesfunctions)fma package (for lots of time series data)expsmooth package (for more time seriesdata)lmtest package (for some regressionfunctions)

Forecasting using R Time series data 34

Page 79: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Time series in RMain package used in this course> library(fpp)This loads:

some data for use in examples and exercisesforecast package (for forecasting functions)tseries package (for a few time seriesfunctions)fma package (for lots of time series data)expsmooth package (for more time seriesdata)lmtest package (for some regressionfunctions)

Forecasting using R Time series data 34

Page 80: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Outline

1 Introduction

2 Some case studies

3 Time series data

4 Some simple forecasting methods

5 Conclusion

Forecasting using R Some simple forecasting methods 35

Page 81: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 36

Australian quarterly beer production

meg

alite

rs

1995 2000 2005

400

450

500

Page 82: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 36

Australian quarterly beer production

meg

alite

rs

1995 2000 2005

400

450

500

Can you think of any forecasting methods for these data?

Page 83: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 37

Number of pigs slaughtered in Victoria

thou

sand

s

1990 1991 1992 1993 1994 1995

8090

100

110

Page 84: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 37

Number of pigs slaughtered in Victoria

thou

sand

s

1990 1991 1992 1993 1994 1995

8090

100

110

How would you forecast these data?

Page 85: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 38

Dow Jones index (daily ending 15 Jul 94)

0 50 100 150 200 250

3600

3700

3800

3900

Page 86: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 38

Dow Jones index (daily ending 15 Jul 94)

0 50 100 150 200 250

3600

3700

3800

3900

How would you forecast these data?

Page 87: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 88: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 89: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 90: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 91: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 92: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 93: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 94: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 95: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Average method

Forecast of all future values is equal to mean ofhistorical data {y1, . . . , yT}.Forecasts: yT+h|T = y = (y1 + · · ·+ yT)/T

Naïve method (for time series only)

Forecasts equal to last observed value.Forecasts: yT+h|T = yT.Consequence of efficient market hypothesis.

Seasonal naïve method

Forecasts equal to last value from same season.Forecasts: yT+h|T = yT+h−km where m =seasonal period and k = b(h− 1)/mc+1.

Forecasting using R Some simple forecasting methods 39

Page 96: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 40

Forecasts for quarterly beer production

1995 2000 2005

400

450

500

Which method is which?

Page 97: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 40

Forecasts for quarterly beer production

1995 2000 2005

400

450

500

Mean methodNaive methodSeasonal naive method

Which method is which?

Page 98: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Drift method

Forecasts equal to last value plus averagechange.

Forecasts:

yT+h|T = yT +h

T − 1

T∑t=2

(yt − yt−1)

= yT +h

T − 1(yT − y1).

Equivalent to extrapolating a line drawnbetween first and last observations.

Forecasting using R Some simple forecasting methods 41

Page 99: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Drift method

Forecasts equal to last value plus averagechange.

Forecasts:

yT+h|T = yT +h

T − 1

T∑t=2

(yt − yt−1)

= yT +h

T − 1(yT − y1).

Equivalent to extrapolating a line drawnbetween first and last observations.

Forecasting using R Some simple forecasting methods 41

Page 100: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Drift method

Forecasts equal to last value plus averagechange.

Forecasts:

yT+h|T = yT +h

T − 1

T∑t=2

(yt − yt−1)

= yT +h

T − 1(yT − y1).

Equivalent to extrapolating a line drawnbetween first and last observations.

Forecasting using R Some simple forecasting methods 41

Page 101: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 42

Dow Jones Index (daily ending 15 Jul 94)

Day

0 50 100 150 200 250 300

3600

3700

3800

3900

Page 102: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Forecasting using R Some simple forecasting methods 42

Dow Jones Index (daily ending 15 Jul 94)

Day

0 50 100 150 200 250 300

3600

3700

3800

3900

Mean methodNaive methodDrift model

Page 103: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Mean: meanf(x, h=20)

Naive: naive(x, h=20) or rwf(x, h=20)

Seasonal naive: snaive(x, h=20)

Drift: rwf(x, drift=TRUE, h=20)

Forecasting using R Some simple forecasting methods 43

Page 104: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Mean: meanf(x, h=20)

Naive: naive(x, h=20) or rwf(x, h=20)

Seasonal naive: snaive(x, h=20)

Drift: rwf(x, drift=TRUE, h=20)

Forecasting using R Some simple forecasting methods 43

Page 105: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Mean: meanf(x, h=20)

Naive: naive(x, h=20) or rwf(x, h=20)

Seasonal naive: snaive(x, h=20)

Drift: rwf(x, drift=TRUE, h=20)

Forecasting using R Some simple forecasting methods 43

Page 106: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Some simple forecasting methods

Mean: meanf(x, h=20)

Naive: naive(x, h=20) or rwf(x, h=20)

Seasonal naive: snaive(x, h=20)

Drift: rwf(x, drift=TRUE, h=20)

Forecasting using R Some simple forecasting methods 43

Page 107: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Outline

1 Introduction

2 Some case studies

3 Time series data

4 Some simple forecasting methods

5 Conclusion

Forecasting using R Conclusion 44

Page 108: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Piazza

You should all have received an invitation tojoin the Piazza course page.

All discussion and distribution of informationoutside of classes will take place there.

Homework available there.

Session slides available there after eachsession.

Please ask questions there.

If you haven’t received an invitation, or arehaving trouble, please ask James to help([email protected]).

Forecasting using R Conclusion 45

Page 109: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Piazza

You should all have received an invitation tojoin the Piazza course page.

All discussion and distribution of informationoutside of classes will take place there.

Homework available there.

Session slides available there after eachsession.

Please ask questions there.

If you haven’t received an invitation, or arehaving trouble, please ask James to help([email protected]).

Forecasting using R Conclusion 45

Page 110: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Piazza

You should all have received an invitation tojoin the Piazza course page.

All discussion and distribution of informationoutside of classes will take place there.

Homework available there.

Session slides available there after eachsession.

Please ask questions there.

If you haven’t received an invitation, or arehaving trouble, please ask James to help([email protected]).

Forecasting using R Conclusion 45

Page 111: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Piazza

You should all have received an invitation tojoin the Piazza course page.

All discussion and distribution of informationoutside of classes will take place there.

Homework available there.

Session slides available there after eachsession.

Please ask questions there.

If you haven’t received an invitation, or arehaving trouble, please ask James to help([email protected]).

Forecasting using R Conclusion 45

Page 112: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Piazza

You should all have received an invitation tojoin the Piazza course page.

All discussion and distribution of informationoutside of classes will take place there.

Homework available there.

Session slides available there after eachsession.

Please ask questions there.

If you haven’t received an invitation, or arehaving trouble, please ask James to help([email protected]).

Forecasting using R Conclusion 45

Page 113: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Piazza

You should all have received an invitation tojoin the Piazza course page.

All discussion and distribution of informationoutside of classes will take place there.

Homework available there.

Session slides available there after eachsession.

Please ask questions there.

If you haven’t received an invitation, or arehaving trouble, please ask James to help([email protected]).

Forecasting using R Conclusion 45

Page 114: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Homework

There will be a homework sheet available foreach session to give you practice with theconcepts introduced.

Please try to do each sheet before the nextsession.

I will post answers on Piazza.

Forecasting using R Conclusion 46

Page 115: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Homework

There will be a homework sheet available foreach session to give you practice with theconcepts introduced.

Please try to do each sheet before the nextsession.

I will post answers on Piazza.

Forecasting using R Conclusion 46

Page 116: Forecasting using - Rob J Hyndman · PDF fileOTexts.com/fpp/2/3 Forecasting using R 1 Rob J Hyndman. Outline ... for forecasting sales for my company. ... part of my job

Homework

There will be a homework sheet available foreach session to give you practice with theconcepts introduced.

Please try to do each sheet before the nextsession.

I will post answers on Piazza.

Forecasting using R Conclusion 46