22
ARIMA MODELING WITH R Pure Seasonal Models

Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA MODELING WITH R

Pure Seasonal Models

Page 2: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Pure Seasonal Models● O!en collect data with a known seasonal component

● Air Passengers (1 cycle every S = 12 months)

● Johnson & Johnson Earnings (1 cycle every S = 4 quarters)

Page 3: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Pure Seasonal Models● Consider pure seasonal models such as an SAR(P = 1)s = 12

Xt = �Xt�12 +Wt

Page 4: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

ACF and PACF of Pure Seasonal ModelsSAR(P)s SMA(Q)s SARMA(P, Q)s

ACF* Tails off Cuts off lag QS Tails off

PACF* Cuts off lag PS Tails off Tails off

* The values at the nonseasonal lags are zero

SAR(1)1 SMA(1)1

Page 5: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA MODELING WITH R

Let’s practice!

Page 6: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA MODELING WITH R

Mixed Seasonal Models

Page 7: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Mixed Seasonal Model

● Consider a SARIMA(0, 0, 1) x (1, 0, 0)12 model

Xt = �Xt�12 +Wt + ✓Wt�1

● SAR(1): Value this month is related to last year’s value

● MA(1): This month’s value related to last month’s shock

Xt�12

Wt�1

● Mixed model: SARIMA(p, d, q) x (P, D, Q)s model

Page 8: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

ACF and PACF of SARIMA(0,0,1) x (1,0,0) s=12

● The ACF and PACF for this mixed model:

Xt = .8Xt�12 +Wt � .5Wt�1

Seasonal

Non-seasonal

Page 9: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Seasonal PersistenceHawaiian Quarterly Occupancy Rate

Timex

2002 2004 2006 2008 2010 2012 2014 2016

6570

7580

85

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

23

41

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

12

34

Seasonal Component

Time

Qx

2002 2004 2006 2008 2010 2012 2014 2016

-4-2

02

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

Seasonal Difference

Time

diff(

x, 4

)

2004 2006 2008 2010 2012 2014 2016

-10

-50

5

1

2

3 41

2

34

1 2 3 4

1 23 4

1 23

4

1

2

3 4

1

23

4

1 2

34 1

2 34

12

3 4 12

3 4 1 2 34

1

23

4

Quarterly Occupancy Rate: % rooms filled

Seasonal Component: this year vs. last year Q1 ≈ Q1, Q2 ≈ Q2, Q3 ≈ Q3, Q4 ≈ Q4

Hawaiian Quarterly Occupancy Rate

Timex

2002 2004 2006 2008 2010 2012 2014 2016

6570

7580

85

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

23

41

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

12

34

Seasonal Component

Time

Qx

2002 2004 2006 2008 2010 2012 2014 2016

-4-2

02

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

Seasonal Difference

Time

diff(

x, 4

)

2004 2006 2008 2010 2012 2014 2016

-10

-50

5

1

2

3 41

2

34

1 2 3 4

1 23 4

1 23

4

1

2

3 4

1

23

4

1 2

34 1

2 34

12

3 4 12

3 4 1 2 34

1

23

4Remove seasonal persistence by a seasonal difference: Xt - Xt-4 or D = 1, S = 4 for quarterly data

Hawaiian Quarterly Occupancy Rate

Timex

2002 2004 2006 2008 2010 2012 2014 2016

6570

7580

85

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

23

41

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

12

34

Seasonal Component

Time

Qx

2002 2004 2006 2008 2010 2012 2014 2016

-4-2

02

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

1

2

3

4

Seasonal Difference

Time

diff(

x, 4

)

2004 2006 2008 2010 2012 2014 2016

-10

-50

5

1

2

3 41

2

34

1 2 3 4

1 23 4

1 23

4

1

2

3 4

1

23

4

1 2

34 1

2 34

12

3 4 12

3 4 1 2 34

1

23

4

Page 10: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Air Passengers● Monthly totals of international airline passengers, 1949-1960

x: AirPassengers

dlx: diff(lx)

ddlx: diff(dlx, 12)

lx: log(x)

Page 11: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Air Passengers: ACF and PACF of ddlx

● Seasonal: ACF cu#ing off at lag 1s (s = 12); PACF tailing off at lags 1s, 2s, 3s…

● Non-Seasonal: ACF and PACF both tailing off

Page 12: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Air Passengers> airpass_fit1 <- sarima(log(AirPassengers), p = 1,

d = 1, q = 1, P = 0, D = 1, Q = 1, S = 12)

> airpass_fit1$ttable

Estimate SE t.value p.value ar1 0.1960 0.2475 0.7921 0.4296 ma1 -0.5784 0.2132 -2.7127 0.0075 sma1 -0.5643 0.0747 -7.5544 0.0000

> airpass_fit2 <- sarima(log(AirPassengers), 0, 1, 1, 0, 1, 1, 12)

> airpass_fit2$ttable

Estimate SE t.value p.value ma1 -0.4018 0.0896 -4.4825 0 sma1 -0.5569 0.0731 -7.6190 0

Page 13: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Air PassengersStandardized Residuals

Time

1950 1952 1954 1956 1958 1960

−3−1

12

3

Model: (0,1,1) (0,1,1) [12]

0.5 1.0 1.5

−0.2

0.2

0.4

ACF of Residuals

LAG

ACF ●●●●●●●●●●●●

●●

● ●

●●

●●

●●

●● ●

●●

●●

●●

●●

●●

●●

●●●

●●

●●

●●

● ●

●●

● ●●

●●

●●

●●

●●●● ●

●●●

●●

●●

●●

● ●

●●

●●

●●

−2 −1 0 1 2

−3−1

12

3Normal Q−Q Plot of Std Residuals

Theoretical Quantiles

Sam

ple

Qua

ntile

s

● ●●

●●

●●

●●

●● ●

●●

●●

●●

●●

● ●● ●

● ● ●

●● ●

5 10 15 20 25 30 35

0.0

0.4

0.8

p values for Ljung−Box statistic

lag

p va

lue

Page 14: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA MODELING WITH R

Let’s practice!

Page 15: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA MODELING WITH R

Forecasting Seasonal ARIMA

Page 16: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Forecasting ARIMA Processes● Once model is chosen, forecasting is easy because the

model describes how the dynamics of the time series behave over time

● Simply continue the model dynamics into the future

● In the astsa package, use sarima.for() for forecasting

Page 17: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Forecasting Air Passengers

> sarima.for(log(AirPassengers), n.ahead = 24, 0, 1, 1, 0, 1, 1, 12)

● In the previous video, we decided that a SARIMA(0,1,1)x(0,1,1)12 model was appropriate

Time

log(AirPassengers)

1954 1956 1958 1960 1962

5.5

6.0

6.5

Page 18: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA MODELING WITH R

Let’s practice!

Page 19: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA MODELING WITH R

Congratulations!

Page 20: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

What you’ve learned● How to identify an ARMA model from data looking at

ACF and PACF

● How to use integrated ARMA (ARIMA) models for nonstationary time series

● How to cope with seasonality

Page 21: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA Modeling with R

Don’t stop here!● astsa-package

● Other DataCamp courses in Time Series Analysis

Page 22: Pure Seasonal Models - Amazon S3 · ARIMA Modeling with R Seasonal Persistence Hawaiian Quarterly Occupancy Rate Time x 2002 2004 2006 2008 2010 2012 2014 2016 65 70 75 80 85 1 2

ARIMA MODELING WITH R

Thank you!