TIME SERIES FORECASTING WITH R -...

145
TIME SERIES FORECASTING WITH TIME SERIES FORECASTING WITH R: from CLASSICAL CLASSICAL to MODERN Methods MODERN Methods 2 Days Workshop Faculty of MIPA, UNIVERSITAS ANDALAS PADANG & INSTITUT TEKNOLOGI SEPULUH NOPEMBER Suhartono (B.Sc.-ITS; M.Sc.-UMIST,UK; Dr.-UGM; Postdoctoral-UTM) Department of Statistics, Institut Teknologi Sepuluh Nopember, Indonesia Email: [email protected], [email protected] Department of Mathematics, Universitas Andalas, Padang 17-18 July 2017

Transcript of TIME SERIES FORECASTING WITH R -...

Page 1: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

TIME SERIES FORECASTING WITHTIME SERIES FORECASTING WITH RR:from CLASSICALCLASSICAL to MODERN MethodsMODERN Methods

2 Days WorkshopFaculty of MIPA, UNIVERSITAS ANDALAS PADANG

& INSTITUT TEKNOLOGI SEPULUH NOPEMBER

Suhartono(B.Sc.-ITS; M.Sc.-UMIST,UK; Dr.-UGM; Postdoctoral-UTM)

Department of Statistics,Institut Teknologi Sepuluh Nopember, Indonesia

Email: [email protected], [email protected]

Department of Mathematics, Universitas Andalas, Padang17-18 July 2017

Page 2: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

TIME SERIES FORECASTING WITHTIME SERIES FORECASTING WITH RR::from CLASSICALCLASSICAL to MODERN MethodsMODERN Methods

2 Days WorkshopFaculty of MIPA, UNIVERSITAS ANDALAS PADANG

& INSTITUT TEKNOLOGI SEPULUH NOPEMBER

Department of Mathematics, Universitas Andalas, Padang17-18 July 2017

Page 3: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

25 years of time series forecastingDe Gooijer & Hyndman (International Journal of Forecasting, 2006)

1980

2005

3

1980

2005

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 4: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MotivationThe M3-Competition: results, conclusions

and implications(1) Statistically sophisticated or complex methods do not

necessarily provide more accurate forecasts than simpler ones.(2) The relative ranking of the performance of the various

methods varies according to the accuracy measure being used.(3) The accuracy when various methods are being combined

outperforms, on average, the individual methods beingcombined and does very well in comparison to other methods.

(4) The accuracy of the various methods depends upon the lengthof the forecasting horizon involved.

Makridakis & Hibon (International Journal of Forecasting, 2000)

4

The M3-Competition: results, conclusionsand implications

(1) Statistically sophisticated or complex methods do notnecessarily provide more accurate forecasts than simpler ones.

(2) The relative ranking of the performance of the variousmethods varies according to the accuracy measure being used.

(3) The accuracy when various methods are being combinedoutperforms, on average, the individual methods beingcombined and does very well in comparison to other methods.

(4) The accuracy of the various methods depends upon the lengthof the forecasting horizon involved.

Makridakis & Hibon (International Journal of Forecasting, 2000)

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 5: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Material1. Time Series Regression (TSR) & ARIMA model

Seasonal models: Multiplicative, Additive, Subset Multiple Seasonal models.

2. ARIMAX & Multivariate Time Series Model Intervention Model & Outlier Detection Calendar Variation Model, Transfer Function Model.

3. Nonlinear Time Series (Modern) Models Non-linearity test, Neural Networks.

4. Hybrid Models TSR-NN, ARIMA-NN, ARIMAX-NN.

5

1. Time Series Regression (TSR) & ARIMA model Seasonal models: Multiplicative, Additive, Subset Multiple Seasonal models.

2. ARIMAX & Multivariate Time Series Model Intervention Model & Outlier Detection Calendar Variation Model, Transfer Function Model.

3. Nonlinear Time Series (Modern) Models Non-linearity test, Neural Networks.

4. Hybrid Models TSR-NN, ARIMA-NN, ARIMAX-NN.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 6: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Reference1. Armstrong, J.S. (2002)

Principles of Forecasting: A Handbook for Researchers andPracticioners, Kluwer Academic Publisher.

2. Hanke, J.E. and Reitsch, A.G. (1995, 2005, 2008)Business Forecasting, 5th, 7th and 9th edition, Prentice Hall.

3. Bowerman, B.L. and O’Connell, R.T. (1993, 2004)Forecasting and Time Series: An Applied Approach,3rd and 4th edition, Duxbury Press: USA.

4. Makridakis, S., Wheelwright, S. C. and Hyndman, R. J. (1998)Forecasting: Method and Applications, New York: Wiley & Sons.

5. Wei, W.W.S. (1990, 2006)Time Series Analysis: Univariate and Multivariate MethodsAddison-Wesley Publishing Co., USA.

6

1. Armstrong, J.S. (2002)Principles of Forecasting: A Handbook for Researchers andPracticioners, Kluwer Academic Publisher.

2. Hanke, J.E. and Reitsch, A.G. (1995, 2005, 2008)Business Forecasting, 5th, 7th and 9th edition, Prentice Hall.

3. Bowerman, B.L. and O’Connell, R.T. (1993, 2004)Forecasting and Time Series: An Applied Approach,3rd and 4th edition, Duxbury Press: USA.

4. Makridakis, S., Wheelwright, S. C. and Hyndman, R. J. (1998)Forecasting: Method and Applications, New York: Wiley & Sons.

5. Wei, W.W.S. (1990, 2006)Time Series Analysis: Univariate and Multivariate MethodsAddison-Wesley Publishing Co., USA.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 7: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

10 Scholars in Time Series

7 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 8: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

10 Scholars in Forecasting

8 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 9: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Indonesian Scholars in Time Series

9 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 10: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

UNAND Scholars in

10 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 11: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

UNAND Scholars in

11 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 12: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Hybrid Model in Time Series Forecasting

12 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 13: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Hybrid Model in Time Series Forecasting

13 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 14: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

“Padang” in Time Series Forecasting research

14 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 15: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

“Padang” in Time Series Forecasting research

15 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 16: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

“Padang” in Time Series Forecasting research

16 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 17: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

“Padang” in Time Series Forecasting research

17 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 18: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

“Padang” in Time Series Forecasting research

18 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 19: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

TIME SERIES FORECASTING WITHTIME SERIES FORECASTING WITH RR:from CLASSICALCLASSICAL to MODERN MethodsMODERN Methods

Page 20: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

DOUBLE SEASONAL ARIMA MODELWITH R, MINITAB AND SAS

2 Days WorkshopFaculty of MIPA, UNIVERSITAS ANDALAS PADANG

& INSTITUT TEKNOLOGI SEPULUH NOPEMBER

Suhartono(B.Sc.-ITS; M.Sc.-UMIST,UK; Dr.-UGM; Postdoctoral-UTM)

Department of Statistics,Institut Teknologi Sepuluh Nopember, Indonesia

Email: [email protected], [email protected]

Department of Mathematics, Universitas Andalas, Padang17-18 July 2017

Page 21: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Develop the best forecast ARIMA model for Short-term Electricity Load Data

MINITAB: Descriptive evaluation about thepattern of DOUBLE Seasonal Time Series Data

R: Theoretical ACF and PACF of DOUBLESeasonal ARIMA model

MINITAB:The Data: identification of stationary& tentative order of DOUBLE Seasonal ARIMA

SAS: Estimation & Diagnostic check. Discussion

Motivation Develop the best forecast ARIMA model for Short-

term Electricity Load Data MINITAB: Descriptive evaluation about the

pattern of DOUBLE Seasonal Time Series Data R: Theoretical ACF and PACF of DOUBLE

Seasonal ARIMA model MINITAB:The Data: identification of stationary

& tentative order of DOUBLE Seasonal ARIMA SAS: Estimation & Diagnostic check. Discussion

2 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 22: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Multiple Seasonal ARIMA models:Double Seasonal ARIMA,Triple Seasonal ARIMA model.

Review: DSARIMA - TSARIMA

3

Website: http://users.ox.ac.uk/~mast0315/

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 23: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction

KehlogKehlog AlbranAlbran“The Profit (1973)”

I have seen the futureand it is just like the present,

only longer.

4

KehlogKehlog AlbranAlbran“The Profit (1973)”

I have seen the futureand it is just like the present,

only longer.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 24: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Problem: Prediction of half hourly load data

5 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 25: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Descriptive: half hourly load data

6 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 26: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Descriptive: half hourly load data

7 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 27: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Descriptive: half hourly load data

8 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 28: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Identification: half hourly load data

9 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 29: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Identification: half hourly load data

10 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 30: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Identification: half hourly load data

11 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 31: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Identification: half hourly load data

12 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 32: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Identification: half hourly load data

13 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 33: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Identification: half hourly load data

14 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 34: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Identification: half hourly load data

