You are on page 1of 95

Rob J Hyndman

Forecasting using

4. White noise and time series decomposition


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

Forecasting using R 1
Student award
To students who make the most contribution to
the class, as voted by their peers.
Contributions can be on Piazza or during the
webex online sessions.
Contribute questions, answers, comments,
code suggestions, etc.
Looking for engaged learners, not experts.
At end of course, all students to vote for best
contributor.
$100 to the top voted student and $50 to
the second student (plus t-shirts).
Forecasting using R 2
Time zones

All sessions are at UTC 22:00


for the entire course.
Be aware when your time zone changes.
Most of Europe changed last Sunday. So classes
are now one hour earlier for most European
residents.
Most of USA and Canada change next Sunday.
So classes will be one hour earlier for most
North American residents from next week.

Forecasting using R 3
Outline

1 White noise

2 Time series decomposition

3 Seasonal adjustment

4 Forecasting and decomposition

Forecasting using R White noise 4


Example: White noise
White noise
2
1
0
x

−1
−2
−3

0 10 20 30 40 50

Time
Forecasting using R White noise 5
Example: White noise
White noise
2

White noise data is uncorrelated across


1

time with zero mean and constant variance.


(Technically, we require independence as
0

well.)
x

−1
−2
−3

0 10 20 30 40 50

Time
Forecasting using R White noise 5
Example: White noise
White noise
2

White noise data is uncorrelated across


1

time with zero mean and constant variance.


(Technically, we require independence as
0

well.)
x

−1

Think of white noise as completely


−2

uninteresting with no predictable patterns.


−3

0 10 20 30 40 50

Time
Forecasting using R White noise 5
Example: White noise
r1 = 0.013

0.4
r2 = −0.163
r3 = 0.163

0.2
r4 = −0.259

ACF

0.0
r5 = −0.198
r6 = 0.064
r7 = −0.139 −0.2

r8 = −0.032
−0.4

r9 = 0.199 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

r10 = −0.240 Lag

Sample autocorrelations for white noise series.


For uncorrelated data, we would expect each
autocorrelation to be close to zero.

Forecasting using R White noise 6


Sampling distribution of autocorrelations

Sampling distribution of rk for white noise data is


asymptotically 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 not
WN.

Common to plot lines at ±1.96/ T when
plotting ACF. These are the critical values.

Forecasting using R White noise 7


Sampling distribution of autocorrelations

Sampling distribution of rk for white noise data is


asymptotically 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 not
WN.

Common to plot lines at ±1.96/ T when
plotting ACF. These are the critical values.

Forecasting using R White noise 7


Sampling distribution of autocorrelations

Sampling distribution of rk for white noise data is


asymptotically 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 not
WN.

Common to plot lines at ±1.96/ T when
plotting ACF. These are the critical values.

Forecasting using R White noise 7


Sampling distribution of autocorrelations

Sampling distribution of rk for white noise data is


asymptotically 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 not
WN.

Common to plot lines at ±1.96/ T when
plotting ACF. These are the critical values.

Forecasting using R White noise 7


Autocorrelation
Example:

0.4
T = 50 and so

0.2
critical √
values at
±1.96/ 50 =

ACF

0.0
±0.28.

−0.2
All autocorrelation
coefficients lie within −0.4

these limits, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Lag

confirming that the


data are white noise.
(More precisely, the data cannot be
distinguished from white noise.)
Forecasting using R White noise 8
Example: Pigs slaughtered
Number of pigs slaughtered in Victoria
110
100
thousands

90
80

1990 1991 1992 1993 1994 1995

Forecasting using R White noise 9


Example: Pigs slaughtered
0.2
ACF

0.0
−0.2

0 10 20 30 40

Lag

Forecasting using R White noise 10


Example: Pigs slaughtered

Monthly total number of pigs slaughtered in the


