forecasting using - rob j. hyndman...rob j hyndman student award to students who make the most...

95
Forecasting using 4. White noise and time series decomposition OTexts.com/fpp/2/6 OTexts.com/fpp/6/ Forecasting using R 1 Rob J Hyndman

Upload: others

Post on 13-Jul-2020

3 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting using

4. White noise and time series decomposition

OTexts.com/fpp/2/6OTexts.com/fpp/6/

Forecasting using R 1

Rob J Hyndman

Page 2: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Student award

To students who make the most contribution tothe class, as voted by their peers.

Contributions can be on Piazza or during thewebex online sessions.

Contribute questions, answers, comments,code suggestions, etc.

Looking for engaged learners, not experts.

At end of course, all students to vote for bestcontributor.

$100 to the top voted student and $50 tothe second student (plus t-shirts).

Forecasting using R 2

Page 3: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time zones

All sessions are at UTC 22:00for the entire course.Be aware when your time zone changes.

Most of Europe changed last Sunday. So classesare now one hour earlier for most Europeanresidents.

Most of USA and Canada change next Sunday.So classes will be one hour earlier for mostNorth American residents from next week.

Forecasting using R 3

Page 4: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Outline

1 White noise

2 Time series decomposition

3 Seasonal adjustment

4 Forecasting and decomposition

Forecasting using R White noise 4

Page 5: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: White noise

Forecasting using R White noise 5

White noise

Time

x

0 10 20 30 40 50

−3

−2

−1

01

2

Page 6: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: White noise

Forecasting using R White noise 5

White noise

Time

x

0 10 20 30 40 50

−3

−2

−1

01

2

White noise data is uncorrelated acrosstime with zero mean and constant variance.(Technically, we require independence aswell.)

Page 7: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: White noise

Forecasting using R White noise 5

White noise

Time

x

0 10 20 30 40 50

−3

−2

−1

01

2

White noise data is uncorrelated acrosstime with zero mean and constant variance.(Technically, we require independence aswell.)

Think of white noise as completelyuninteresting with no predictable patterns.

Page 8: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: White noise

r1 = 0.013r2 = −0.163r3 = 0.163r4 = −0.259r5 = −0.198r6 = 0.064r7 = −0.139r8 = −0.032r9 = 0.199r10 = −0.240

Sample autocorrelations for white noise series.For uncorrelated data, we would expect eachautocorrelation to be close to zero.

Forecasting using R White noise 6

−0.

4−

0.2

0.0

0.2

0.4

Lag

AC

F

1 2 3 4 5 6 7 8 9 10 11 12 13 14 1511 13

Page 9: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Sampling distribution of autocorrelations

Sampling distribution of rk for white noise data isasymptotically N(0,1/T).

95% of all rk for white noise must lie within±1.96/

√T.

If this is not the case, the series is probably notWN.

Common to plot lines at ±1.96/√T when

plotting ACF. These are the critical values.

Forecasting using R White noise 7

Page 10: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Sampling distribution of autocorrelations

Sampling distribution of rk for white noise data isasymptotically N(0,1/T).

95% of all rk for white noise must lie within±1.96/

√T.

If this is not the case, the series is probably notWN.

Common to plot lines at ±1.96/√T when

plotting ACF. These are the critical values.

Forecasting using R White noise 7

Page 11: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Sampling distribution of autocorrelations

Sampling distribution of rk for white noise data isasymptotically N(0,1/T).

95% of all rk for white noise must lie within±1.96/

√T.

If this is not the case, the series is probably notWN.

Common to plot lines at ±1.96/√T when

plotting ACF. These are the critical values.

Forecasting using R White noise 7

Page 12: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Sampling distribution of autocorrelations

Sampling distribution of rk for white noise data isasymptotically N(0,1/T).

95% of all rk for white noise must lie within±1.96/

√T.

If this is not the case, the series is probably notWN.

Common to plot lines at ±1.96/√T when

plotting ACF. These are the critical values.

Forecasting using R White noise 7

Page 13: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Autocorrelation

