Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic...

68
Forecasting using 7. Transformations and adjustments OTexts.com/fpp/2/4/ Forecasting using R 1 Rob J Hyndman

Transcript of Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic...

Page 1: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Forecasting using

7. Transformations and adjustments

OTexts.com/fpp/2/4/

Forecasting using R 1

Rob J Hyndman

Page 2: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Outline

1 Exponential smoothing

2 Transformations

3 Adjustments

Forecasting using R Exponential smoothing 2

Page 3: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

ets() function

Automatically chooses a model by default usingthe AIC, AICc or BIC.

Can handle any combination of trend,seasonality and damping

Produces prediction intervals for every model

Ensures the parameters are admissible(equivalent to invertible)

Produces an object of class ets.

Forecasting using R Exponential smoothing 3

Page 4: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

ets() function

Automatically chooses a model by default usingthe AIC, AICc or BIC.

Can handle any combination of trend,seasonality and damping

Produces prediction intervals for every model

Ensures the parameters are admissible(equivalent to invertible)

Produces an object of class ets.

Forecasting using R Exponential smoothing 3

Page 5: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

ets() function

Automatically chooses a model by default usingthe AIC, AICc or BIC.

Can handle any combination of trend,seasonality and damping

Produces prediction intervals for every model

Ensures the parameters are admissible(equivalent to invertible)

Produces an object of class ets.

Forecasting using R Exponential smoothing 3

Page 6: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

ets() function

Automatically chooses a model by default usingthe AIC, AICc or BIC.

Can handle any combination of trend,seasonality and damping

Produces prediction intervals for every model

Ensures the parameters are admissible(equivalent to invertible)

Produces an object of class ets.

Forecasting using R Exponential smoothing 3

Page 7: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

ets() function

Automatically chooses a model by default usingthe AIC, AICc or BIC.

Can handle any combination of trend,seasonality and damping

Produces prediction intervals for every model

Ensures the parameters are admissible(equivalent to invertible)

Produces an object of class ets.

Forecasting using R Exponential smoothing 3

Page 8: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

ets objects

Methods: coef(), plot(), summary(),

residuals(), fitted(), simulate()

and forecast()

plot() function shows time plots of the

original time series along with the

extracted components (level, growth

and seasonal).

Forecasting using R Exponential smoothing 4

Page 9: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

ets objects

Methods: coef(), plot(), summary(),

residuals(), fitted(), simulate()

and forecast()

plot() function shows time plots of the

original time series along with the

extracted components (level, growth

and seasonal).

Forecasting using R Exponential smoothing 4

Page 10: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

Forecasting using R Exponential smoothing 5

200

400

600

obse

rved

250

350

450

leve

l

0.99

01.

005

slop

e

0.9

1.1

1960 1970 1980 1990 2000 2010

seas

on

Time

Decomposition by ETS(M,Md,M) methodplot(fit)

Page 11: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Goodness-of-fit

> accuracy(fit)ME RMSE MAE MPE MAPE MASE

0.17847 15.48781 11.77800 0.07204 2.81921 0.20705

> accuracy(fit2)ME RMSE MAE MPE MAPE MASE

-0.11711 15.90526 12.18930 -0.03765 2.91255 0.21428

Forecasting using R Exponential smoothing 6

Page 12: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Forecast intervals

Forecasting using R Exponential smoothing 7

Forecasts from ETS(M,Md,M)

1995 2000 2005 2010

300

350

400

450

500

550

600

> plot(forecast(fit,level=c(50,80,95)))

Page 13: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Forecast intervals

Forecasting using R Exponential smoothing 7

Forecasts from ETS(M,Md,M)

1995 2000 2005 2010

300

350

400

450

500

550

600

> plot(forecast(fit,fan=TRUE))

Page 14: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Exponential smoothing

ets() function also allows refitting model to newdata set.

> usfit <- ets(usnetelec[1:45])> test <- ets(usnetelec[46:55], model = usfit)

> accuracy(test)ME RMSE MAE MPE MAPE MASE

-3.35419 58.02763 43.85545 -0.07624 1.18483 0.52452

> accuracy(forecast(usfit,10), usnetelec[46:55])ME RMSE MAE MPE MAPE MASE

40.7034 61.2075 46.3246 1.0980 1.2620 0.6776

Forecasting using R Exponential smoothing 8

Page 15: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Unstable models

ETS(M,M,A)

ETS(M,Md,A)

ETS(A,N,M)

ETS(A,A,M)

ETS(A,Ad,M)