state of Victoria, Australia, from January 1990
through August 1995. (Source: Australian Bureau of
Statistics.)
Difficult to detect pattern in time plot.
ACF shows some significant autocorrelation at
lags 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


Example: Pigs slaughtered

Monthly total number of pigs slaughtered in the


state of Victoria, Australia, from January 1990
through August 1995. (Source: Australian Bureau of
Statistics.)
Difficult to detect pattern in time plot.
ACF shows some significant autocorrelation at
lags 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


Example: Pigs slaughtered

Monthly total number of pigs slaughtered in the


state of Victoria, Australia, from January 1990
through August 1995. (Source: Australian Bureau of
Statistics.)
Difficult to detect pattern in time plot.
ACF shows some significant autocorrelation at
lags 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


Example: Pigs slaughtered

Monthly total number of pigs slaughtered in the


state of Victoria, Australia, from January 1990
through August 1995. (Source: Australian Bureau of
Statistics.)
Difficult to detect pattern in time plot.
ACF shows some significant autocorrelation at
lags 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


Example: Pigs slaughtered

Monthly total number of pigs slaughtered in the


state of Victoria, Australia, from January 1990
through August 1995. (Source: Australian Bureau of
Statistics.)
Difficult to detect pattern in time plot.
ACF shows some significant autocorrelation at
lags 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


Example: Pigs slaughtered

Monthly total number of pigs slaughtered in the


state of Victoria, Australia, from January 1990
through August 1995. (Source: Australian Bureau of
Statistics.)
Difficult to detect pattern in time plot.
ACF shows some significant autocorrelation at
lags 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


ACF of residuals
We assume that the residuals are white noise
(uncorrelated, mean zero, constant variance). If
they aren’t, then there is information left in the
residuals that should be used in computing
forecasts.
So a standard residual diagnostic is to check
the ACF of the residuals of a forecasting
method.
We expect these to look like white noise.
Dow-Jones naive forecasts revisited
ŷt|t−1 = yt−1
et = yt − yt−1
Forecasting using R White noise 12
ACF of residuals
We assume that the residuals are white noise
(uncorrelated, mean zero, constant variance). If
they aren’t, then there is information left in the
residuals that should be used in computing
forecasts.
So a standard residual diagnostic is to check
the ACF of the residuals of a forecasting
method.
We expect these to look like white noise.
Dow-Jones naive forecasts revisited
ŷt|t−1 = yt−1
et = yt − yt−1
Forecasting using R White noise 12
ACF of residuals
We assume that the residuals are white noise
(uncorrelated, mean zero, constant variance). If
they aren’t, then there is information left in the
residuals that should be used in computing
forecasts.
So a standard residual diagnostic is to check
the ACF of the residuals of a forecasting
method.
We expect these to look like white noise.
Dow-Jones naive forecasts revisited
ŷt|t−1 = yt−1
et = yt − yt−1
Forecasting using R White noise 12
ACF of residuals
We assume that the residuals are white noise
(uncorrelated, mean zero, constant variance). If
they aren’t, then there is information left in the
residuals that should be used in computing
forecasts.
So a standard residual diagnostic is to check
the ACF of the residuals of a forecasting
method.
We expect these to look like white noise.
Dow-Jones naive forecasts revisited
ŷt|t−1 = yt−1
et = yt − yt−1
Forecasting using R White noise 12
ACF of residuals
We assume that the residuals are white noise
(uncorrelated, mean zero, constant variance). If
they aren’t, then there is information left in the
residuals that should be used in computing
forecasts.
So a standard residual diagnostic is to check
the ACF of the residuals of a forecasting
method.
We expect these to look like white noise.
Dow-Jones naive forecasts revisited
ŷt|t−1 = yt−1
et = yt − yt−1
Forecasting using R White noise 12
Forecasting Dow-Jones index
50
Change in Dow−Jones index

0
−50
−100

0 50 100 150 200 250 300

Day

Forecasting using R White noise 13


Forecasting Dow-Jones index
0.15
0.10
0.05
ACF