Forecasting using R White noise 8

−0.

4−

0.2

0.0

0.2

0.4

Lag

AC

F

1 2 3 4 5 6 7 8 9 10 11 12 13 14 1511 13

Example:T = 50 and socritical values at±1.96/

√50 =

±0.28.All autocorrelationcoefficients lie withinthese limits,confirming that thedata are white noise.(More precisely, the data cannot bedistinguished from white noise.)

Page 14: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Pigs slaughtered

Forecasting using R White noise 9

Number of pigs slaughtered in Victoria

thou

sand

s

1990 1991 1992 1993 1994 1995

8090

100

110

Page 15: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Pigs slaughtered

Forecasting using R White noise 10

−0.

20.

00.

2

Lag

AC

F

0 10 20 30 40

Page 16: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Pigs slaughtered

Monthly total number of pigs slaughtered in thestate of Victoria, Australia, from January 1990through August 1995. (Source: Australian Bureau ofStatistics.)

Difficult to detect pattern in time plot.

ACF shows some significant autocorrelation atlags 1, 2, and 3.

r12 relatively large although not significant.This may indicate some slight seasonality.

These show the series is not a white noise series.

Forecasting using R White noise 11

Page 17: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Pigs slaughtered

Monthly total number of pigs slaughtered in thestate of Victoria, Australia, from January 1990through August 1995. (Source: Australian Bureau ofStatistics.)

Difficult to detect pattern in time plot.

ACF shows some significant autocorrelation atlags 1, 2, and 3.

r12 relatively large although not significant.This may indicate some slight seasonality.

These show the series is not a white noise series.

Forecasting using R White noise 11

Page 18: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Pigs slaughtered

Monthly total number of pigs slaughtered in thestate of Victoria, Australia, from January 1990through August 1995. (Source: Australian Bureau ofStatistics.)

Difficult to detect pattern in time plot.

ACF shows some significant autocorrelation atlags 1, 2, and 3.

r12 relatively large although not significant.This may indicate some slight seasonality.

These show the series is not a white noise series.

Forecasting using R White noise 11

Page 19: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Pigs slaughtered

Monthly total number of pigs slaughtered in thestate of Victoria, Australia, from January 1990through August 1995. (Source: Australian Bureau ofStatistics.)

Difficult to detect pattern in time plot.

ACF shows some significant autocorrelation atlags 1, 2, and 3.

r12 relatively large although not significant.This may indicate some slight seasonality.

These show the series is not a white noise series.

Forecasting using R White noise 11

Page 20: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Pigs slaughtered

Monthly total number of pigs slaughtered in thestate of Victoria, Australia, from January 1990through August 1995. (Source: Australian Bureau ofStatistics.)

Difficult to detect pattern in time plot.

ACF shows some significant autocorrelation atlags 1, 2, and 3.

r12 relatively large although not significant.This may indicate some slight seasonality.

These show the series is not a white noise series.

Forecasting using R White noise 11

Page 21: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Pigs slaughtered

Monthly total number of pigs slaughtered in thestate of Victoria, Australia, from January 1990through August 1995. (Source: Australian Bureau ofStatistics.)

Difficult to detect pattern in time plot.

ACF shows some significant autocorrelation atlags 1, 2, and 3.

r12 relatively large although not significant.This may indicate some slight seasonality.

These show the series is not a white noise series.

Forecasting using R White noise 11

Page 22: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

ACF of residuals

We assume that the residuals are white noise(uncorrelated, mean zero, constant variance). Ifthey aren’t, then there is information left in theresiduals that should be used in computingforecasts.So a standard residual diagnostic is to checkthe ACF of the residuals of a forecastingmethod.We expect these to look like white noise.

Dow-Jones naive forecasts revisited

yt|t−1 = yt−1

et = yt − yt−1

Forecasting using R White noise 12

Page 23: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

ACF of residuals

We assume that the residuals are white noise(uncorrelated, mean zero, constant variance). Ifthey aren’t, then there is information left in theresiduals that should be used in computingforecasts.So a standard residual diagnostic is to checkthe ACF of the residuals of a forecastingmethod.We expect these to look like white noise.