ETS(A,M,N)

ETS(A,M,A)

ETS(A,M,M)

ETS(A,Md,N)

ETS(A,Md,A)

ETS(A,Md,M)Forecasting using R Exponential smoothing 9

Page 16: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Unstable models

ETS(M,M,A)

ETS(M,Md,A)

ETS(A,N,M)

ETS(A,A,M)

ETS(A,Ad,M)

ETS(A,M,N)

ETS(A,M,A)

ETS(A,M,M)

ETS(A,Md,N)

ETS(A,Md,A)

ETS(A,Md,M)Forecasting using R Exponential smoothing 9

In practice, the modelswork fine for short- tomedium-term forecastsprovided the data arestrictly positive.

Page 17: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Forecastability conditions

ets(y, model="ZZZ", damped=NULL, alpha=NULL,beta=NULL, gamma=NULL, phi=NULL,additive.only=FALSE,lower=c(rep(0.0001,3),0.80),upper=c(rep(0.9999,3),0.98),opt.crit=c("lik","amse","mse","sigma"),nmse=3,bounds=c("both","usual","admissible"),ic=c("aic","aicc","bic"), restrict=TRUE)

Forecasting using R Exponential smoothing 10

Page 18: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

The magic forecast() function

forecast returns forecasts when applied to anets object (or the output from many other timeseries models).

If you use forecast directly on data, it willselect an ETS model automatically and thenreturn forecasts.

Forecasting using R Exponential smoothing 11

Page 19: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

The magic forecast() function

forecast returns forecasts when applied to anets object (or the output from many other timeseries models).

If you use forecast directly on data, it willselect an ETS model automatically and thenreturn forecasts.

Forecasting using R Exponential smoothing 11

Page 20: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Outline

1 Exponential smoothing

2 Transformations

3 Adjustments

Forecasting using R Transformations 12

Page 21: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Transformations to stabilize the variance

If the data show different variation at different levels of theseries, then a transformation can be useful.Denote original observations as y1, . . . , yn and transformedobservations as w1, . . . ,wn.

Mathematical transformations for stabilizing variation

Square root wt =√yt ↓

Cube root wt = 3√yt Increasing

Logarithm wt = log(yt) strength

Logarithms, in particular, are useful because they are more

interpretable: changes in a log value are relative (percent)

changes on the original scale.

Forecasting using R Transformations 13

Page 22: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Transformations to stabilize the variance

If the data show different variation at different levels of theseries, then a transformation can be useful.Denote original observations as y1, . . . , yn and transformedobservations as w1, . . . ,wn.

Mathematical transformations for stabilizing variation

Square root wt =√yt ↓

Cube root wt = 3√yt Increasing

Logarithm wt = log(yt) strength

Logarithms, in particular, are useful because they are more

interpretable: changes in a log value are relative (percent)

changes on the original scale.

Forecasting using R Transformations 13

Page 23: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Transformations to stabilize the variance

If the data show different variation at different levels of theseries, then a transformation can be useful.Denote original observations as y1, . . . , yn and transformedobservations as w1, . . . ,wn.

Mathematical transformations for stabilizing variation

Square root wt =√yt ↓

Cube root wt = 3√yt Increasing

Logarithm wt = log(yt) strength

Logarithms, in particular, are useful because they are more

interpretable: changes in a log value are relative (percent)

changes on the original scale.

Forecasting using R Transformations 13

Page 24: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Transformations to stabilize the variance

If the data show different variation at different levels of theseries, then a transformation can be useful.Denote original observations as y1, . . . , yn and transformedobservations as w1, . . . ,wn.

Mathematical transformations for stabilizing variation

Square root wt =√yt ↓

Cube root wt = 3√yt Increasing

Logarithm wt = log(yt) strength

Logarithms, in particular, are useful because they are more

interpretable: changes in a log value are relative (percent)

changes on the original scale.

Forecasting using R Transformations 13

Page 25: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Transformations

Forecasting using R Transformations 14

Square root electricity production

Year

1960 1970 1980 1990

4060

8010

012

0

Page 26: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Transformations

Forecasting using R Transformations 14

Cube root electricity production

Year

1960 1970 1980 1990

1214

1618

2022

24

Page 27: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Transformations

Forecasting using R Transformations 14

Log electricity production

Year

1960 1970 1980 1990

7.5

8.0

8.5

9.0

9.5

Page 28: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Transformations

Forecasting using R Transformations 14

Inverse electricity production

Year

1960 1970 1980 1990

−8e

−04