−0.05
−0.15

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

Lag

Forecasting using R White noise 14


Example: Dow-Jones residuals

0.15
0.10
0.05
ACF

−0.05
−0.15

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

Lag

These look like white noise.


But the ACF is a multiple testing problem.

Forecasting using R White noise 15


Example: Dow-Jones residuals

0.15
0.10
0.05
ACF

−0.05
−0.15

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

Lag

These look like white noise.


But the ACF is a multiple testing problem.

Forecasting using R White noise 15


Portmanteau tests
Consider a whole set of rk values, and develop a
test to see whether the set is significantly different
from a zero set.

Forecasting using R White noise 16


Portmanteau tests
Consider a whole set of rk values, and develop a
test to see whether the set is significantly different
from a zero set.
Box-Pierce test
h
X
Q=T rk2
k =1
where h is max lag being considered and T is
number of observations.
My preferences: h = 10 for non-seasonal data, h = 2m
for seasonal data.
If each rk close to zero, Q will be small.
If some rk values large (positive or negative), Q will be
large.
Forecasting using R White noise 16
Portmanteau tests
Consider a whole set of rk values, and develop a
test to see whether the set is significantly different
from a zero set.
Box-Pierce test
h
X
Q=T rk2
k =1
where h is max lag being considered and T is
number of observations.
My preferences: h = 10 for non-seasonal data, h = 2m
for seasonal data.
If each rk close to zero, Q will be small.
If some rk values large (positive or negative), Q will be
large.
Forecasting using R White noise 16
Portmanteau tests
Consider a whole set of rk values, and develop a
test to see whether the set is significantly different
from a zero set.
Box-Pierce test
h
X
Q=T rk2
k =1
where h is max lag being considered and T is
number of observations.
My preferences: h = 10 for non-seasonal data, h = 2m
for seasonal data.
If each rk close to zero, Q will be small.
If some rk values large (positive or negative), Q will be
large.
Forecasting using R White noise 16
Portmanteau tests
Consider a whole set of rk values, and develop a
test to see whether the set is significantly different
from a zero set.
Box-Pierce test
h
X
Q=T rk2
k =1
where h is max lag being considered and T is
number of observations.
My preferences: h = 10 for non-seasonal data, h = 2m
for seasonal data.
If each rk close to zero, Q will be small.
If some rk values large (positive or negative), Q will be
large.
Forecasting using R White noise 16
Portmanteau tests
Consider a whole set of rk values, and develop a
test to see whether the set is significantly different
from a zero set.
Ljung-Box test
h
X

Q = T (T + 2) (T − k)−1 rk2
k =1
where h is max lag being considered and T is
number of observations.
My preferences: h = 10 for non-seasonal data, h = 2m
for seasonal data.
Better performance, especially in small samples.

Forecasting using R White noise 16


Portmanteau tests
If 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 test
X-squared = 14.0451, df = 10, p-value = 0.1709
> Box.test(res, lag=10, fitdf=0, type="Lj")
Box-Ljung test
X-squared = 14.4615, df = 10, p-value = 0.153
Forecasting using R White noise 17
Portmanteau tests
If 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 test
X-squared = 14.0451, df = 10, p-value = 0.1709
> Box.test(res, lag=10, fitdf=0, type="Lj")
Box-Ljung test
X-squared = 14.4615, df = 10, p-value = 0.153
Forecasting using R White noise 17
Portmanteau tests
If 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 test
X-squared = 14.0451, df = 10, p-value = 0.1709
> Box.test(res, lag=10, fitdf=0, type="Lj")
Box-Ljung test
X-squared = 14.4615, df = 10, p-value = 0.153
Forecasting using R White noise 17
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


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


Outline

1 White noise

2 Time series decomposition

3 Seasonal adjustment

4 Forecasting and decomposition

Forecasting using R Time series decomposition 20


Time series decomposition