Dow-Jones naive forecasts revisited

yt|t−1 = yt−1

et = yt − yt−1

Forecasting using R White noise 12

Page 24: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

ACF of residuals

We assume that the residuals are white noise(uncorrelated, mean zero, constant variance). Ifthey aren’t, then there is information left in theresiduals that should be used in computingforecasts.So a standard residual diagnostic is to checkthe ACF of the residuals of a forecastingmethod.We expect these to look like white noise.

Dow-Jones naive forecasts revisited

yt|t−1 = yt−1

et = yt − yt−1

Forecasting using R White noise 12

Page 25: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

ACF of residuals

We assume that the residuals are white noise(uncorrelated, mean zero, constant variance). Ifthey aren’t, then there is information left in theresiduals that should be used in computingforecasts.So a standard residual diagnostic is to checkthe ACF of the residuals of a forecastingmethod.We expect these to look like white noise.

Dow-Jones naive forecasts revisited

yt|t−1 = yt−1

et = yt − yt−1

Forecasting using R White noise 12

Page 26: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

ACF of residuals

We assume that the residuals are white noise(uncorrelated, mean zero, constant variance). Ifthey aren’t, then there is information left in theresiduals that should be used in computingforecasts.So a standard residual diagnostic is to checkthe ACF of the residuals of a forecastingmethod.We expect these to look like white noise.

Dow-Jones naive forecasts revisited

yt|t−1 = yt−1

et = yt − yt−1

Forecasting using R White noise 12

Page 27: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting Dow-Jones index

Forecasting using R White noise 13

Day

Cha

nge

in D

ow−

Jone

s in

dex

0 50 100 150 200 250 300

−10

0−

500

50

Page 28: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting Dow-Jones index

Forecasting using R White noise 14

−0.

15−

0.05

0.05

0.10

0.15

Lag

AC

F

1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 2211 13 15 17 19 21 23

Page 29: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Dow-Jones residuals

−0.

15−

0.05

0.05

0.10

0.15

Lag

AC

F

1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 2211 13 15 17 19 21 23

These look like white noise.

But the ACF is a multiple testing problem.

Forecasting using R White noise 15

Page 30: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Example: Dow-Jones residuals

−0.

15−

0.05

0.05

0.10

0.15

Lag

AC

F

1 2 3 4 5 6 7 8 9 10 12 14 16 18 20 2211 13 15 17 19 21 23

These look like white noise.

But the ACF is a multiple testing problem.

Forecasting using R White noise 15

Page 31: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsConsider a whole set of rk values, and develop atest to see whether the set is significantly differentfrom a zero set.

Forecasting using R White noise 16

Page 32: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsConsider a whole set of rk values, and develop atest to see whether the set is significantly differentfrom a zero set.

Box-Pierce test

Q = Th∑

k=1

r2k

where h is max lag being considered and T isnumber of observations.

My preferences: h = 10 for non-seasonal data, h = 2mfor seasonal data.If each rk close to zero, Q will be small.If some rk values large (positive or negative), Q will belarge.

Forecasting using R White noise 16

Page 33: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsConsider a whole set of rk values, and develop atest to see whether the set is significantly differentfrom a zero set.

Box-Pierce test

Q = Th∑

k=1

r2k

where h is max lag being considered and T isnumber of observations.

My preferences: h = 10 for non-seasonal data, h = 2mfor seasonal data.If each rk close to zero, Q will be small.If some rk values large (positive or negative), Q will belarge.

Forecasting using R White noise 16

Page 34: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsConsider a whole set of rk values, and develop atest to see whether the set is significantly differentfrom a zero set.

Box-Pierce test

Q = Th∑

k=1

r2k

where h is max lag being considered and T isnumber of observations.

My preferences: h = 10 for non-seasonal data, h = 2mfor seasonal data.If each rk close to zero, Q will be small.If some rk values large (positive or negative), Q will belarge.

Forecasting using R White noise 16