15 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 35: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

MINITAB Identification: half hourly load data

16 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 36: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

ARIMA, SARIMA, DSARIMA model

o ARIMA model

o SARIMA model

tqtd

p aBZBB 01

ts

QqtDsds

Pp aBBZBBBB )()()1()1)(()(

17

o DSARIMA model

ts

QqtDsds

Pp aBBZBBBB )()()1()1)(()(

tDsDsds

Ps

Pp ZBBBBBB 22112

2

1

1)1()1()1)(()()(

ts

Qs

Qq aBBB )()()( 22

11

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 37: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

ACF of SARIMA modelo SARIMA(0,0,1)(0,0,1)24 model

others.,0

,24,)1(

,25and23,)1)(1(

,1,)1(

,0,1

224

24

224

21

241

21

1

k

k

k

k

k

k

18

others.,0

,24,)1(

,25and23,)1)(1(

,1,)1(

,0,1

224

24

224

21

241

21

1

k

k

k

k

k

k

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 38: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

ACF ofD

SAR

IMA

model

oD

SARIMA(0,0,1)(0,0,1) 24(0,0,1) 168

.others0,

,192,)1)(1(

,168,)1)(1)(1(

)1(

,169and167,)1)(1(

,144,)1)(1)(1(

193,and191,145,143,)1)(1)(1(

,24,)1(

,25and23,)1)(1(

,1,)1(

,0,1

2168

224

16824

2168

224

21

224

21

224168

2168

21

1681

2168

224

21

16824

2168

224

21

168241

224

24

224

21

241

21

1

k

k

k

k

k

k

k

k

k

k

k

19

ACF ofD

SAR

IMA

model

oD

SARIMA(0,0,1)(0,0,1) 24(0,0,1) 168

.others0,

,192,)1)(1(

,168,)1)(1)(1(

)1(

,169and167,)1)(1(

,144,)1)(1)(1(

193,and191,145,143,)1)(1)(1(

,24,)1(

,25and23,)1)(1(

,1,)1(

,0,1

2168

224

16824

2168

224

21

224

21

224168

2168

21

1681

2168

224

21

16824

2168

224

21

168241

224

24

224

21

241

21

1

k

k

k

k

k

k

k

k

k

k

k

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 39: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

R script: ACF of SARIMAo SARIMA(0,0,1)(0,0,1)24 model

# Program to calculate ACF and PACF theoreticallytheta = c(-0.6,rep(0,22),-0.5,0.3)acf.arma = ARMAacf(ar=0, ma=theta, 168)pacf.arma = ARMAacf(ar=0, ma=theta, 168, pacf=T)acf.arma = acf.arma[2:169]c1 = acf.armac2 = pacf.armaarma = cbind(c1, c2)arma # ACF and PACF theoreticallypar(mfrow=c(1,2))plot(acf.arma, type="h", xlab="lag", ylim=c(-1,1))abline(h=0)plot(pacf.arma, type="h", xlab="lag", ylim=c(-1,1))abline(h=0)

20

# Program to calculate ACF and PACF theoreticallytheta = c(-0.6,rep(0,22),-0.5,0.3)acf.arma = ARMAacf(ar=0, ma=theta, 168)pacf.arma = ARMAacf(ar=0, ma=theta, 168, pacf=T)acf.arma = acf.arma[2:169]c1 = acf.armac2 = pacf.armaarma = cbind(c1, c2)arma # ACF and PACF theoreticallypar(mfrow=c(1,2))plot(acf.arma, type="h", xlab="lag", ylim=c(-1,1))abline(h=0)plot(pacf.arma, type="h", xlab="lag", ylim=c(-1,1))abline(h=0)

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 40: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

R script: ACF of SARIMAo SARIMA(0,0,1)(0,0,1)24(0,0,1)168 model

# Program to calculate ACF and PACF theoreticallytheta = c(-0.6,rep(0,22),-0.5,0.3,rep(0,143),-0.4,0.24,rep(0,12),0.2,-0.12)acf.arma = ARMAacf(ar=0, ma=theta, 200)pacf.arma = ARMAacf(ar=0, ma=theta, 200, pacf=T)acf.arma = acf.arma[2:201]c1 = acf.armac2 = pacf.armaarma = cbind(c1, c2)arma # ACF and PACF theoreticallypar(mfrow=c(1,2))plot(acf.arma, type="h", xlab="lag", ylim=c(-1,1))abline(h=0)plot(pacf.arma, type="h", xlab="lag", ylim=c(-1,1))abline(h=0)

21

# Program to calculate ACF and PACF theoreticallytheta = c(-0.6,rep(0,22),-0.5,0.3,rep(0,143),-0.4,0.24,rep(0,12),0.2,-0.12)acf.arma = ARMAacf(ar=0, ma=theta, 200)pacf.arma = ARMAacf(ar=0, ma=theta, 200, pacf=T)acf.arma = acf.arma[2:201]c1 = acf.armac2 = pacf.armaarma = cbind(c1, c2)arma # ACF and PACF theoreticallypar(mfrow=c(1,2))plot(acf.arma, type="h", xlab="lag", ylim=c(-1,1))abline(h=0)plot(pacf.arma, type="h", xlab="lag", ylim=c(-1,1))abline(h=0)

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 41: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

R: the result - ACF of DSARIMAo SARIMA(0,0,1)(0,0,1)24(0,0,1)168 model with

1=0.8,24 =0.65, and168=0.45

0 100 200 300 400

-1.0-0.5

0.00.5

1.0

lag

acf.arm

a

22

0 100 200 300 400

-1.0-0.5

0.00.5

1.0

lag

acf.arm

a

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 42: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

R: the result - PACF of DSARIMAo SARIMA(0,0,1)(0,0,1)24(0,0,1)168 model with

1=0.8,24 =0.65, and168=0.45

0 100 200 300 400

-1.0

-0.5

0.00.5

1.0

lag

pacf.a

rma

23

0 100 200 300 400

-1.0

-0.5

0.00.5

1.0

lag

pacf.a

rma

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 43: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

R: the result - ACF of DSARIMAo SARIMA(1,0,0)(1,0,0)24(1,0,0)168 model with

1=0.7,24 =0.4, and168=0.8

0 100 200 300 400

-1.0

-0.5

0.00.5

1.0

lag

acf.ar

ma

24

0 100 200 300 400

-1.0

-0.5

0.00.5

1.0

lag

acf.ar

ma

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 44: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

R: the result - PACF of DSARIMAo SARIMA(1,0,0)(1,0,0)24(1,0,0)168 model with

1=0.7,24 =0.4, and168=0.8

0 100 200 300 400

-1.0

-0.5

0.00.5

1.0

lag

pacf.a

rma

25

0 100 200 300 400

-1.0

-0.5

0.00.5

1.0

lag

pacf.a

rma

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 45: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

SAS Program: Estimation DSARIMAdata listrik;

input y;cards;12123.6...11947.8;proc arima data=listrik out=b1;

/*** IDENTIFICATION Step ***/identify var=y(1,48,336) nlag=12;run;/*** PARAMETER ESTIMATION & DIAGNOSTIC CHECK Step ***/estimate p=(5,8) q=(1)(24)(168) noconstant;run;/*** FORECASTING Step ***/forecast lead=336 out=b2 noprint;run;

26

data listrik;input y;

cards;12123.6...11947.8;proc arima data=listrik out=b1;

/*** IDENTIFICATION Step ***/identify var=y(1,48,336) nlag=12;run;/*** PARAMETER ESTIMATION & DIAGNOSTIC CHECK Step ***/estimate p=(5,8) q=(1)(24)(168) noconstant;run;/*** FORECASTING Step ***/forecast lead=336 out=b2 noprint;run;

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 46: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

SAS Program: Estimation DSARIMAproc arima data=listrik out=b1;

/*** IDENTIFICATION Step ***/identify var=y(1,48,336) nlag=12;run;/*** PARAMETER ESTIMATION & DIAGNOSTIC CHECK Step ***/estimate p=(5,8) q=(1)(24)(168) noconstant;run;/*** FORECASTING Step ***/forecast lead=336 out=b2 noprint;run;

proc export data= work.b2outfile= "D:\results1.xls"dbms=excel2000 replace;

sheet="om_41";run;

27

proc arima data=listrik out=b1;/*** IDENTIFICATION Step ***/identify var=y(1,48,336) nlag=12;run;/*** PARAMETER ESTIMATION & DIAGNOSTIC CHECK Step ***/estimate p=(5,8) q=(1)(24)(168) noconstant;run;/*** FORECASTING Step ***/forecast lead=336 out=b2 noprint;run;

proc export data= work.b2outfile= "D:\results1.xls"dbms=excel2000 replace;

sheet="om_41";run;

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 47: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

This paper shows that R, MINITAB and SAS must beused comprehensively for model building ofDSARIMA from certain time series data.

R: To calculate the theoretical ACF and PACF fromDOUBLE Seasonal ARIMA models

MINITAB: Descriptive evaluation & Identification step.

SAS: Parameter Estimation, Diagnostic check, andForecasting steps.

Conclusion This paper shows that R, MINITAB and SAS must be

used comprehensively for model building ofDSARIMA from certain time series data.

R: To calculate the theoretical ACF and PACF fromDOUBLE Seasonal ARIMA models

MINITAB: Descriptive evaluation & Identification step.

SAS: Parameter Estimation, Diagnostic check, andForecasting steps.

28 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 48: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Two Levels Regression Modeling of TradingTrading DayDayand HolidayHoliday EffectsEffects for Forecasting Retail Data

2 Days WorkshopFaculty of MIPA, UNIVERSITAS ANDALAS PADANG

& INSTITUT TEKNOLOGI SEPULUH NOPEMBER

Suhartono(B.Sc.-ITS; M.Sc.-UMIST,UK; Dr.-UGM; Postdoctoral-UTM)

Department of Statistics,Institut Teknologi Sepuluh Nopember, Indonesia

Email: [email protected], [email protected]

Department of Mathematics, Universitas Andalas, Padang17-18 July 2017

Page 49: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Outline• Introduction: General time series “pattern”• The aims of this paper: Develop two levels calendar

variation model• Data: Monthly men’s jeans and women's trousers sales in

a retail company• Modeling method: Based on time series regression• Results, analysis and evaluation: forecast accuracy• Conclusion and future works

2

• Introduction: General time series “pattern”• The aims of this paper: Develop two levels calendar

variation model• Data: Monthly men’s jeans and women's trousers sales in

a retail company• Modeling method: Based on time series regression• Results, analysis and evaluation: forecast accuracy• Conclusion and future works

2Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 50: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction

General time series “PATTERN” Stationer Trend: linear & nonlinear Seasonal: additive & multiplicative Cyclic CalendarVariation

3

General time series “PATTERN” Stationer Trend: linear & nonlinear Seasonal: additive & multiplicative Cyclic CalendarVariation

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 51: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introductiono Two kinds of calendar variation effects:

1. Trading day effectsThe levels of economics or business activities may changedepending on the day of the week. The composition of daysof the week varies from month to month and year to year.

2. Holiday (traditional festivals) effectsSome traditional festivals or holidays, such as Eid ul-Fitr, Easter,Chinese New Year, and Jewish Passover are set according tolunar calendars and the dates of such holidays may vary betweentwo adjacent months in the Gregorian calendar from year toyear.

cont’

4

o Two kinds of calendar variation effects:1. Trading day effects

The levels of economics or business activities may changedepending on the day of the week. The composition of daysof the week varies from month to month and year to year.

2. Holiday (traditional festivals) effectsSome traditional festivals or holidays, such as Eid ul-Fitr, Easter,Chinese New Year, and Jewish Passover are set according tolunar calendars and the dates of such holidays may vary betweentwo adjacent months in the Gregorian calendar from year toyear.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 52: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction cont’

YearMonth

20092008200720062005200420032002JanJanJanJanJanJanJanJan

2.0

1.5

1.0

0.5

0.0

Unit

sale

s(T

hous

ands

)

Dec '02 Nov '03 Nov '04 Nov '05 Oct '06 Oct '07 Oct '08 Sep '09

(a). Y1: Men's jeans sales in Boyolali shop

11

11

1110

10

10 9 9

5

YearMonth

20092008200720062005200420032002JanJanJanJanJanJanJanJan

2.0

1.5

1.0

0.5

0.0

Unit

sale

s(T

hous

ands

)

Dec '02 Nov '03 Nov '04 Nov '05 Oct '06 Oct '07 Oct '08 Sep '09

(a). Y1: Men's jeans sales in Boyolali shop

10 9 9

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 53: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction cont’

Eid holidays for the period 2002 to 2011

6 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 54: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction cont’

YearMonth

20092008200720062005200420032002JanJanJanJanJanJanJanJan

2.0

1.5

1.0

0.5

0.0

Unit

sale

s(T

hous

ands

)

Dec '02 Nov '03 Nov '04 Nov '05 Oct '06 Oct '07 Oct '08 Sep '09

(b). Y2: Women's trouser sales in Boyolali shop

11

11

11

10 10 10

99

7

YearMonth

20092008200720062005200420032002JanJanJanJanJanJanJanJan

2.0

1.5

1.0

0.5

0.0

Unit

sale

s(T

hous

ands

)

Dec '02 Nov '03 Nov '04 Nov '05 Oct '06 Oct '07 Oct '08 Sep '09

(b). Y2: Women's trouser sales in Boyolali shop

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 55: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction cont’

8 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 56: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

The aims

To develop two levels calendar variation modelbased on time series regression method forforecasting sales data with the Eid ul-Fitr effects.

To compare the forecast accuracy with otherforecasting methods, i.e.o ARIMA modelo Feed-forward Neural Networks (FFNN)

9

To develop two levels calendar variation modelbased on time series regression method forforecasting sales data with the Eid ul-Fitr effects.

To compare the forecast accuracy with otherforecasting methods, i.e.o ARIMA modelo Feed-forward Neural Networks (FFNN)

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 57: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Modeling method

Model for linear trend:… (1)

Regression with dummy variable for seasonal pattern:… (2)

Regression for calendar effects:

… (3)

10

Model for linear trend:… (1)

Regression with dummy variable for seasonal pattern:… (2)

Regression for calendar effects:

… (3)

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 58: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

The Proposed Model

Model at the first level :

Model at the second level :1. Linear model 2. Exponential model

11

Model at the first level :

Model at the second level :1. Linear model 2. Exponential model

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 59: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Background of Two LevelsLinear

illustrationLinear

illustration

12 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 60: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Dummy at Two Levels

13 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 61: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

The proposed procedureStep 1: Determination of dummy variable for calendar variation period.Step 2: Determination of deterministic trend and seasonal model.Step 3: Simultaneous estimation of calendar effects and other patterns.Step 4: Diagnostic checks on error model. If error is not white noise, add

significant lags (autoregressive order) based on ACF and PACFplots of error model.

Step 5: Re-estimate calendar effect, other pattern (trend, seasonal), andappropriate lags (autoregressive order) simultaneously for the firstlevel model.

Step 6: Estimate the second level model to predict the effects of calendarvariation in every possibility number of days before Eid ul-Fitrcelebration.

14

Step 1: Determination of dummy variable for calendar variation period.Step 2: Determination of deterministic trend and seasonal model.Step 3: Simultaneous estimation of calendar effects and other patterns.Step 4: Diagnostic checks on error model. If error is not white noise, add

significant lags (autoregressive order) based on ACF and PACFplots of error model.

Step 5: Re-estimate calendar effect, other pattern (trend, seasonal), andappropriate lags (autoregressive order) simultaneously for the firstlevel model.

Step 6: Estimate the second level model to predict the effects of calendarvariation in every possibility number of days before Eid ul-Fitrcelebration.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 62: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Step 1 Based on the time series plot, two dummy variables are used

for evaluating calendar variation effect, i.e.

The months prior to Eid ul Fitr,DDj,tj,t--11 = dummy variable for ONE month prior to Eid

ul-Fitr celebration. During the month of Eid ul-Fitr celebration,DDj,tj,t = dummy variable for during the month of Eid

ul-Fitr celebration.o j = number of days before Eid ul-Fitr celebration

15

Based on the time series plot, two dummy variables are usedfor evaluating calendar variation effect, i.e.

The months prior to Eid ul Fitr,DDj,tj,t--11 = dummy variable for ONE month prior to Eid

ul-Fitr celebration. During the month of Eid ul-Fitr celebration,DDj,tj,t = dummy variable for during the month of Eid

ul-Fitr celebration.o j = number of days before Eid ul-Fitr celebration

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 63: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Step 2 -3

Model for linear trend:

Regression with dummy variable for seasonal pattern:

Regression for calendar effects and other patterns:

16

Model for linear trend:

Regression with dummy variable for seasonal pattern:

Regression for calendar effects and other patterns:

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 64: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Step 4-6

Model at the first level :

Model at the second level :1. Linear model 2. Exponential model

17

Model at the first level :

Model at the second level :1. Linear model 2. Exponential model

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 65: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Results: monthly sales of men’s jeans

18 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 66: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Results: monthly sales of women’s trouser

19 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 67: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Results: monthly sales of women’s trouser

2520151050

1.50

1.25

1.00

0.75

0.50

j

alph

a(j)

1st level2nd level 'linear'2nd level 'exponential'

Variable

2520151050

1.4

1.2

1.0

0.8

0.6

0.4

0.2

0.0

j

gam

ma(

j)

1st level2nd level 'linear'2nd level 'exponential'

Variable

20

2520151050

1.50

1.25

1.00

0.75

0.50

j

alph

a(j)

1st level2nd level 'linear'2nd level 'exponential'

Variable

2520151050

1.4

1.2

1.0

0.8

0.6

0.4

0.2

0.0

j

gam

ma(

j)

1st level2nd level 'linear'2nd level 'exponential'

Variable

Fig. 3. The fitted line of the second level model regression in Eq.(13a)-(14b) for monthly sales of women’s trouser data

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 68: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

ResultsMethod

Y1,t = men’s jeans Y2,t = women trouserin-sample out-sample in-sample out-sample

ARIMA 0.1408 0.2634 0.1685 0.4235FFNN: no skip layer3-1-13-2-13-3-1…

3-9-13-10-1

0.11880.08090.0786

…0.07090.0894

0.38474.34660.3375

…11.76765.6064

0.08450.07410.0657

…0.05510.0598

0.32900.38440.2789

…1.7997

10.6219

21

FFNN: no skip layer3-1-13-2-13-3-1…

3-9-13-10-1

0.11880.08090.0786

…0.07090.0894

0.38474.34660.3375

…11.76765.6064

0.08450.07410.0657

…0.05510.0598

0.32900.38440.2789

…1.7997

10.6219FFNN: with skip layer3-1-13-2-13-3-1…

3-9-13-10-1

0.11480.08090.0708

…0.12450.1087

0.41590.56590.6290

…2.6E+011.9E+07

0.08890.07100.0663

…0.06160.0561

0.32730.33830.2855

…2.6E+018.2E+01

Two levels regression2nd: linear model2nd: exponential model

0.06860.24340.2424

0.05100.15080.0929

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 69: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Graphical Results

YearMonth

2011201020092008JanJanJanJan

1.2

1.0

0.8

0.6

0.4

0.2

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 10/11 Sep 1021/22 Sep 09 30/31 Aug 11

ActualARIMA

V ariable

(a2). ARIMA method

22

YearMonth

2011201020092008JanJanJanJan

1.2

1.0

0.8

0.6

0.4

0.2

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 10/11 Sep 1021/22 Sep 09 30/31 Aug 11

ActualARIMA

V ariable

(a2). ARIMA method

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 70: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Graphical Results

YearMonth

2011201020092008JanJanJanJan

2.8

2.4

2.0

1.6

1.2

0.8

0.4

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 Sep/2009 Sep/2010 Aug/2011

ActualNN:3-3-1

V ariable

(b2). Neural Networks method

23

YearMonth

2011201020092008JanJanJanJan

2.8

2.4

2.0

1.6

1.2

0.8

0.4

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 Sep/2009 Sep/2010 Aug/2011

ActualNN:3-3-1

V ariable

(b2). Neural Networks method

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 71: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Graphical Results

YearMonth

2011201020092008JanJanJanJan

2.0

1.5

1.0

0.5

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 21/22 Sep 09 10/11 Sep 10 30/31 Aug 11

ActualTS Regression

V ariable

(c2). Time Series Regression method

24

YearMonth

2011201020092008JanJanJanJan

2.0

1.5

1.0

0.5

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 21/22 Sep 09 10/11 Sep 10 30/31 Aug 11

ActualTS Regression

V ariable

(c2). Time Series Regression method

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 72: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Conclusion The proposed two levels calendar variation model based on

time series regression yield better prediction for out-sampledata, compared to those of ARIMA model and neuralnetworks.

The application of ARIMA model usually yield spuriousresults, particularly about seasonal pattern and the presenceof outliers.

Whereas, neural networks perform well only for in-sampledata.

25

The proposed two levels calendar variation model based ontime series regression yield better prediction for out-sampledata, compared to those of ARIMA model and neuralnetworks.

The application of ARIMA model usually yield spuriousresults, particularly about seasonal pattern and the presenceof outliers.

Whereas, neural networks perform well only for in-sampledata.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 73: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

References1. Alagidede, P. (2008a). Day of the week seasonality in African stock markets. Applied Financial Economics

Letters, 4, 115-120.

2. Alagidede, P. (2008b). Month-of-the-year and pre-holiday seasonality in African stock markets. StirlingEconomics Discussion Paper 2008-23, Department of Economics, University of Stirling.

3. Al-Khazali, O.M., Koumanakos, E.P., & Pyun, C.S. (2008). Calendar anomaly in the Greek stock market:Stochastic dominance analysis. International Review of Financial Analysis, 17, 461–474.

4. Ariel, R.A. (1990). High Stock Returns before Holidays: Existence and Evidence on Possible Causes. TheJournal of Finance, 45(5), 1611-1626.

5. Balaban, E. (1995). Day of the week effects: new evidence from an emerging stock market. Applied EconomicsLetters, 2, 139-143.

6. Bell, W.R., & Hillmer, S.C. (1983). Modeling Time Series with Calendar Variation. Journal of the AmericanStatistical Association, 78, 526-534.

7. Brockman, P., & Michayluk, D. (1998). The Persistent Holiday Effect: Additional Evidence. Applied EconomicsLetters, 5, 205-209.

8. Brooks, C., & Persand, G. (2001). Seasonality in Southeast Asian stock markets: some new evidence on day-of-the week effects. Applied Economics Letters, 8, 155-158.

26

1. Alagidede, P. (2008a). Day of the week seasonality in African stock markets. Applied Financial EconomicsLetters, 4, 115-120.

2. Alagidede, P. (2008b). Month-of-the-year and pre-holiday seasonality in African stock markets. StirlingEconomics Discussion Paper 2008-23, Department of Economics, University of Stirling.

3. Al-Khazali, O.M., Koumanakos, E.P., & Pyun, C.S. (2008). Calendar anomaly in the Greek stock market:Stochastic dominance analysis. International Review of Financial Analysis, 17, 461–474.

4. Ariel, R.A. (1990). High Stock Returns before Holidays: Existence and Evidence on Possible Causes. TheJournal of Finance, 45(5), 1611-1626.

5. Balaban, E. (1995). Day of the week effects: new evidence from an emerging stock market. Applied EconomicsLetters, 2, 139-143.

6. Bell, W.R., & Hillmer, S.C. (1983). Modeling Time Series with Calendar Variation. Journal of the AmericanStatistical Association, 78, 526-534.

7. Brockman, P., & Michayluk, D. (1998). The Persistent Holiday Effect: Additional Evidence. Applied EconomicsLetters, 5, 205-209.

8. Brooks, C., & Persand, G. (2001). Seasonality in Southeast Asian stock markets: some new evidence on day-of-the week effects. Applied Economics Letters, 8, 155-158.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 74: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

References9. Cleveland, W.S. & Devlin, S.J. (1980). Calendar Effects in Monthly Time Series: Detection by Spectrum

Analysis and Graphical Methods. Journal of the American Statistical Association, 75(371), 487-496.

10. Cleveland, W.S. & Devlin, S.J. (1982). Calendar Effects in Monthly Time Series: Modeling and Adjustment.Journal of the American Statistical Association, 77(379), 520-528.

11. Evans, K.P., & Speight, A.E.H. (2010). Intraday periodicity, calendar and announcement effects in Euroexchange rate volatility. Research in International Business and Finance, 24, 82-101.

12. Faraway, J., & Chatfield, C. (1998). Time series forecasting with neural networks: a comparative study usingthe airline data. Applied Statistics, 47, 231-250.

13. Gao, L., & Kling, G. (2005). Calendar Effects in Chinese Stock Market. Annals of Economics and Finance, 6,75-88.

14. Hillmer, S.C. (1982). Forecasting Time Series with Trading Day Variation. Journal of Forecasting, 1, 385-395.

15. Holden, K., Thompson, J., & Ruangrit, Y. (2005). The Asian crisis and calendar effects on stock returns inThailand. European Journal of Operational Research, 163, 242–252.

16. Liu, L.M. (1980). Analysis of Time Series with Calendar Effects. Management Science, 2, 106-112.

27

9. Cleveland, W.S. & Devlin, S.J. (1980). Calendar Effects in Monthly Time Series: Detection by SpectrumAnalysis and Graphical Methods. Journal of the American Statistical Association, 75(371), 487-496.

10. Cleveland, W.S. & Devlin, S.J. (1982). Calendar Effects in Monthly Time Series: Modeling and Adjustment.Journal of the American Statistical Association, 77(379), 520-528.

11. Evans, K.P., & Speight, A.E.H. (2010). Intraday periodicity, calendar and announcement effects in Euroexchange rate volatility. Research in International Business and Finance, 24, 82-101.

12. Faraway, J., & Chatfield, C. (1998). Time series forecasting with neural networks: a comparative study usingthe airline data. Applied Statistics, 47, 231-250.

13. Gao, L., & Kling, G. (2005). Calendar Effects in Chinese Stock Market. Annals of Economics and Finance, 6,75-88.

14. Hillmer, S.C. (1982). Forecasting Time Series with Trading Day Variation. Journal of Forecasting, 1, 385-395.

15. Holden, K., Thompson, J., & Ruangrit, Y. (2005). The Asian crisis and calendar effects on stock returns inThailand. European Journal of Operational Research, 163, 242–252.

16. Liu, L.M. (1980). Analysis of Time Series with Calendar Effects. Management Science, 2, 106-112.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 75: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Two Levels ARIMAX and Regression Modelsfor Forecasting Time Series Datawith Calendar Variation Effects

2 Days WorkshopFaculty of MIPA, UNIVERSITAS ANDALAS PADANG

& INSTITUT TEKNOLOGI SEPULUH NOPEMBER

Suhartono(B.Sc.-ITS; M.Sc.-UMIST,UK; Dr.-UGM; Postdoctoral-UTM)

Department of Statistics,Institut Teknologi Sepuluh Nopember, Indonesia

Email: [email protected], [email protected]

Department of Mathematics, Universitas Andalas, Padang17-18 July 2017

Page 76: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Outline• Introduction: General time series “pattern”• The aims of this paper: Develop two levels calendar

variation model• Data: Monthly men’s jeans and women's trousers sales

in a retail company• Modeling method: Based on ARIMAX and Regression• Results, analysis and evaluation: forecast accuracy• Conclusion and future works

2

• Introduction: General time series “pattern”• The aims of this paper: Develop two levels calendar

variation model• Data: Monthly men’s jeans and women's trousers sales

in a retail company• Modeling method: Based on ARIMAX and Regression• Results, analysis and evaluation: forecast accuracy• Conclusion and future works

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 77: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction

General time series “PATTERN” Stationer Trend: linear & nonlinear Seasonal: additive & multiplicative Cyclic CalendarVariation

3

General time series “PATTERN” Stationer Trend: linear & nonlinear Seasonal: additive & multiplicative Cyclic CalendarVariation

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 78: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introductiono Two kinds of calendar variation effects:

1. Trading day effectsThe levels of economics or business activities may changedepending on the day of the week. The composition of daysof the week varies from month to month and year to year.

2. Holiday (traditional festivals) effectsSome traditional festivals or holidays, such as Eid ul-Fitr, Easter,Chinese New Year, and Jewish Passover are set according tolunar calendars and the dates of such holidays may vary betweentwo adjacent months in the Gregorian calendar from year toyear.

cont’

4

o Two kinds of calendar variation effects:1. Trading day effects

The levels of economics or business activities may changedepending on the day of the week. The composition of daysof the week varies from month to month and year to year.

2. Holiday (traditional festivals) effectsSome traditional festivals or holidays, such as Eid ul-Fitr, Easter,Chinese New Year, and Jewish Passover are set according tolunar calendars and the dates of such holidays may vary betweentwo adjacent months in the Gregorian calendar from year toyear.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 79: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction cont’

YearMonth

20092008200720062005200420032002JanJanJanJanJanJanJanJan

2.0

1.5

1.0

0.5

0.0

Unit

sale

s(T

hous

ands

)

Dec '02 Nov '03 Nov '04 Nov '05 Oct '06 Oct '07 Oct '08 Sep '09

(a). Y1: Men's jeans sales in Boyolali shop

11

11

1110

10

10 9 9

5

YearMonth

20092008200720062005200420032002JanJanJanJanJanJanJanJan

2.0

1.5

1.0

0.5

0.0

Unit

sale

s(T

hous

ands

)

Dec '02 Nov '03 Nov '04 Nov '05 Oct '06 Oct '07 Oct '08 Sep '09

(a). Y1: Men's jeans sales in Boyolali shop

10 9 9

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 80: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction cont’

Eid holidays for the period 2002 to 2011

6 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 81: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

YearMonth

20092008200720062005200420032002JanJanJanJanJanJanJanJan

2.0

1.5

1.0

0.5

0.0

Unit

sale

s(T

hous

ands

)

Dec '02 Nov '03 Nov '04 Nov '05 Oct '06 Oct '07 Oct '08 Sep '09

(b). Y2: Women's trouser sales in Boyolali shop

11

11

11

10 10 10

99

Introduction cont’

7

YearMonth

20092008200720062005200420032002JanJanJanJanJanJanJanJan

2.0

1.5

1.0

0.5

0.0

Unit

sale

s(T

hous

ands

)

Dec '02 Nov '03 Nov '04 Nov '05 Oct '06 Oct '07 Oct '08 Sep '09

(b). Y2: Women's trouser sales in Boyolali shop

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 82: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Introduction cont’

8 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 83: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

The aims To develop two levels calendar variation model

based on ARIMAX and regression method forforecasting sales data with the Eid ul-Fitr effects.

To compare the forecast accuracy with otherforecasting methods, i.e.o ARIMA modelo Feed-forward Neural Networks (FFNN)o Two levels Time Series Regression

9

To develop two levels calendar variation modelbased on ARIMAX and regression method forforecasting sales data with the Eid ul-Fitr effects.

To compare the forecast accuracy with otherforecasting methods, i.e.o ARIMA modelo Feed-forward Neural Networks (FFNN)o Two levels Time Series Regression

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 84: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Modeling method Model for linear trend:

… (1)

Regression with dummy variable for seasonal pattern:… (2)

Regression for calendar effects:

… (3)

10

Model for linear trend:… (1)

Regression with dummy variable for seasonal pattern:… (2)

Regression for calendar effects:

… (3)

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 85: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

The Two Levels Regression Model

Model at the first level :

Model at the second level :1. Linear model 2. Exponential model

11

Model at the first level :

Model at the second level :1. Linear model 2. Exponential model

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 86: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

The PROPOSED Model Model at the first levelARIMAX-1: stochastic TREND-SEASONAL

Model at the first levelARIMAX-2: deterministic TREND-SEASONAL

Model at the second level : Linear model

12

Model at the first levelARIMAX-1: stochastic TREND-SEASONAL

Model at the first levelARIMAX-2: deterministic TREND-SEASONAL

Model at the second level : Linear model

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 87: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Background of Two LevelsLINEAR

illustrationLINEAR

illustration

13 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 88: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Dummy at Two Levels

14 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 89: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

The Proposed ProcedureStep 1: Determination of dummy variable for calendar variation period.Step 2: Remove the calendar variation effect form the response by fitting

for model with stochastic trend and seasonal model, or fitting

simultaneuously for model with deterministic trend and seasonal, toobtain the error, Nt.

Step 3: Find the best ARIMA model of Nt using Box-Jenkins procedure.Step 4: Simultaneously fit the model from step 2 and 3.This model is the first

level of calendar variation model based on ARIMAX method.Step 5: Test the significance of parameter and perform diagnostic check.Step 6: Estimate the second level model to predict the effects of calendar

variation in every possibility number of days before Eid ul-Fitr.

15

Step 1: Determination of dummy variable for calendar variation period.Step 2: Remove the calendar variation effect form the response by fitting

for model with stochastic trend and seasonal model, or fitting

simultaneuously for model with deterministic trend and seasonal, toobtain the error, Nt.

Step 3: Find the best ARIMA model of Nt using Box-Jenkins procedure.Step 4: Simultaneously fit the model from step 2 and 3.This model is the first

level of calendar variation model based on ARIMAX method.Step 5: Test the significance of parameter and perform diagnostic check.Step 6: Estimate the second level model to predict the effects of calendar

variation in every possibility number of days before Eid ul-Fitr.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 90: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Step 1 Based on the time series plot, TWO DUMMY VARIABLES

are used for evaluating calendar variation effect, i.e.

The months prior to Eid ul Fitr,Dj,t-1 = dummy variable for ONE month prior to Eid

ul-Fitr celebration. During the month of Eid ul-Fitr celebration,

Dj,t = dummy variable for during the month of Eidul-Fitr celebration.

o j = number of days before Eid ul-Fitr celebration

16

Based on the time series plot, TWO DUMMY VARIABLESare used for evaluating calendar variation effect, i.e.

The months prior to Eid ul Fitr,Dj,t-1 = dummy variable for ONE month prior to Eid

ul-Fitr celebration. During the month of Eid ul-Fitr celebration,

Dj,t = dummy variable for during the month of Eidul-Fitr celebration.

o j = number of days before Eid ul-Fitr celebration

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 91: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Step 2 - 6 Model at the first levelARIMAX-1: stochastic TREND-SEASONAL

Model at the first levelARIMAX-2: deterministic TREND-SEASONAL

Model at the second level : Linear model

17

Model at the first levelARIMAX-1: stochastic TREND-SEASONAL

Model at the first levelARIMAX-2: deterministic TREND-SEASONAL

Model at the second level : Linear model

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 92: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Results: monthly sales of men’s jeans

18 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 93: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Results: monthly sales of men’s jeans

19 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 94: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Results

20 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 95: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Graphical Results

YearMonth

2011201020092008JanJanJanJan

1.2

1.0

0.8

0.6

0.4

0.2

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 10/11 Sep 1021/22 Sep 09 30/31 Aug 11

ActualARIMA

V ariable

(a2). ARIMA method

21

YearMonth

2011201020092008JanJanJanJan

1.2

1.0

0.8

0.6

0.4

0.2

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 10/11 Sep 1021/22 Sep 09 30/31 Aug 11

ActualARIMA

V ariable

(a2). ARIMA method

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 96: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

YearMonth

2011201020092008JanJanJanJan

2.8

2.4

2.0

1.6

1.2

0.8

0.4

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 Sep/2009 Sep/2010 Aug/2011

ActualNN:3-3-1

V ariable

(b2). Neural Networks method

Graphical Results

22

YearMonth

2011201020092008JanJanJanJan

2.8

2.4

2.0

1.6

1.2

0.8

0.4

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 Sep/2009 Sep/2010 Aug/2011

ActualNN:3-3-1

V ariable

(b2). Neural Networks method

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 97: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

YearMonth

2011201020092008JanJanJanJan

2.0

1.5

1.0

0.5

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 21/22 Sep 09 10/11 Sep 10 30/31 Aug 11

ActualTS Regression

V ariable

(c2). Time Series Regression method

Graphical Results

23

YearMonth

2011201020092008JanJanJanJan

2.0

1.5

1.0

0.5

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 21/22 Sep 09 10/11 Sep 10 30/31 Aug 11

ActualTS Regression

V ariable

(c2). Time Series Regression method

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 98: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Graphical Results

YearMonth

2011201020092008JanJanJanJan

2.0

1.5

1.0

0.5

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 21/22 Sep 09 10/11 Sep 10 30/31 Aug 11

Actual1st ARIMAX

V ariable

(d2). The 1st ARIMAX method

24

YearMonth

2011201020092008JanJanJanJan

2.0

1.5

1.0

0.5

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 21/22 Sep 09 10/11 Sep 10 30/31 Aug 11

Actual1st ARIMAX

V ariable

(d2). The 1st ARIMAX method

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 99: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Graphical Results

YearMonth

2011201020092008JanJanJanJan

2.0

1.5

1.0

0.5

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 21/22 Sep 09 10/11 Sep 10 30/31 Aug 11

Actual2nd ARMAX

V ariable

(e2). The 2nd ARIMAX method

25

YearMonth

2011201020092008JanJanJanJan

2.0

1.5

1.0

0.5

0.0

Y1(T

hous

ands

unit)

1/2 Oct 08 21/22 Sep 09 10/11 Sep 10 30/31 Aug 11

Actual2nd ARMAX

V ariable

(e2). The 2nd ARIMAX method

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 100: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Conclusion The proposed two levels calendar variation model

based on ARIMAX and Regression method yield betterprediction for out-sample data, compared to those ofARIMA model and neural networks.

The application of ARIMA model usually yield spuriousresults, particularly about seasonal pattern and thepresence of outliers.

Whereas, Neural Networks perform well only for in-sample data.

26

The proposed two levels calendar variation modelbased on ARIMAX and Regression method yield betterprediction for out-sample data, compared to those ofARIMA model and neural networks.

The application of ARIMA model usually yield spuriousresults, particularly about seasonal pattern and thepresence of outliers.

Whereas, Neural Networks perform well only for in-sample data.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 101: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

References1. L.M. Liu, Analysis of Time Series with Calendar Effects, Management Science, 2, 106-112 (1980).

2. L.M. Liu, Identification of Time Series Models in the Presence of Calendar Variation, International Journalof Forecasting, 2, 357-372 (1986).

3. T.C. Mills and J.A. Coutts, Calendar effects in the London Stock Exchange FT-SE indices,The EuropeanJournal of Finance, 1, 79-93 (1995).

4. L.Gao and G. Kling, Calendar Effects in Chinese Stock Market,Annals of Economics and Finance, 6, 75-88(2005).

5. R. Sullivan, A.Timmermann and H.White, Dangers of data mining: The case of calendar effects in stockreturns, Journal of Econometrics, 105, 249-286 (2001).

6. F.J. Seyyed, A.Abraham and M. Al-Hajji, Seasonality in stock returns and volatility: The Ramadan effect,Research in International Business and Finance, 19, 374-383 (2005).

7. Suhartono and M.H. Lee, Two levels regression modeling of trading day and holiday effects for forecastingretail data, Proceeding The 7th IMT-GT International Conference on Mathematics, Statistics and itsApplications (ICMSA 2011), Bangkok, Thailand, pp. 150-164.

8. W.S. Cleveland and S.J. Devlin, Calendar Effects in Monthly Time Series: Detection by Spectrum Analysisand Graphical Methods, Journal of the American Statistical Association, 75(371), 487-496 (1980).

27

1. L.M. Liu, Analysis of Time Series with Calendar Effects, Management Science, 2, 106-112 (1980).

2. L.M. Liu, Identification of Time Series Models in the Presence of Calendar Variation, International Journalof Forecasting, 2, 357-372 (1986).

3. T.C. Mills and J.A. Coutts, Calendar effects in the London Stock Exchange FT-SE indices,The EuropeanJournal of Finance, 1, 79-93 (1995).

4. L.Gao and G. Kling, Calendar Effects in Chinese Stock Market,Annals of Economics and Finance, 6, 75-88(2005).

5. R. Sullivan, A.Timmermann and H.White, Dangers of data mining: The case of calendar effects in stockreturns, Journal of Econometrics, 105, 249-286 (2001).

6. F.J. Seyyed, A.Abraham and M. Al-Hajji, Seasonality in stock returns and volatility: The Ramadan effect,Research in International Business and Finance, 19, 374-383 (2005).

7. Suhartono and M.H. Lee, Two levels regression modeling of trading day and holiday effects for forecastingretail data, Proceeding The 7th IMT-GT International Conference on Mathematics, Statistics and itsApplications (ICMSA 2011), Bangkok, Thailand, pp. 150-164.

8. W.S. Cleveland and S.J. Devlin, Calendar Effects in Monthly Time Series: Detection by Spectrum Analysisand Graphical Methods, Journal of the American Statistical Association, 75(371), 487-496 (1980).

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 102: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

References9. C. Brooks and G. Persand, Seasonality in Southeast Asian stock markets: some new evidence on day-of-the

week effects,Applied Economics Letters, 8, 155-158 (2001).

10. K. Holden, J.Thompson and Y. Ruangrit, The Asian crisis and calendar effects on stock returns in Thailand,European Journal of Operational Research, 163, 242–252 (2005).

11. W.W.S. Wei, Time Series Analysis: Univariate and Multivariate Methods, 2nd edition, California: Addison-Wesley Publishing Company, Inc. (2006).

12. G.E.P. Box, G.M. Jenkins and G.C. Reinsel, Time Series Analysis, Forecasting and Control, 4th edition,New Jersey: John Wiley & Sons, Inc. (2008).

13. J.D. Cryer and K.S. Chan, Time Series Analysis: with Application in R, 2nd edition, New York: Springer-Verlag. (2008).

14. Suhartono,Time Series Forecasing by using Seasonal Autoregressive Integrated Moving Average: Subset,Multiplicative or Additive, Journal of Mathematics and Statistics, 7 (1), 20-27, (2011).

15. G.E.P. Box and G.M. Jenkins, Time Series Analysis: Forecasting and Control, San Fransisco: Holden-Day,Revised ed. (1976).

16. Suhartono and M.H. Lee, A Hybrid Approach based on Winter’s Model and Weighted Fuzzy Time Series forForecasting Trend and Seasonal Data. Journal of Mathematics and Statistics, 7 (3), 177-183, (2011).

28

9. C. Brooks and G. Persand, Seasonality in Southeast Asian stock markets: some new evidence on day-of-theweek effects,Applied Economics Letters, 8, 155-158 (2001).

10. K. Holden, J.Thompson and Y. Ruangrit, The Asian crisis and calendar effects on stock returns in Thailand,European Journal of Operational Research, 163, 242–252 (2005).

11. W.W.S. Wei, Time Series Analysis: Univariate and Multivariate Methods, 2nd edition, California: Addison-Wesley Publishing Company, Inc. (2006).

12. G.E.P. Box, G.M. Jenkins and G.C. Reinsel, Time Series Analysis, Forecasting and Control, 4th edition,New Jersey: John Wiley & Sons, Inc. (2008).

13. J.D. Cryer and K.S. Chan, Time Series Analysis: with Application in R, 2nd edition, New York: Springer-Verlag. (2008).

14. Suhartono,Time Series Forecasing by using Seasonal Autoregressive Integrated Moving Average: Subset,Multiplicative or Additive, Journal of Mathematics and Statistics, 7 (1), 20-27, (2011).

15. G.E.P. Box and G.M. Jenkins, Time Series Analysis: Forecasting and Control, San Fransisco: Holden-Day,Revised ed. (1976).

16. Suhartono and M.H. Lee, A Hybrid Approach based on Winter’s Model and Weighted Fuzzy Time Series forForecasting Trend and Seasonal Data. Journal of Mathematics and Statistics, 7 (3), 177-183, (2011).

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 103: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

ApplyingApplying Data AnalyticsData Analytics UsingUsingNeural NetworksNeural Networks

2 Days WorkshopFaculty of MIPA, UNIVERSITAS ANDALAS PADANG

& INSTITUT TEKNOLOGI SEPULUH NOPEMBER

Suhartono(B.Sc.-ITS; M.Sc.-UMIST,UK; Dr.-UGM; Postdoctoral-UTM)

Department of Statistics,Institut Teknologi Sepuluh Nopember, Indonesia

Email: [email protected], [email protected]

Department of Mathematics, Universitas Andalas, Padang17-18 July 2017

Page 104: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Outline Introduction: Background,Motivation, Jargons,

Goals. Architecture of Neural Networks: Supervised &

Unsupervised networks Model selection in Neural Networks: Inputs,

Number of hidden neurons,Activation function,Preprocessing method.

Application and Development: Forecasting andClassification problems.

2

Introduction: Background,Motivation, Jargons,Goals.

Architecture of Neural Networks: Supervised &Unsupervised networks

Model selection in Neural Networks: Inputs,Number of hidden neurons,Activation function,Preprocessing method.

Application and Development: Forecasting andClassification problems.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 105: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Neural Networks – NN

3 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 106: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

General Background During the last few decades, modeling to explain nonlinear relationship between variables, and some procedures to detect this nonlinear relationship

have grown in a spectacular way and received a great dealof attention. Granger, C.W.J. and Terasvirta,T., (1993) Terasvirta, T., Tjostheim, D. and Granger, C.W.J., (1994)

Due to computational advances and increased computationalpower, nonparametric models that do not make assumptionsabout the parametric form of the functional relationshipbetween the variables to be modelled have become moreeasily applicable.

4

During the last few decades, modeling to explain nonlinear relationship between variables, and some procedures to detect this nonlinear relationship

have grown in a spectacular way and received a great dealof attention. Granger, C.W.J. and Terasvirta,T., (1993) Terasvirta, T., Tjostheim, D. and Granger, C.W.J., (1994)

Due to computational advances and increased computationalpower, nonparametric models that do not make assumptionsabout the parametric form of the functional relationshipbetween the variables to be modelled have become moreeasily applicable.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 107: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Motivation of NN Research Today’s research is largely motivated by the possibility of

using NN model as an instrument to solve a wide varietyof application problems such as:

pattern recognition (classification), signal processing,process control, and forecasting.

The use of the NN model in applied work is generallymotivated by a mathematical result stating that undermild regularity conditions, a relatively simple NN modelis capable of approximating any Borel-measureablefunction to any given degree of accuracy.

(see e.g. Hornik, Stichombe and White (1989, 1990),White (1990); Cybenko (1989))

5

Today’s research is largely motivated by the possibility ofusing NN model as an instrument to solve a wide varietyof application problems such as:

pattern recognition (classification), signal processing,process control, and forecasting.

The use of the NN model in applied work is generallymotivated by a mathematical result stating that undermild regularity conditions, a relatively simple NN modelis capable of approximating any Borel-measureablefunction to any given degree of accuracy.

(see e.g. Hornik, Stichombe and White (1989, 1990),White (1990); Cybenko (1989))

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 108: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

The use of NN … [Sarle, 1994]

1. as models of biological nervous systemsand “intelligence”,

2. as real-time adaptive signal processors orcontrollers implemented in hardware forapplications such as robots,

3. as data analytic methods.

This paper is concerned with NN for DATAANALYSIS.

6

1. as models of biological nervous systemsand “intelligence”,

2. as real-time adaptive signal processors orcontrollers implemented in hardware forapplications such as robots,

3. as data analytic methods.

This paper is concerned with NN for DATAANALYSIS.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 109: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Chart of Neural Networkshttp://www.asimovinstitute.org/neural-network-zoo/

7 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 110: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Supervised vs Unsupervised networks

8

DependenceMethods

InterdependenceMethods

Multivariate Data Analysis

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 111: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Chart of Neural Networkshttp://www.asimovinstitute.org/neural-network-zoo/

9

Source: Sarle (1994)

Figure 2: Simple Nonlinear Perceptron = Logistic Regression

1

2

3

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 112: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Feed Forward Neural Networks

Multilayer perceptron (MLP), also knownas feedforward neural networks (FFNN),is probably the most commonly used NNarchitecture in engineering application.

Typically, applications of NN for regression,time series modeling and classification(discriminant analysis) are based on theFFNN architecture.

10

Multilayer perceptron (MLP), also knownas feedforward neural networks (FFNN),is probably the most commonly used NNarchitecture in engineering application.

Typically, applications of NN for regression,time series modeling and classification(discriminant analysis) are based on theFFNN architecture.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 113: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Neural Networks & Statistical Jargon

Neural Networks Statistics features variables

inputs independent variables

outputs predicted values

targets or training values dependent variables

errors residuals

11

training, learning, adaptation estimation

patterns or training pairs observations

weights parameter estimates

supervised learning regression & discriminant

unsupervised learning data reduction

adaptive vector quantization cluster analysis

generalization interpolation & extrapolation

X1, X2, …, Xp Y

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 114: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

FFNN as Nonlinear regression

FFNN includes estimated weightsbetween the inputs and the hiddenlayer, and the hidden layer usesnonlinear activation functionssuch as the logistic function, theFFNN becomes genuinelynonlinear model, i.e., nonlinear inthe parameters.

In this case, FFNN can be seen asnonlinear regression. FFNN canhave multiple inputs and outputs(This figure is multiple inputs withsingle output), and thisarchitecture is similar to multiplenonlinear regression.

12

FFNN includes estimated weightsbetween the inputs and the hiddenlayer, and the hidden layer usesnonlinear activation functionssuch as the logistic function, theFFNN becomes genuinelynonlinear model, i.e., nonlinear inthe parameters.

In this case, FFNN can be seen asnonlinear regression. FFNN canhave multiple inputs and outputs(This figure is multiple inputs withsingle output), and thisarchitecture is similar to multiplenonlinear regression.

X1, X2, …, Xp Y

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 115: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

FFNN as Logistic Regression andDiscriminant Analysis

FFNN with nonmetric data(dichotomous/polycothomus)in target values is identical tologistic regression andnonlinear discriminantanalysis.

In this case, FFNN often use amultiple logistic function toestimate the conditionalprobabilities of each class. Amultiple logistic function iscalled a softmax activationfunction in the NN literature.

13

FFNN with nonmetric data(dichotomous/polycothomus)in target values is identical tologistic regression andnonlinear discriminantanalysis.

In this case, FFNN often use amultiple logistic function toestimate the conditionalprobabilities of each class. Amultiple logistic function iscalled a softmax activationfunction in the NN literature.

X1, X2, …, Xp Y

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 116: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

FFNN as Nonlinear AR(p) model

14 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 117: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

FFNN as Nonlinear AR(p) model

Model building strategy that proposed byTerasvirta et al. (1994)

1. Test Yt for linearity, using linearity test(neglected nonlinearity).

2. If linearity is rejected, consider a smallnumber of alternative parametric modelsand/or nonparametric models.

3. These models should be estimated in-sample and compared out-of-sample.

15

Model building strategy that proposed byTerasvirta et al. (1994)

1. Test Yt for linearity, using linearity test(neglected nonlinearity).

2. If linearity is rejected, consider a smallnumber of alternative parametric modelsand/or nonparametric models.

3. These models should be estimated in-sample and compared out-of-sample.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 118: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

FFNN: the main problems !!!

1. How many nodes(neurons) in hidden layer?

2. What is the best inputs(features selection)?

3. What is the best pre-processing method?

4. What is the bestactivation function inhidden and output layer?

In Classification & Regression

16

1. How many nodes(neurons) in hidden layer?

2. What is the best inputs(features selection)?

3. What is the best pre-processing method?

4. What is the bestactivation function inhidden and output layer?

Model selection in NeuralNetworksX1, X2, …, Xp

Y

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 119: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

FFNN: the main problems !!!

1. What is the best inputs(features selection)?

2. How many nodes(neurons) in hidden layer?

3. What is the best pre-processing method?

4. What is the bestactivation function inhidden and output layer?

In Time Series Forecasting

17

1. What is the best inputs(features selection)?

2. How many nodes(neurons) in hidden layer?

3. What is the best pre-processing method?

4. What is the bestactivation function inhidden and output layer?

Model selection in NeuralNetworksYt-1,Yt-2, …,Yt-p

Yt

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 120: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Nonlinear relationship Concept

18

Lag plot: Yt-7 vs Yt

Nonlinear Time SeriesNonlinear Time Series

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 121: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Model Selection in Neural Network

In general, there are two procedures usually usedto find the best FFNN model or the optimalarchitecture, those are “general-to-specific” or“top-down” and “specific-to-general” or “bottom-up” procedures.

“Top-down” procedure is started from complexmodel and then applies an algorithm to reducenumber of parameters (number of input variablesand unit nodes in hidden layer) by using somestopping criteria, whereas “bottom-up” procedureworks from a simple model.

19

In general, there are two procedures usually usedto find the best FFNN model or the optimalarchitecture, those are “general-to-specific” or“top-down” and “specific-to-general” or “bottom-up” procedures.

“Top-down” procedure is started from complexmodel and then applies an algorithm to reducenumber of parameters (number of input variablesand unit nodes in hidden layer) by using somestopping criteria, whereas “bottom-up” procedureworks from a simple model.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 122: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Neural Networks “software”

20 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 123: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Neural Networks “software”

21

Lag plot: Yt-7 vs Yt

Nonlinear Time Series

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 124: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Neural Networks “software”

22

Lag plot: Yt-7 vs Yt

Nonlinear Time Series

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 125: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Classification

Variable NotationY default (Yes = 1 , No = 0)X1 ageX2 ed (categorical)

- Source: bankloan.sav from SPSS

23

X2 ed (categorical)X3 employX4 addressX5 incomeX6 debtincX7 creddebtX8 othdebt Level of education

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 126: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Classification- Source: bankloan.sav from SPSS

Input variablesAll Input X1, X2, …, X8: age, ed, …, othdebt

Best Input employ, address, debtinc, and creddebt

Number of neurons 1 – 25

Activation Function Logistic Sigmoid vsTangent Hyperbolic

24

Preprocessing Method None, Standardized, Normalized, Adjusted Normalized

1.What is the best inputs (features selection)?2.How many nodes (neurons) in hidden layer?3.What is the best activation function in hidden and output layer?4.What is the best pre-processing method?

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 127: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Classification- Source: bankloan.sav from SPSS

Input variablesAll Input X1, X2, …, X8: age, ed, …, othdebt

Best Input employ, address, debtinc, and creddebt

Stepwise Discriminant Logistic Regression

Variable FWilk’s

Lambda Variable Wald p-value

25

Variable FWilk’s

Lambda Variable Wald p-value

Debtinc 30,531 0,747 Employ 63,360 0,000

Employ 73,671 0,798 Address 15,621 0,000

Creddebt 43,584 0,762 Debtinc 20,129 0,000

Address 9,560 0,721 Creddebt 35,799 0,000

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 128: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Classification- Source: bankloan.sav from SPSS

Percentage correct of classification

26

Number of neurons in hidden layer Number of neurons in hidden layer

The effect of INPUTS and number of NEURONS in hidden layer

Training Testing

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 129: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Classification- Source: bankloan.sav from SPSS

Percentage correct of classification

27

The effect of PREPROCESSING method & number of NEURONS

Training

Number of neurons in hidden layer Number of neurons in hidden layer

Testing

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 130: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Classification- Source: bankloan.sav from SPSS

Percentage correct of classification

28

The effect of ACTIVATION function method & number of NEURONS

Training

Number of neurons in hidden layer Number of neurons in hidden layer

Testing

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 131: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Classification- Source: bankloan.sav from SPSS

Summary of the results:(1) More sophisticated or complex methods do not

necessarily provide more accurate classification thansimpler ones, particularly at testing dataset.

(2) The performance of the various NN methods forclassification problem depends upon :

Inputs,Number of neurons in hidden layer,Pre-processing method, andActivation function.

.29

Summary of the results:(1) More sophisticated or complex methods do not

necessarily provide more accurate classification thansimpler ones, particularly at testing dataset.

(2) The performance of the various NN methods forclassification problem depends upon :

Inputs,Number of neurons in hidden layer,Pre-processing method, andActivation function.

.Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 132: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Time Series Forecasting

- Source: simulation study using ESTAR(1)7 model

, et N(0, 0.5)

30 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 133: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Time Series Forecasting

Input variablesMany Inputs include lag 7 (Xt-7) and without lag 7

Best Input only using lag 7 or Xt-7

Number of neurons 1,2,3,4,5,10,15

Activation Function Logistic Sigmoid vsTangent Hyperbolic

Preprocessing Method None, Standardized, Normalized, Adjusted Normalized

- Source: simulation study using ESTAR(1)7 model

31

Preprocessing Method None, Standardized, Normalized, Adjusted Normalized

1.What is the best inputs (features selection)?2.How many nodes (neurons) in hidden layer?3.What is the best activation function in hidden and output layer?4.What is the best pre-processing method?

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 134: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Time Series Forecasting- Source: simulation study using ESTAR(1)7 model

32

Identification the appropriate lag inputs: use LAG PLOT in R

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 135: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Time Series Forecasting- Source: simulation study using ESTAR(1)7 model

RMSE

with Xt-7 with Xt-7

without Xt-7without Xt-7

33

Number of neurons in hidden layer Number of neurons in hidden layer

The effect of INPUTS and number of NEURONS in hidden layer

Training Testing

with Xt-7 with Xt-7

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 136: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Time Series Forecasting- Source: simulation study using ESTAR(1)7 model

RMSE

34

The effect of ACTIVATION function and number of NEURONS

Number of neurons in hidden layer Number of neurons in hidden layer

Training Testing

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 137: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Application: NN for Time Series Forecasting- Source: simulation study using ESTAR(1)7 model

RMSE

35

The effect of PREPROCESSING method & number of NEURONS

Number of neurons in hidden layer Number of neurons in hidden layer

Training Testing

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 138: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Summary of the results:(1) More sophisticated or complex methods do not

necessarily provide more accurate forecast thansimpler ones.

(2) The performance of the various NN methods for timeseries forecasting problem depends upon :

Inputs or lag variables,Number of neurons in hidden layer,Pre-processing method.

Application: NN for Time Series Forecasting- Source: simulation study using ESTAR(1)7 model

36

Summary of the results:(1) More sophisticated or complex methods do not

necessarily provide more accurate forecast thansimpler ones.

(2) The performance of the various NN methods for timeseries forecasting problem depends upon :

Inputs or lag variables,Number of neurons in hidden layer,Pre-processing method.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 139: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

25 years of time series forecastingDe Gooijer & Hyndman (International Journal of Forecasting, 2006)

1980

2005

37

1980

2005

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 140: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Research MotivationThe M3-Competition: results, conclusions

and implications(1) Statistically sophisticated or complex methods do not

necessarily provide more accurate forecasts than simpler ones.(2) The relative ranking of the performance of the various

methods varies according to the accuracy measure being used.(3) The accuracy when various methods are being combined

outperforms, on average, the individual methods beingcombined and does very well in comparison to other methods.

(4) The accuracy of the various methods depends upon the lengthof the forecasting horizon involved.

Makridakis & Hibon (International Journal of Forecasting, 2000)

38

The M3-Competition: results, conclusionsand implications

(1) Statistically sophisticated or complex methods do notnecessarily provide more accurate forecasts than simpler ones.

(2) The relative ranking of the performance of the variousmethods varies according to the accuracy measure being used.

(3) The accuracy when various methods are being combinedoutperforms, on average, the individual methods beingcombined and does very well in comparison to other methods.

(4) The accuracy of the various methods depends upon the lengthof the forecasting horizon involved.

Makridakis & Hibon (International Journal of Forecasting, 2000)

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 141: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Recent development of NN for forecasting

Hybrid Model – Combined - Ensemble

39 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 142: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Recent development of NN for forecasting

Hybrid Model – Combined - Ensemble

40 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 143: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Recent development of NN for forecasting

Hybrid Model – Combined - Ensemble

41 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 144: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Conclusion Statistical models and NN are not competing

methodologies for data analysis. There isconsiderable many similarities between the twomodels.

NN include several models, such as FFNN, thatare useful for statistical applications.

Statistical methodology is directly applicable toNN in a variety of ways, including estimationcriteria, optimization algorithm, testinghypothesis and diagnostic check.

42

Statistical models and NN are not competingmethodologies for data analysis. There isconsiderable many similarities between the twomodels.

NN include several models, such as FFNN, thatare useful for statistical applications.

Statistical methodology is directly applicable toNN in a variety of ways, including estimationcriteria, optimization algorithm, testinghypothesis and diagnostic check.

Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND

Page 145: TIME SERIES FORECASTING WITH R - Unandmatematika.fmipa.unand.ac.id/images/bahan-seminar/suhartono.pdf · TIME SERIES FORECASTING WITH R: from CLASSICAL to MODERN Methods 2 Days Workshop

Main References

43 Inspiring Creative & Innovative Minds – Dept. of Mathematics, UNAND