Yt = f (St , Tt , Et )
where Yt = data at period t
St = seasonal component at period t
Tt = trend-cycle component at period t
Et = 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


Time series decomposition

Yt = f (St , Tt , Et )
where Yt = data at period t
St = seasonal component at period t
Tt = trend-cycle component at period t
Et = 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


Time series decomposition

Yt = f (St , Tt , Et )
where Yt = data at period t
St = seasonal component at period t
Tt = trend-cycle component at period t
Et = 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


Time series decomposition

Additive model appropriate if magnitude of


seasonal fluctuations does not vary with level.
If seasonal are proportional to level of series,
then multiplicative model appropriate.
Multiplicative decomposition more prevalent
with economic series
Logs turn multiplicative relationship into an
additive relationship:

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

Forecasting using R Time series decomposition 22


Time series decomposition

Additive model appropriate if magnitude of


seasonal fluctuations does not vary with level.
If seasonal are proportional to level of series,
then multiplicative model appropriate.
Multiplicative decomposition more prevalent
with economic series
Logs turn multiplicative relationship into an
additive relationship:

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

Forecasting using R Time series decomposition 22


Time series decomposition

Additive model appropriate if magnitude of


seasonal fluctuations does not vary with level.
If seasonal are proportional to level of series,
then multiplicative model appropriate.
Multiplicative decomposition more prevalent
with economic series
Logs turn multiplicative relationship into an
additive relationship:

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

Forecasting using R Time series decomposition 22


Time series decomposition

Additive model appropriate if magnitude of


seasonal fluctuations does not vary with level.
If seasonal are proportional to level of series,
then multiplicative model appropriate.
Multiplicative decomposition more prevalent
with economic series
Logs turn multiplicative relationship into an
additive relationship:

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

Forecasting using R Time series decomposition 22


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


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


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


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


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


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


Classical decomposition

90
70
data

50
30

10
5
seasonal

0
−5
−10
60
trend

50
40
30

10
remainder

0
−10
1975 1980 1985 1990 1995

time

Forecasting using R Time series decomposition 24


STL decomposition

90
70
data

50
30

10
5
seasonal

0
−10 −5
60
trend

50
40

5 10
remainder

−5 0
−15
1975 1980 1985 1990 1995

time

Forecasting using R Time series decomposition 25


Examples: US house sales
Sales of new one−family houses, USA
90
80
70
Total sales

60
50
40
30

1975 1980 1985 1990 1995

Forecasting using R Time series decomposition 26


Examples: US house sales
Sales of new one−family houses, USA
90
80
70
Total sales

60
50
40
30

1975 1980 1985 1990 1995

Forecasting using R Time series decomposition 27


Examples: US house sales
90
70
Data

50
30

1975 1980 1985 1990 1995

Time
5
Seasonal

0
−10

1975 1980 1985 1990 1995

Forecasting using R Time series decomposition 28


Examples: US house sales
90
70
Data

50
30

1975 1980 1985 1990 1995


15
5
Error

−5
−15

1975 1980 1985 1990 1995

Time

Forecasting using R Time series decomposition 29


Examples: US house sales
90
70
Data

50
30

1975 1980 1985 1990 1995


15
5
Error

−5
−15

1975 1980 1985 1990 1995

Time

Forecasting using R Time series decomposition 29


Examples: US house sales

90
70
data

50
30

10
5
seasonal

0
−10 −5
60
trend

50
40

5 10
remainder

−5 0
−15
1975 1980 1985 1990 1995

time

Forecasting using R Time series decomposition 30


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


Euro electrical equipment
Electrical equipment manufacturing (Euro area)
130
120
110
New orders index

100
90
80
70
60

2000 2005 2010

Forecasting using R Time series decomposition 32


Euro electrical equipment
Electrical equipment manufacturing (Euro area)
130
120
110
New orders index

100
90
80
70
60

2000 2005 2010

Forecasting using R Time series decomposition 33