Page 35: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsConsider a whole set of rk values, and develop atest to see whether the set is significantly differentfrom a zero set.

Box-Pierce test

Q = Th∑

k=1

r2k

where h is max lag being considered and T isnumber of observations.

My preferences: h = 10 for non-seasonal data, h = 2mfor seasonal data.If each rk close to zero, Q will be small.If some rk values large (positive or negative), Q will belarge.

Forecasting using R White noise 16

Page 36: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsConsider a whole set of rk values, and develop atest to see whether the set is significantly differentfrom a zero set.

Ljung-Box test

Q∗ = T(T + 2)h∑

k=1

(T − k)−1r2k

where h is max lag being considered and T isnumber of observations.

My preferences: h = 10 for non-seasonal data, h = 2mfor seasonal data.Better performance, especially in small samples.

Forecasting using R White noise 16

Page 37: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsIf data are WN, Q∗ has χ2 distribution with(h− K) degrees of freedom where K = no.parameters in model.

When applied to raw data, set K = 0.For the Dow-Jones example,

res <- residuals(naive(dj))

# lag=h and fitdf=K> Box.test(res, lag=10, fitdf=0)Box-Pierce testX-squared = 14.0451, df = 10, p-value = 0.1709> Box.test(res, lag=10, fitdf=0, type="Lj")Box-Ljung testX-squared = 14.4615, df = 10, p-value = 0.153

Forecasting using R White noise 17

Page 38: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsIf data are WN, Q∗ has χ2 distribution with(h− K) degrees of freedom where K = no.parameters in model.

When applied to raw data, set K = 0.For the Dow-Jones example,

res <- residuals(naive(dj))

# lag=h and fitdf=K> Box.test(res, lag=10, fitdf=0)Box-Pierce testX-squared = 14.0451, df = 10, p-value = 0.1709> Box.test(res, lag=10, fitdf=0, type="Lj")Box-Ljung testX-squared = 14.4615, df = 10, p-value = 0.153

Forecasting using R White noise 17

Page 39: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Portmanteau testsIf data are WN, Q∗ has χ2 distribution with(h− K) degrees of freedom where K = no.parameters in model.

When applied to raw data, set K = 0.For the Dow-Jones example,

res <- residuals(naive(dj))

# lag=h and fitdf=K> Box.test(res, lag=10, fitdf=0)Box-Pierce testX-squared = 14.0451, df = 10, p-value = 0.1709> Box.test(res, lag=10, fitdf=0, type="Lj")Box-Ljung testX-squared = 14.4615, df = 10, p-value = 0.153

Forecasting using R White noise 17

Page 40: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Exercise

1 Calculate the residuals from a seasonal

naive forecast applied to the quarterly

Australian beer production data from

1992.

2 Test if the residuals are white noise.

Forecasting using R White noise 18

Page 41: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Exercise

1 Calculate the residuals from a seasonal

naive forecast applied to the quarterly

Australian beer production data from

1992.

2 Test if the residuals are white noise.

beer <- window(ausbeer,start=1992)fc <- snaive(beer)res <- residuals(fc)Acf(res)Box.test(res, lag=8, fitdf=0, type="Lj")

Forecasting using R White noise 19

Page 42: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Outline

1 White noise

2 Time series decomposition

3 Seasonal adjustment

4 Forecasting and decomposition

Forecasting using R Time series decomposition 20

Page 43: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time series decomposition

Yt = f(St, Tt,Et)

where Yt = data at period tSt = seasonal component at period tTt = trend-cycle component at period tEt = remainder (or irregular or error)

component at period t

Additive decomposition: Yt = St + Tt + Et.Multiplicative decomposition: Yt = St × Tt × Et.

Forecasting using R Time series decomposition 21

Page 44: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time series decomposition

Yt = f(St, Tt,Et)

where Yt = data at period tSt = seasonal component at period tTt = trend-cycle component at period tEt = remainder (or irregular or error)

component at period t

Additive decomposition: Yt = St + Tt + Et.Multiplicative decomposition: Yt = St × Tt × Et.

