Forecasting using R - Rob J. Hyndman · Forecasting using R Box-Cox transformations 12. Automated...
Transcript of Forecasting using R - Rob J. Hyndman · Forecasting using R Box-Cox transformations 12. Automated...
Forecasting using R 1
Forecasting using R
Rob J Hyndman
2.2 Transformations
Outline
1 Variance stabilization
2 Box-Cox transformations
3 Lab session 9
Forecasting using R Variance stabilization 2
Variance stabilizationIf the data show different variation at different levels ofthe series, then a transformation can be useful.Denote original observations as y1, . . . , yn andtransformed observations 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 moreinterpretable: changes in a log value are relative (percent)changes on the original scale.
Forecasting using R Variance stabilization 3
Variance stabilizationIf the data show different variation at different levels ofthe series, then a transformation can be useful.Denote original observations as y1, . . . , yn andtransformed observations 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 moreinterpretable: changes in a log value are relative (percent)changes on the original scale.
Forecasting using R Variance stabilization 3
Variance stabilizationIf the data show different variation at different levels ofthe series, then a transformation can be useful.Denote original observations as y1, . . . , yn andtransformed observations 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 moreinterpretable: changes in a log value are relative (percent)changes on the original scale.
Forecasting using R Variance stabilization 3
Variance stabilizationIf the data show different variation at different levels ofthe series, then a transformation can be useful.Denote original observations as y1, . . . , yn andtransformed observations 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 moreinterpretable: changes in a log value are relative (percent)changes on the original scale.
Forecasting using R Variance stabilization 3
Variance stabilization
50
75
100
125
1960 1970 1980 1990Year
Square root electricity production
Forecasting using R Variance stabilization 4
Variance stabilization
15
20
25
1960 1970 1980 1990Year
Cube root electricity production
Forecasting using R Variance stabilization 5
Variance stabilization
8
9
1960 1970 1980 1990Year
Log electricity production
Forecasting using R Variance stabilization 6
Variance stabilization
−8e−04
−6e−04
−4e−04
−2e−04
1960 1970 1980 1990Year
Inverse electricity production
Forecasting using R Variance stabilization 7
Outline
1 Variance stabilization
2 Box-Cox transformations
3 Lab session 9
Forecasting using R Box-Cox transformations 8
Box-Cox transformations
Each of these transformations is close to a member of thefamily of Box-Cox transformations:
wt = log(yt), λ = 0;(yλt − 1)/λ, λ 6= 0.
λ = 1: (No substantive transformation)λ = 1
2 : (Square root plus linear transformation)λ = 0: (Natural logarithm)λ = −1: (Inverse plus 1)
Forecasting using R Box-Cox transformations 9
Box-Cox transformations
Each of these transformations is close to a member of thefamily of Box-Cox transformations:
wt = log(yt), λ = 0;(yλt − 1)/λ, λ 6= 0.
λ = 1: (No substantive transformation)λ = 1
2 : (Square root plus linear transformation)λ = 0: (Natural logarithm)λ = −1: (Inverse plus 1)
Forecasting using R Box-Cox transformations 9
Box-Cox transformations
Forecasting using R Box-Cox transformations 10
Box-Cox transformations
autoplot(BoxCox(elec,lambda=1/3))
30
40
50
60
70
1960 1970 1980 1990Time
Box
Cox
(ele
c, la
mbd
a =
1/3
)
Forecasting using R Box-Cox transformations 11
Box-Cox transformationsyλt for λ close to zero behaves like logs.If some yt = 0, then must have λ > 0if some yt < 0, no power transformation is possibleunless all yt adjusted by adding a constant to allvalues.Choose a simple value of λ. It makes explanationeasier.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 force forecasts tobe positive
Forecasting using R Box-Cox transformations 12
Automated Box-Cox transformations
(BoxCox.lambda(elec))
## [1] 0.2654076
This attempts to balance the seasonal fluctuationsand random variation across the series.Always check the results.A low value of λ can give extremely large predictionintervals.
Forecasting using R Box-Cox transformations 13
Automated Box-Cox transformations
(BoxCox.lambda(elec))
## [1] 0.2654076
This attempts to balance the seasonal fluctuationsand random variation across the series.Always check the results.A low value of λ can give extremely large predictionintervals.
Forecasting using R Box-Cox transformations 13
Back-transformation
Wemust reverse the transformation (or back-transform) toobtain forecasts on the original scale. The reverse Box-Coxtransformations are given by
yt = exp(wt), λ = 0;(λWt + 1)1/λ, λ 6= 0.
Forecasting using R Box-Cox transformations 14
Back-transformation
fit <- snaive(elec, lambda=1/3)autoplot(fit)
5000
10000
15000
1960 1970 1980 1990Time
y
level
80
95
Forecasts from Seasonal naive method
Forecasting using R Box-Cox transformations 15
Back-transformation
autoplot(fit, include=120)
10000
12000
14000
16000
1987.5 1990.0 1992.5 1995.0 1997.5Time
y
level
80
95
Forecasts from Seasonal naive method
Forecasting using R Box-Cox transformations 16
ETS and transformations
A Box-Cox transformation followed by an additive ETSmodel is often better than an ETS model withouttransformation.It makes no sense to use a Box-Cox transformationand a non-additive ETS model.
Forecasting using R Box-Cox transformations 17
Outline
1 Variance stabilization
2 Box-Cox transformations
3 Lab session 9
Forecasting using R Lab session 9 18
Lab Session 9
Forecasting using R Lab session 9 19