Euro electrical equipment

120
100
data

80
60

10
5
seasonal

0
−10
−20
110
100
trend

90
80

6
4
remainder

2
0
−4
−8
2000 2005 2010

time
Forecasting using R Time series decomposition 34
Euro electrical equipment

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

100
data
plot(fit)

80
60

10
5
seasonal

0
−10
−20
110
100
trend

90
80

6
4
remainder

2
0
−4
−8
2000 2005 2010

time
Forecasting using R Time series decomposition 35
Euro electrical equipment
15
10
5
Seasonal

0
−5
−10
−15
−20

J F M A M J J A S O N D
Seasonal sub-series plot of the seasonal component
Forecasting using R Time series decomposition 36
Euro electrical equipment
15

monthplot(fit$time.series[,"seasonal"],
10

ylab="Seasonal")
5
Seasonal

0
−5
−10
−15
−20

J F M A M J J A S O N D
Seasonal sub-series plot of the seasonal component
Forecasting using R Time series decomposition 37
Euro electrical equipment

120
100
data

80
60

10
5
seasonal

0
−5
−15
110
100
trend

90
80

10
5
remainder

0
−5
2000 2005 2010

time
Forecasting using R Time series decomposition 38
Euro electrical equipment

120
fit <- stl(elecequip, t.window=15,

100
data
s.window="periodic", robust=TRUE)

80
plot(fit)

60

10
5
seasonal

0
−5
−15
110
100
trend

90
80

10
5
remainder

0
−5
2000 2005 2010

time
Forecasting using R Time series decomposition 39
Euro electrical equipment

120
fit <- stl(elecequip, t.window=15,

100
data
s.window="periodic", robust=TRUE)

80
plot(fit)

60

10
5
seasonal

0
t.window

−5
controls

−15
wiggliness of
110

trend
100
trend

component.
90
80

10
s.window

5
remainder

controls

0
variation in

−5
seasonal
2000 2005 2010

component. time
Forecasting using R Time series decomposition 40
Euro electrical equipment

120
fit <- stl(elecequip, t.window=15,

100
data
s.window="periodic", robust=TRUE)

80
plot(fit)

60

10
5
seasonal

0
t.window

−5
controls

−15
wiggliness of
110

trend
100
trend

component.
90
80

10
s.window

5
remainder

controls

0
variation in

−5
seasonal
2000 2005 2010

component. time
Forecasting using R Time series decomposition 40
Outline

1 White noise

2 Time series decomposition

3 Seasonal adjustment

4 Forecasting and decomposition

Forecasting using R Seasonal adjustment 41


Seasonal adjustment
Useful by-product of decomposition: an easy
way to calculate seasonally adjusted data.
Additive decomposition: seasonally adjusted
data given by

Yt − St = Tt + Et

Multiplicative decomposition: seasonally


adjusted data given by

Yt /St = Tt × Et

Forecasting using R Seasonal adjustment 42


Seasonal adjustment
Useful by-product of decomposition: an easy
way to calculate seasonally adjusted data.
Additive decomposition: seasonally adjusted
data given by

Yt − St = Tt + Et

Multiplicative decomposition: seasonally


adjusted data given by

Yt /St = Tt × Et

Forecasting using R Seasonal adjustment 42


Seasonal adjustment
Useful by-product of decomposition: an easy
way to calculate seasonally adjusted data.
Additive decomposition: seasonally adjusted
data given by

Yt − St = Tt + Et

Multiplicative decomposition: seasonally


adjusted data given by

Yt /St = Tt × Et

Forecasting using R Seasonal adjustment 42


Euro electrical equipment
Electrical equipment manufacturing
130
120
110
New orders index

100
90
80
70
60

2000 2005 2010


Seasonally adjusted series
Forecasting using R Seasonal adjustment 43
Seasonal adjustment in R