Forecasting using R Time series decomposition 21

Page 45: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time series decomposition

Yt = f(St, Tt,Et)

where Yt = data at period tSt = seasonal component at period tTt = trend-cycle component at period tEt = remainder (or irregular or error)

component at period t

Additive decomposition: Yt = St + Tt + Et.Multiplicative decomposition: Yt = St × Tt × Et.

Forecasting using R Time series decomposition 21

Page 46: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time series decomposition

Additive model appropriate if magnitude ofseasonal fluctuations does not vary with level.

If seasonal are proportional to level of series,then multiplicative model appropriate.

Multiplicative decomposition more prevalentwith economic series

Logs turn multiplicative relationship into anadditive relationship:

Yt = St×Tt×Et ⇒ log Yt = logSt+log Tt+logEt.

Forecasting using R Time series decomposition 22

Page 47: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time series decomposition

Additive model appropriate if magnitude ofseasonal fluctuations does not vary with level.

If seasonal are proportional to level of series,then multiplicative model appropriate.

Multiplicative decomposition more prevalentwith economic series

Logs turn multiplicative relationship into anadditive relationship:

Yt = St×Tt×Et ⇒ log Yt = logSt+log Tt+logEt.

Forecasting using R Time series decomposition 22

Page 48: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time series decomposition

Additive model appropriate if magnitude ofseasonal fluctuations does not vary with level.

If seasonal are proportional to level of series,then multiplicative model appropriate.

Multiplicative decomposition more prevalentwith economic series

Logs turn multiplicative relationship into anadditive relationship:

Yt = St×Tt×Et ⇒ log Yt = logSt+log Tt+logEt.

Forecasting using R Time series decomposition 22

Page 49: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time series decomposition

Additive model appropriate if magnitude ofseasonal fluctuations does not vary with level.

If seasonal are proportional to level of series,then multiplicative model appropriate.

Multiplicative decomposition more prevalentwith economic series

Logs turn multiplicative relationship into anadditive relationship:

Yt = St×Tt×Et ⇒ log Yt = logSt+log Tt+logEt.

Forecasting using R Time series decomposition 22

Page 50: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

History of time series decomposition

Classical method originated in 1920s.

In R: decompose().

Census II method introduced in 1957.

Basis for modern X-12-ARIMA method.

STL method introduced in 1983. It only

allows additive decomposition.

In R: stl().

TRAMO/SEATS introduced in 1990s.

Forecasting using R Time series decomposition 23

Page 51: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

History of time series decomposition

Classical method originated in 1920s.

In R: decompose().

Census II method introduced in 1957.

Basis for modern X-12-ARIMA method.

STL method introduced in 1983. It only

allows additive decomposition.

In R: stl().

TRAMO/SEATS introduced in 1990s.

Forecasting using R Time series decomposition 23

Page 52: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

History of time series decomposition

Classical method originated in 1920s.

In R: decompose().

Census II method introduced in 1957.

Basis for modern X-12-ARIMA method.

STL method introduced in 1983. It only

allows additive decomposition.

In R: stl().

TRAMO/SEATS introduced in 1990s.

Forecasting using R Time series decomposition 23

Page 53: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

History of time series decomposition

Classical method originated in 1920s.

In R: decompose().

Census II method introduced in 1957.

Basis for modern X-12-ARIMA method.

STL method introduced in 1983. It only

allows additive decomposition.

In R: stl().

TRAMO/SEATS introduced in 1990s.

Forecasting using R Time series decomposition 23

Page 54: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

History of time series decomposition

Classical method originated in 1920s.

In R: decompose().

Census II method introduced in 1957.

Basis for modern X-12-ARIMA method.

STL method introduced in 1983. It only

allows additive decomposition.

In R: stl().

TRAMO/SEATS introduced in 1990s.

Forecasting using R Time series decomposition 23

Page 55: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

History of time series decomposition

Classical method originated in 1920s.

In R: decompose().

Census II method introduced in 1957.

Basis for modern X-12-ARIMA method.

STL method introduced in 1983. It only