−6e

−04

−4e

−04

−2e

−04

Page 29: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

Each of these transformations is close to a memberof the family of Box-Cox transformations:

wt =

{log(yt), λ = 0;(yλt − 1)/λ, λ 6= 0.

λ = 1: (No substantive transformation)

λ = 12: (Square root plus linear transformation)

λ = 0: (Natural logarithm)

λ = −1: (Inverse plus 1)

Forecasting using R Transformations 15

Page 30: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

Each of these transformations is close to a memberof the family of Box-Cox transformations:

wt =

{log(yt), λ = 0;(yλt − 1)/λ, λ 6= 0.

λ = 1: (No substantive transformation)

λ = 12: (Square root plus linear transformation)

λ = 0: (Natural logarithm)

λ = −1: (Inverse plus 1)

Forecasting using R Transformations 15

Page 31: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

Each of these transformations is close to a memberof the family of Box-Cox transformations:

wt =

{log(yt), λ = 0;(yλt − 1)/λ, λ 6= 0.

λ = 1: (No substantive transformation)

λ = 12: (Square root plus linear transformation)

λ = 0: (Natural logarithm)

λ = −1: (Inverse plus 1)

Forecasting using R Transformations 15

Page 32: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

Each of these transformations is close to a memberof the family of Box-Cox transformations:

wt =

{log(yt), λ = 0;(yλt − 1)/λ, λ 6= 0.

λ = 1: (No substantive transformation)

λ = 12: (Square root plus linear transformation)

λ = 0: (Natural logarithm)

λ = −1: (Inverse plus 1)

Forecasting using R Transformations 15

Page 33: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

Each of these transformations is close to a memberof the family of Box-Cox transformations:

wt =

{log(yt), λ = 0;(yλt − 1)/λ, λ 6= 0.

λ = 1: (No substantive transformation)

λ = 12: (Square root plus linear transformation)

λ = 0: (Natural logarithm)

λ = −1: (Inverse plus 1)

Forecasting using R Transformations 15

Page 34: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

Forecasting using R Transformations 16

Page 35: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

yλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation ispossible unless all yt adjusted by adding aconstant to all values.Choose a simple value of λ. It makesexplanation easier.Results are relatively insensitive to value of λOften no transformation (λ = 1) needed.Transformation often makes little difference toforecasts but has large effect on PI.Choosing λ = 0 is a simple way to forceforecasts to be positive

Forecasting using R Transformations 17

Page 36: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

yλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation ispossible unless all yt adjusted by adding aconstant to all values.Choose a simple value of λ. It makesexplanation easier.Results are relatively insensitive to value of λOften no transformation (λ = 1) needed.Transformation often makes little difference toforecasts but has large effect on PI.Choosing λ = 0 is a simple way to forceforecasts to be positive

Forecasting using R Transformations 17

Page 37: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

yλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation ispossible unless all yt adjusted by adding aconstant to all values.Choose a simple value of λ. It makesexplanation easier.Results are relatively insensitive to value of λOften no transformation (λ = 1) needed.Transformation often makes little difference toforecasts but has large effect on PI.Choosing λ = 0 is a simple way to forceforecasts to be positive

Forecasting using R Transformations 17

Page 38: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

yλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation ispossible unless all yt adjusted by adding aconstant to all values.Choose a simple value of λ. It makesexplanation easier.Results are relatively insensitive to value of λOften no transformation (λ = 1) needed.Transformation often makes little difference toforecasts but has large effect on PI.Choosing λ = 0 is a simple way to forceforecasts to be positive

Forecasting using R Transformations 17

Page 39: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

yλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation ispossible unless all yt adjusted by adding aconstant to all values.Choose a simple value of λ. It makesexplanation easier.Results are relatively insensitive to value of λOften no transformation (λ = 1) needed.Transformation often makes little difference toforecasts but has large effect on PI.Choosing λ = 0 is a simple way to forceforecasts to be positive

Forecasting using R Transformations 17

Page 40: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

yλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation ispossible unless all yt adjusted by adding aconstant to all values.Choose a simple value of λ. It makesexplanation easier.Results are relatively insensitive to value of λOften no transformation (λ = 1) needed.Transformation often makes little difference toforecasts but has large effect on PI.Choosing λ = 0 is a simple way to forceforecasts to be positive

Forecasting using R Transformations 17

Page 41: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

yλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation ispossible unless all yt adjusted by adding aconstant to all values.Choose a simple value of λ. It makesexplanation easier.Results are relatively insensitive to value of λOften no transformation (λ = 1) needed.Transformation often makes little difference toforecasts but has large effect on PI.Choosing λ = 0 is a simple way to forceforecasts to be positive

Forecasting using R Transformations 17

Page 42: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Box-Cox transformations

yλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation ispossible unless all yt adjusted by adding aconstant to all values.Choose a simple value of λ. It makesexplanation easier.Results are relatively insensitive to value of λOften no transformation (λ = 1) needed.Transformation often makes little difference toforecasts but has large effect on PI.Choosing λ = 0 is a simple way to forceforecasts to be positive

Forecasting using R Transformations 17

Page 43: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Back-transformation

We must reverse the transformation (orback-transform) to obtain forecasts on the originalscale. The reverse Box-Cox transformations aregiven by

yt =

{exp(wt), λ = 0;(λWt + 1)1/λ, λ 6= 0.

plot(BoxCox(elec,lambda=1/3))fit <- snaive(elec, lambda=1/3)plot(fit)plot(fit, include=120)

Forecasting using R Transformations 18

Page 44: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Back-transformation

We must reverse the transformation (orback-transform) to obtain forecasts on the originalscale. The reverse Box-Cox transformations aregiven by

yt =

{exp(wt), λ = 0;(λWt + 1)1/λ, λ 6= 0.

plot(BoxCox(elec,lambda=1/3))fit <- snaive(elec, lambda=1/3)plot(fit)plot(fit, include=120)

Forecasting using R Transformations 18

Page 45: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Automated Box-Cox transformations

BoxCox.lambda(elec)

This attempts to balance the seasonalfluctuations and random variation across theseries.

Always check the results.

A low value of λ can give extremely largeprediction intervals.

Forecasting using R Transformations 19

Page 46: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Automated Box-Cox transformations

BoxCox.lambda(elec)

This attempts to balance the seasonalfluctuations and random variation across theseries.

Always check the results.

A low value of λ can give extremely largeprediction intervals.

Forecasting using R Transformations 19

Page 47: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Automated Box-Cox transformations

BoxCox.lambda(elec)

This attempts to balance the seasonalfluctuations and random variation across theseries.

Always check the results.

A low value of λ can give extremely largeprediction intervals.

Forecasting using R Transformations 19

Page 48: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Automated Box-Cox transformations

BoxCox.lambda(elec)

This attempts to balance the seasonalfluctuations and random variation across theseries.

Always check the results.

A low value of λ can give extremely largeprediction intervals.

Forecasting using R Transformations 19

Page 49: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

ETS and transformations

A Box-Cox transformation followed by anadditive ETS model is often better than an ETSmodel without transformation.

A Box-Cox transformation followed by STL +ETS is often better than an ETS model withouttransformation.

It makes no sense to use a Box-Coxtransformation and a non-additive ETS model.

Forecasting using R Transformations 20

Page 50: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

ETS and transformations

A Box-Cox transformation followed by anadditive ETS model is often better than an ETSmodel without transformation.

A Box-Cox transformation followed by STL +ETS is often better than an ETS model withouttransformation.

It makes no sense to use a Box-Coxtransformation and a non-additive ETS model.

Forecasting using R Transformations 20

Page 51: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

ETS and transformations

A Box-Cox transformation followed by anadditive ETS model is often better than an ETSmodel without transformation.

A Box-Cox transformation followed by STL +ETS is often better than an ETS model withouttransformation.

It makes no sense to use a Box-Coxtransformation and a non-additive ETS model.

Forecasting using R Transformations 20

Page 52: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Outline

1 Exponential smoothing

2 Transformations

3 Adjustments

Forecasting using R Adjustments 21

Page 53: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Calendar adjustments

Some of the variation in a time series may be due tothe variation in the number of trading days eachmonth. It is a good idea to adjust for this knownsource of variation to allow study of otherinteresting features.

Month length

Trading day

Forecasting using R Adjustments 22

Page 54: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Calendar adjustments

Some of the variation in a time series may be due tothe variation in the number of trading days eachmonth. It is a good idea to adjust for this knownsource of variation to allow study of otherinteresting features.

Month length

Trading day

Forecasting using R Adjustments 22

Page 55: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Month length adjustment

If this is not removed, it shows up as a seasonaleffect, which may not cause problems though itdoes make any seasonal pattern hard to interpret. Itis easily adjusted for:

y∗t = yt ×no. of days in an average month

no. of days in month t

= yt ×365.25/12

no. of days in month t

where yt has already been transformed if necessary.

monthdays gives the number of days in each monthor quarter.

Forecasting using R Adjustments 23

Page 56: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Month length adjustment

If this is not removed, it shows up as a seasonaleffect, which may not cause problems though itdoes make any seasonal pattern hard to interpret. Itis easily adjusted for:

y∗t = yt ×no. of days in an average month

no. of days in month t

= yt ×365.25/12

no. of days in month t

where yt has already been transformed if necessary.

monthdays gives the number of days in each monthor quarter.

Forecasting using R Adjustments 23

Page 57: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Trading day adjustmentoccurs in monthly data when there is also aweekly cycle, since proportions of various daysin given month vary from year to year.number of trading days is predictable, buteffects of various days are unknown.Simplest case: All trading days assumed tohave same effect.

y∗t = yt ×no. of trading days in average month

no. of trading days in month t.

where yt has already been adjusted for monthlength and transformed if necessary.If weekly cycle more complex, these effectsmust be estimated from data.

Forecasting using R Adjustments 24

Page 58: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Trading day adjustmentoccurs in monthly data when there is also aweekly cycle, since proportions of various daysin given month vary from year to year.number of trading days is predictable, buteffects of various days are unknown.Simplest case: All trading days assumed tohave same effect.

y∗t = yt ×no. of trading days in average month

no. of trading days in month t.

where yt has already been adjusted for monthlength and transformed if necessary.If weekly cycle more complex, these effectsmust be estimated from data.

Forecasting using R Adjustments 24

Page 59: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Trading day adjustmentoccurs in monthly data when there is also aweekly cycle, since proportions of various daysin given month vary from year to year.number of trading days is predictable, buteffects of various days are unknown.Simplest case: All trading days assumed tohave same effect.

y∗t = yt ×no. of trading days in average month

no. of trading days in month t.

where yt has already been adjusted for monthlength and transformed if necessary.If weekly cycle more complex, these effectsmust be estimated from data.

Forecasting using R Adjustments 24

Page 60: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Trading day adjustmentoccurs in monthly data when there is also aweekly cycle, since proportions of various daysin given month vary from year to year.number of trading days is predictable, buteffects of various days are unknown.Simplest case: All trading days assumed tohave same effect.

y∗t = yt ×no. of trading days in average month

no. of trading days in month t.

where yt has already been adjusted for monthlength and transformed if necessary.If weekly cycle more complex, these effectsmust be estimated from data.

Forecasting using R Adjustments 24

Page 61: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Explainable variation

Examples:

Calendar variation

Increasing population

Inflation

Strikes

Changes in government

Changes in law

Try and understand all possible sources of variationbefore modelling the time series.

Forecasting using R Adjustments 25

Page 62: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Explainable variation

Examples:

Calendar variation

Increasing population

Inflation

Strikes

Changes in government

Changes in law

Try and understand all possible sources of variationbefore modelling the time series.

Forecasting using R Adjustments 25

Page 63: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Explainable variation

Examples:

Calendar variation

Increasing population

Inflation

Strikes

Changes in government

Changes in law

Try and understand all possible sources of variationbefore modelling the time series.

Forecasting using R Adjustments 25

Page 64: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Explainable variation

Examples:

Calendar variation

Increasing population

Inflation

Strikes

Changes in government

Changes in law

Try and understand all possible sources of variationbefore modelling the time series.

Forecasting using R Adjustments 25

Page 65: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Explainable variation

Examples:

Calendar variation

Increasing population

Inflation

Strikes

Changes in government

Changes in law

Try and understand all possible sources of variationbefore modelling the time series.

Forecasting using R Adjustments 25

Page 66: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Explainable variation

Examples:

Calendar variation

Increasing population

Inflation

Strikes

Changes in government

Changes in law

Try and understand all possible sources of variationbefore modelling the time series.

Forecasting using R Adjustments 25

Page 67: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Explainable variation

Examples:

Calendar variation

Increasing population

Inflation

Strikes

Changes in government

Changes in law

Try and understand all possible sources of variationbefore modelling the time series.

Forecasting using R Adjustments 25

Page 68: Forecasting using - Rob J Hyndman · Forecasting using R Exponential smoothing 10. The magic forecast() function ... adjusted by. adding a constant to all values. Choose a simple

Explainable variation

Examples:

Calendar variation

Increasing population

Inflation

Strikes

Changes in government

Changes in law

Try and understand all possible sources of variationbefore modelling the time series.

Forecasting using R Adjustments 25