seasadj(obj)
where obj is the output from stl() or
decompose().
Example
plot(hsales,col="gray")
fit <- stl(hsales,s.window=15)
hsales.sa <- seasadj(fit)
lines(hsales.sa, col="red")

Forecasting using R Seasonal adjustment 44


Seasonal adjustment in R

seasadj(obj)
where obj is the output from stl() or
decompose().
Example
plot(hsales,col="gray")
fit <- stl(hsales,s.window=15)
hsales.sa <- seasadj(fit)
lines(hsales.sa, col="red")

Forecasting using R Seasonal adjustment 44


Outline

1 White noise

2 Time series decomposition

3 Seasonal adjustment

4 Forecasting and decomposition

Forecasting using R Forecasting and decomposition 45


Forecasting and decomposition
Forecast seasonal component by repeating the
last year
Forecast seasonally adjusted data using
non-seasonal time series method. E.g.,
Holt’s method — next topic
Random walk with drift model

Combine forecasts of seasonal component with


forecasts of seasonally adjusted data to get
forecasts of original data.
Sometimes a decomposition is useful just for
understanding the data before building a
separate forecasting model.
Forecasting using R Forecasting and decomposition 46
Forecasting and decomposition
Forecast seasonal component by repeating the
last year
Forecast seasonally adjusted data using
non-seasonal time series method. E.g.,
Holt’s method — next topic
Random walk with drift model

Combine forecasts of seasonal component with


forecasts of seasonally adjusted data to get
forecasts of original data.
Sometimes a decomposition is useful just for
understanding the data before building a
separate forecasting model.
Forecasting using R Forecasting and decomposition 46
Forecasting and decomposition
Forecast seasonal component by repeating the
last year
Forecast seasonally adjusted data using
non-seasonal time series method. E.g.,
Holt’s method — next topic
Random walk with drift model

Combine forecasts of seasonal component with


forecasts of seasonally adjusted data to get
forecasts of original data.
Sometimes a decomposition is useful just for
understanding the data before building a
separate forecasting model.
Forecasting using R Forecasting and decomposition 46
Forecasting and decomposition
Forecast seasonal component by repeating the
last year
Forecast seasonally adjusted data using
non-seasonal time series method. E.g.,
Holt’s method — next topic
Random walk with drift model

Combine forecasts of seasonal component with


forecasts of seasonally adjusted data to get
forecasts of original data.
Sometimes a decomposition is useful just for
understanding the data before building a
separate forecasting model.
Forecasting using R Forecasting and decomposition 46
Forecasting and decomposition
Forecast seasonal component by repeating the
last year
Forecast seasonally adjusted data using
non-seasonal time series method. E.g.,
Holt’s method — next topic
Random walk with drift model

Combine forecasts of seasonal component with


forecasts of seasonally adjusted data to get
forecasts of original data.
Sometimes a decomposition is useful just for
understanding the data before building a
separate forecasting model.
Forecasting using R Forecasting and decomposition 46
Forecasting and decomposition
Forecast seasonal component by repeating the
last year
Forecast seasonally adjusted data using
non-seasonal time series method. E.g.,
Holt’s method — next topic
Random walk with drift model

Combine forecasts of seasonal component with


forecasts of seasonally adjusted data to get
forecasts of original data.
Sometimes a decomposition is useful just for
understanding the data before building a
separate forecasting model.
Forecasting using R Forecasting and decomposition 46
Seas adj elec equipment
Electrical equipment manufacturing
130
120
110
New orders index

100
90
80
70
60

2000 2005 2010

Forecasting using R Forecasting and decomposition 47


Seas adj elec equipment
Naive forecasts of seasonally adjusted data
120
110
100
New orders index

90
80
70

2000 2005 2010

Forecasting using R Forecasting and decomposition 48


Seas adj elec equipment
Forecasts from STL + Random walk
120
100
New orders index

80
60
40

2000 2005 2010

Forecasting using R Forecasting and decomposition 49


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


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


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


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

You might also like