allows additive decomposition.

In R: stl().

TRAMO/SEATS introduced in 1990s.

Forecasting using R Time series decomposition 23

Page 56: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Classical decomposition

Forecasting using R Time series decomposition 24

3050

7090

data

−10

−5

05

10

seas

onal

3040

5060

tren

d

−10

010

1975 1980 1985 1990 1995

rem

aind

er

time

Page 57: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

STL decomposition

Forecasting using R Time series decomposition 25

3050

7090

data

−10

−5

05

10

seas

onal

4050

60

tren

d

−15

−5

05

10

1975 1980 1985 1990 1995

rem

aind

er

time

Page 58: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Examples: US house sales

Forecasting using R Time series decomposition 26

Sales of new one−family houses, USA

Tota

l sal

es

1975 1980 1985 1990 1995

3040

5060

7080

90

Page 59: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Examples: US house sales

Forecasting using R Time series decomposition 27

Sales of new one−family houses, USA

Tota

l sal

es

1975 1980 1985 1990 1995

3040

5060

7080

90

Page 60: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Examples: US house sales

Forecasting using R Time series decomposition 28

Time

Dat

a

1975 1980 1985 1990 1995

3050

7090

Sea

sona

l

1975 1980 1985 1990 1995

−10

05

Page 61: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Examples: US house sales

Forecasting using R Time series decomposition 29

Dat

a

1975 1980 1985 1990 1995

3050

7090

Time

Err

or

1975 1980 1985 1990 1995

−15

−5

515

Page 62: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Examples: US house sales

Forecasting using R Time series decomposition 29

Dat

a

1975 1980 1985 1990 1995

3050

7090

Time

Err

or

1975 1980 1985 1990 1995

−15

−5

515

Page 63: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Examples: US house sales

Forecasting using R Time series decomposition 30

3050

7090

data

−10

−5

05

10

seas

onal

4050

60

tren

d

−15

−5

05

10

1975 1980 1985 1990 1995

rem

aind

er

time

Page 64: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Time series decomposition in R

plot(decompose(hsales))

plot(stl(hsales,s.window="periodic"))

plot(stl(hsales,s.window=15))

Forecasting using R Time series decomposition 31

Page 65: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Forecasting using R Time series decomposition 32

Electrical equipment manufacturing (Euro area)

New

ord

ers

inde

x

2000 2005 2010

6070

8090

100

110

120

130

Page 66: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Forecasting using R Time series decomposition 33

Electrical equipment manufacturing (Euro area)

New

ord

ers

inde

x

2000 2005 2010

6070

8090

100

110

120

130

Page 67: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Forecasting using R Time series decomposition 34

6080

100

120

data

−20

−10

05

10

seas

onal

8090

100

110

tren

d

−8

−4

02

46

2000 2005 2010

rem

aind

er

time

Page 68: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Forecasting using R Time series decomposition 35

6080

100

120

data

−20

−10

05

10

seas

onal

8090

100

110

tren

d

−8

−4

02

46

2000 2005 2010

rem

aind

er

time

fit <- stl(elecequip, s.window=5)plot(fit)

Page 69: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Seasonal sub-series plot of the seasonal component

Forecasting using R Time series decomposition 36

Sea

sona

l

J F M A M J J A S O N D

−20

−15

−10

−5

05

1015

Page 70: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Seasonal sub-series plot of the seasonal component

Forecasting using R Time series decomposition 37

Sea

sona

l

J F M A M J J A S O N D

−20

−15

−10

−5

05

1015

monthplot(fit$time.series[,"seasonal"],ylab="Seasonal")

Page 71: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Forecasting using R Time series decomposition 38

6080

100

120

data

−15

−5

05

10

seas

onal

8090

100

110

tren

d

−5

05

10

2000 2005 2010

rem

aind

er

time

Page 72: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Forecasting using R Time series decomposition 39

6080

100

120

data

−15

−5

05

10

seas

onal

8090

100

110

tren

d

−5

05

10

2000 2005 2010

rem

aind

er

time

fit <- stl(elecequip, t.window=15,s.window="periodic", robust=TRUE)

plot(fit)

Page 73: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Forecasting using R Time series decomposition 40

6080

100

120

data

−15

−5

05

10

seas

onal

8090

100

110

tren

d

−5

05

10

2000 2005 2010

rem

aind

er

time

fit <- stl(elecequip, t.window=15,s.window="periodic", robust=TRUE)

plot(fit)

t.windowcontrolswiggliness oftrendcomponent.

s.windowcontrolsvariation inseasonalcomponent.

Page 74: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Forecasting using R Time series decomposition 40

6080

100

120

data

−15

−5

05

10

seas

onal

8090

100

110

tren

d

−5

05

10

2000 2005 2010

rem

aind

er

time

fit <- stl(elecequip, t.window=15,s.window="periodic", robust=TRUE)

plot(fit)

t.windowcontrolswiggliness oftrendcomponent.

s.windowcontrolsvariation inseasonalcomponent.

Page 75: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Outline

1 White noise

2 Time series decomposition

3 Seasonal adjustment

4 Forecasting and decomposition

Forecasting using R Seasonal adjustment 41

Page 76: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Seasonal adjustment

Useful by-product of decomposition: an easyway to calculate seasonally adjusted data.

Additive decomposition: seasonally adjusteddata given by

Yt − St = Tt + Et

Multiplicative decomposition: seasonallyadjusted data given by

Yt/St = Tt × Et

Forecasting using R Seasonal adjustment 42

Page 77: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Seasonal adjustment

Useful by-product of decomposition: an easyway to calculate seasonally adjusted data.

Additive decomposition: seasonally adjusteddata given by

Yt − St = Tt + Et

Multiplicative decomposition: seasonallyadjusted data given by

Yt/St = Tt × Et

Forecasting using R Seasonal adjustment 42

Page 78: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Seasonal adjustment

Useful by-product of decomposition: an easyway to calculate seasonally adjusted data.

Additive decomposition: seasonally adjusteddata given by

Yt − St = Tt + Et

Multiplicative decomposition: seasonallyadjusted data given by

Yt/St = Tt × Et

Forecasting using R Seasonal adjustment 42

Page 79: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Euro electrical equipment

Seasonally adjusted series

Forecasting using R Seasonal adjustment 43

Electrical equipment manufacturing

New

ord

ers

inde

x

2000 2005 2010

6070

8090

100

110

120

130

Page 80: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Seasonal adjustment in R

seasadj(obj)

where obj is the output from stl() or

decompose().

Exampleplot(hsales,col="gray")

fit <- stl(hsales,s.window=15)

hsales.sa <- seasadj(fit)

lines(hsales.sa, col="red")

Forecasting using R Seasonal adjustment 44

Page 81: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Seasonal adjustment in R

seasadj(obj)

where obj is the output from stl() or

decompose().

Exampleplot(hsales,col="gray")

fit <- stl(hsales,s.window=15)

hsales.sa <- seasadj(fit)

lines(hsales.sa, col="red")

Forecasting using R Seasonal adjustment 44

Page 82: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Outline

1 White noise

2 Time series decomposition

3 Seasonal adjustment

4 Forecasting and decomposition

Forecasting using R Forecasting and decomposition 45

Page 83: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting and decomposition

Forecast seasonal component by repeating thelast year

Forecast seasonally adjusted data usingnon-seasonal time series method. E.g.,

Holt’s method — next topicRandom walk with drift model

Combine forecasts of seasonal component withforecasts of seasonally adjusted data to getforecasts of original data.

Sometimes a decomposition is useful just forunderstanding the data before building aseparate forecasting model.

Forecasting using R Forecasting and decomposition 46

Page 84: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting and decomposition

Forecast seasonal component by repeating thelast year

Forecast seasonally adjusted data usingnon-seasonal time series method. E.g.,

Holt’s method — next topicRandom walk with drift model

Combine forecasts of seasonal component withforecasts of seasonally adjusted data to getforecasts of original data.

Sometimes a decomposition is useful just forunderstanding the data before building aseparate forecasting model.

Forecasting using R Forecasting and decomposition 46

Page 85: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting and decomposition

Forecast seasonal component by repeating thelast year

Forecast seasonally adjusted data usingnon-seasonal time series method. E.g.,

Holt’s method — next topicRandom walk with drift model

Combine forecasts of seasonal component withforecasts of seasonally adjusted data to getforecasts of original data.

Sometimes a decomposition is useful just forunderstanding the data before building aseparate forecasting model.

Forecasting using R Forecasting and decomposition 46

Page 86: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting and decomposition

Forecast seasonal component by repeating thelast year

Forecast seasonally adjusted data usingnon-seasonal time series method. E.g.,

Holt’s method — next topicRandom walk with drift model

Combine forecasts of seasonal component withforecasts of seasonally adjusted data to getforecasts of original data.

Sometimes a decomposition is useful just forunderstanding the data before building aseparate forecasting model.

Forecasting using R Forecasting and decomposition 46

Page 87: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting and decomposition

Forecast seasonal component by repeating thelast year

Forecast seasonally adjusted data usingnon-seasonal time series method. E.g.,

Holt’s method — next topicRandom walk with drift model

Combine forecasts of seasonal component withforecasts of seasonally adjusted data to getforecasts of original data.

Sometimes a decomposition is useful just forunderstanding the data before building aseparate forecasting model.

Forecasting using R Forecasting and decomposition 46

Page 88: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Forecasting and decomposition

Forecast seasonal component by repeating thelast year

Forecast seasonally adjusted data usingnon-seasonal time series method. E.g.,

Holt’s method — next topicRandom walk with drift model

Combine forecasts of seasonal component withforecasts of seasonally adjusted data to getforecasts of original data.

Sometimes a decomposition is useful just forunderstanding the data before building aseparate forecasting model.

Forecasting using R Forecasting and decomposition 46

Page 89: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Seas adj elec equipment

Forecasting using R Forecasting and decomposition 47

Electrical equipment manufacturing

New

ord

ers

inde

x

2000 2005 2010

6070

8090

100

110

120

130

Page 90: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Seas adj elec equipment

Forecasting using R Forecasting and decomposition 48

Naive forecasts of seasonally adjusted data

New

ord

ers

inde

x

2000 2005 2010

7080

9010

011

012

0

Page 91: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Seas adj elec equipment

Forecasting using R Forecasting and decomposition 49

Forecasts from STL + Random walk

New

ord

ers

inde

x

2000 2005 2010

4060

8010

012

0

Page 92: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

How to do this in R

fit <- stl(elecequip, t.window=15,s.window="periodic", robust=TRUE)

eeadj <- seasadj(fit)plot(naive(eeadj), xlab="New orders index")

fcast <- forecast(fit, method="naive")plot(fcast, ylab="New orders index")

Forecasting using R Forecasting and decomposition 50

Page 93: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Decomposition and prediction intervals

It is common to take the prediction

intervals from the seasonally adjusted

forecasts and modify them with the

seasonal component.

This ignores the uncertainty in the

seasonal component estimate.

It also ignores the uncertainty in the

future seasonal pattern.

Forecasting using R Forecasting and decomposition 51

Page 94: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Decomposition and prediction intervals

It is common to take the prediction

intervals from the seasonally adjusted

forecasts and modify them with the

seasonal component.

This ignores the uncertainty in the

seasonal component estimate.

It also ignores the uncertainty in the

future seasonal pattern.

Forecasting using R Forecasting and decomposition 51

Page 95: Forecasting using - Rob J. Hyndman...Rob J Hyndman Student award To students who make the most contribution to the class, as voted by their peers. Contributions can be on Piazza or

Decomposition and prediction intervals

It is common to take the prediction

intervals from the seasonally adjusted

forecasts and modify them with the

seasonal component.

This ignores the uncertainty in the

seasonal component estimate.

It also ignores the uncertainty in the

future seasonal pattern.

Forecasting using R Forecasting and decomposition 51