Time Series: Chapter 5 - Forecasting

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

Time Series

Chapter 5 - Forecasting

Forecasting (Time Series) Chapter 5 1 / 36


...
Agenda

1 Introduction

2 Box and Jenkins Approach


ARMA models
ARIMA models

3 Holt-Winters Approach

4 Summary: Time Series Analysis

5 Treasury Bill Example

6 Accident Death Example

Forecasting (Time Series) Chapter 5 2 / 36


...
Introduction
Forecast function

n def
Ybn+h ≡ Yn+h = E(Yn+h |Yn , Yn−1 , . . . , Y1 )
n
Yn+h is a function of the observation (Y1 , . . . , Yn ) used for prediction
Yn+h is the unknown future value
Forecast error
n
en (h) = Yn+h − Yn+h
Variance of forecast error
h i
n n
Pn+h = Var(en (h)|Yn , . . . , Y1 ) = E (Yn+h − Yn+h )2 |Yn , . . . , Y1

95% Prediction Interval for Yn+h


 q q 
n n ,Y n n
Yn+h − 1.96 Pn+h n+h + 1.96 Pn+h

Forecasting (Time Series) Chapter 5 3 / 36


...
Agenda

1 Introduction

2 Box and Jenkins Approach


ARMA models
ARIMA models

3 Holt-Winters Approach

4 Summary: Time Series Analysis

5 Treasury Bill Example

6 Accident Death Example

Forecasting (Time Series) Chapter 5 4 / 36


...
Agenda

1 Introduction

2 Box and Jenkins Approach


ARMA models
ARIMA models

3 Holt-Winters Approach

4 Summary: Time Series Analysis

5 Treasury Bill Example

6 Accident Death Example

Forecasting (Time Series) Chapter 5 5 / 36


...
Box and Jenkins Approach (General (but tedious) Version)
Work for causal and invertible ARMA(p,q) model : φ(B)Yt = θ(B)Zt
Causal Representation: Yt = ∞
P
i=0 ψi Zt−i
i)

ii) Forecast: Using E(Zs |Yn , . . . , Y1 ) = Zs · 1{s≤n} , we have



X ∞
X
n
Yn+h = E(Yn+h |Yn , . . . , Y1 ) = E( ψi Zn+h−i |Yn , . . . , Y1 ) = ψi Zn+h−i
i=0 i=h
n Ph−1
iii) Forecast error: en (h) = Yn+h − Yn+h = i=0 ψi Zn+h−i
iv) Variance of forecast error
Xh−1
n
Pn+h = Var(en (h)|Yn , . . . , Y1 ) = σ 2 ψi2
i=0
v) 95% prediction interval for Yn+h :
q
n n
Yn+h ± 1.96 Pn+h

Past noises Zk , k ≤ n can be solved from the ARMA equation recursively by


assuming that Zn = 0 for n ≤ p. (Invertibility needed!)
Future noises Zk , k > n are unknown and are treated as 0 (their expectation)
Forecasting (Time Series) Chapter 5 6 / 36
...
Box and Jenkins Approach (Recursive Version)
Work for causal and invertible ARMA(p,q) model : φ(B)Yt = θ(B)Zt
i) Recursively find Zk , k ≤ n from Y1 , . . . , Yn .
ii) n
Recursively find Yn+h and en (h) = Yn+h − Yn+h n , h ≥ 1:

•Yn+1 = φ1 Yn + · · · + φp Yn+1−p + Zn+1 + θ1 Zn + · · · + θq Zn+1−q


n
Yn+1 = φ1 Yn + · · · + φp Yn+1−p + 0 + θ1 Zn + · · · + θq Zn+1−q
n
en (1) = Yn+1 − Yn+1 = Zn+1 .
•Yn+2 = φ1 Yn+1 + · · · + φp Yn+2−p + Zn+2 + θ1 Zn+1 + · · · + θq Zn+2−q
n n
Yn+2 = φ1 Yn+1 + · · · + φp Yn+2−p + 0 + 0 + θ2 Zn + · · · + θq Zn+2−q
n
en (2) = φ1 (Yn+1 − Yn+1 ) + Zn+2 + θ1 Zn+1 = φ1 en (1) + Zn+2 + θ1 Zn+1
n n n
•Yn+3 = φ1 Yn+2 + φ2 Yn+1 + φ3 Yn + · · · + φp Yn+3−p + θ3 Zn + · · · + θq Zn+3−q
en (3) = φ1 en (2) + φ2 en (1) + Zn+3 + θ1 Zn+2 + θ2 Zn+1
··· = ···
n n n n
•Yn+h = φ1 Yn+h−1 + φ2 Yn+h−2 + · · · + φp Yn+h−p
en (h) = φ1 en (h − 1) + φ2 en (h − 2) + · · · + φp en (h − p)
+Zn+h + θ1 Zn+h−1 + · · · + θq Zn+h−q . (h > max(p, q))

n
p
iii) 95% Prediction interval: Yn+h ± 1.96 Var(en (h)|Yn , . . . , Y1 )
Forecasting (Time Series) Chapter 5 7 / 36
...
Box and Jenkins Approach: Example 1 (General Version)
Example : AR(1) : Yt = αYt−1 + Zt , Zt ∼ N (0, σ 2 )
Causal Representation: Yt = ∞ i
P
i=0 α Zt−i .
i)

ii) Forecast:

X
n
Yn+h = E(Yn+h |Yn , Yn−1 , . . . , Y1 ) = E( αi Zn+h−i |Yn , . . . , Y1 )
i=0

X ∞
X
= αi Zn+h−i = αh αi Zn−i = αh Yn .
i=h i=0

n Ph−1 i
iii) Forecast error: en (h) = Yn+h − Yn+h = i=0 α Zn+h−i
iv) Variance of forecast error:
h−1
n
X 1 − α2h
Pn+h = Var(en (h)) = σ 2 α2i = σ 2 .
i=0
1 − α2
q
1−α2h
v) 95% Prediction interval: αh Yn ± 1.96σ 1−α2
Forecasting (Time Series) Chapter 5 8 / 36
...
Box and Jenkins Approach: Example 1 (Recursive Version)
Example : AR(1) : Yt = αYt−1 + Zt , Zt ∼ N (0, σ 2 )
i) 1-Step forecast
n
Yn+1 = E(Yn+1 |Yn , . . . , Y1 ) = E(αYn + Zn+1 |Yn , . . . , Y1 ) = αYn
n
en (1) = Yn+1 − Yn+1 = Zn+1
n 2
Pn+1 = Var(en (1)|Yn , . . . Y1 ) = E(Zn+1 ) = σ2
ii) 2-Step forecast
n n
Yn+2 = E(αYn+1 + Zn+2 |Yn , . . . , Y1 ) = αYn+1 = α2 Yn
n n
en (2) = Yn+2 − Yn+2 = α(Yn+1 − Yn+1 ) + Zn+2 = αZn+1 + Zn+2
n
Pn+2 = Var(en (2)|Yn , . . . Y1 ) = σ 2 (1 + α2 )

iii) 95% Prediction intervals


1-Step: αYn ± 1.96σ

2-Step: α2 Yn ± 1.96σ 1 + α2
q
1−α2h
Agree with general version: αh Yn ± 1.96σ 1−α2
Forecasting (Time Series) Chapter 5 9 / 36
...
Box and Jenkins Approach: Example 2
SARIMA(1, 0, 0) × (0, 1, 1)12 Model:
Yn − Yn−12 = φ(Yn−1 − Yn−13 ) + Zn − θZn−12
Forecast:
n
One-step: Yn+1 = Yn−11 + φ(Yn − Yn−12 ) − θZn−11
n n
Two-step: Yn+2 = Yn−10 + φ(Yn+1 − Yn−11 ) − θZn−10
Forecast Error:
n
One-step: Yn+1 − Yn+1 = Zn+1
n n
Two-step: Yn+2 − Yn+2 = Zn+2 + φ(Yn+1 − Yn+1 ) = Zn+2 + φZn+1
Variance of forecast error:
n
One-step: Pn+1 = Var(Zn+1 ) = σ 2
n
Two-step: Pn+2 = Var(Zn+2 + φZn+1 ) = (1 + φ2 )σ 2
95% Prediction Intervals:
n n n
p
One-step: Yn+1 ± 1.96 Pn+1 = Yn+1 ± 1.96σ
p
n n n
p
Two-step: Yn+2 ± 1.96 Pn+2 = Yn+2 ± 1.96σ 1 + φ2
Forecasting (Time Series) Chapter 5 10 / 36
...
Box and Jenkins Approach: Example 3
ARMA(2,2) model
Yt = φ1 Yt−1 + φ2 Yt−2 + Zt + θ1 Zt−1 + θ2 Zt−2
Assume that Zn = 0 for n ≤ p = 2, we have,
Y3 = φ1 Y2 + φ2 Y1 + Z3 ⇒ get Z3
Y4 = φ1 Y3 + φ2 Y2 + Z4 + θ1 Z3 ⇒ get Z4
Y5 = φ1 Y4 + φ2 Y3 + Z5 + θ1 Z4 + θ2 Z3 ⇒ get Z5
Recursively get Z6 , Z7 , . . ., Zn
n
Yn+1 = φ1 Yn + φ2 Yn−1 + θ1 Zn + θ2 Zn−1
n n n n n
Yn+2 = φ1 Yn+1 + φ2 Yn + θ2 Zn ; Yn+h = φ1 Yn+h−1 + φ2 Yn+h−2 ;
R-codes:
set.seed(123);n=200;x=arima.sim(n,model=list(ar=c(0.5,0.2),ma=c(0.1,0.6)))
fit=arima(x,order=c(2,0,2),include.mean=F);p=fit$coef
Z=rep(0,n);for (j in 3:n){
Z[j]=x[j]-p[1]*x[j-1]-p[2]*x[j-2]-p[3]*Z[j-1]-p[4]*Z[j-2] }
Pred1=p[1]*x[n]+p[2]*x[n-1]+p[3]*Z[n]+p[4]*Z[n-1]
Pred2=p[1]*Pred1+p[2]*x[n]+p[4]*Z[n]
Pred1;Pred2
predict(fit,n.ahead=2)
Forecasting (Time Series) Chapter 5 11 / 36
...
Agenda

1 Introduction

2 Box and Jenkins Approach


ARMA models
ARIMA models

3 Holt-Winters Approach

4 Summary: Time Series Analysis

5 Treasury Bill Example

6 Accident Death Example

Forecasting (Time Series) Chapter 5 12 / 36


...
Forecasting ARIMA models
ARIMA models (d = 1 for simplicity): φ(B)(1 − B)Yt = θ(B)Zt .
Xt = (1 − B)Yt follows ARMA model
n
Let Xn+h and en,X (h) be the forecast and error for {Xt }.
Forecast for the ARIMA process {Yt }:
Yn+h = Xn+h + Yn+h−1 = · · · = Xn+h + Xn+h−1 + · · · + Xn+1 + Yn ,
n n n n
Yn+h = Xn+h + Xn+h−1 + · · · + Xn+1 + Yn

Forecast error for the ARIMA process {Yt }:


h
X h
X
n n
en,Y (h) = Yn+h − Yn+h = (Xn+j − Xn+j )= en,X (j) .
j=1 j=1
P 
n h
Variance of forecast error: Pn+h = Var j=1 en,X (j) .
 q 
n
95% P.I. for Yn+h : Yn+h n )
± 1.96 Var(Pn+h
Forecasting (Time Series) Chapter 5 13 / 36
...
Forecasting ARIMA models: Example 1
ARIMA(0,1,2) : (1 − B)Yt = Xt = Zt + θ1 Zt−1 + θ2 Zt−2 , Zt ∼ N (0, σ 2 )
i) 1-Step forecast
n
Xn+1 = E(Zn+1 + θ1 Zn + θ2 Zn−1 |Yn , . . . , Y1 ) = θ1 Zn + θ2 Zn−1
n n
Yn+1 = Xn+1 + Yn
n
en,X (1) = Xn+1 − Xn+1 = Zn+1
en,Y (1) = en,X (1) = Zn+1
n 2
Pn+1 = Var(en,Y (1)|Yn , . . . Y1 ) = E(Zn+1 ) = σ2

ii) 2-Step forecast


n
Xn+2 = E(Zn+2 + θ1 Zn+1 + θ2 Zn |Yn , . . . , Y1 ) = θ2 Zn
n n n
Yn+2 = Xn+2 + Xn+1 + Yn
n
en,X (2) = Xn+2 − Xn+2 = Zn+2 + θ1 Zn+1
en,Y (2) = en,X (1) + en,X (2) = Zn+2 + (1 + θ1 )Zn+1
n

Pn+2 = Var en,Y (2)|Yn , . . . Y1 = E(Zn+2 + (1 + θ1 )Zn+1 )2 = σ 2 (2 + 2θ1 + θ12 )
iii) 95% Prediction intervals
n
1-Step: Yn+1 ± 1.96σ
p
n
2-Step: Yn+2 ± 1.96σ 2 + 2θ1 + θ12
Forecasting (Time Series) Chapter 5 14 / 36
...
Agenda

1 Introduction

2 Box and Jenkins Approach


ARMA models
ARIMA models

3 Holt-Winters Approach

4 Summary: Time Series Analysis

5 Treasury Bill Example

6 Accident Death Example

Forecasting (Time Series) Chapter 5 15 / 36


...
Holt-Winters (Exponential Smoothing) Approach

Key Idea: Update = wCurrent + (1 − w)Previous

Setting (No model assumption):


Data: Y1 , . . . , Yn
Pre-specified period: d
Parameter: α, β, γ

Prediction: (n + h − dk ≤ n)

n
Yn+h = `n + hbn + sn+h−dk

Level: `t = α(Yt − st−d ) + (1 − α)(`t−1 + bt−1 )


Trend: bt = β(`t − `t−1 ) + (1 − β)bt−1
Seasonality: st = γ(Yt − `t ) + (1 − γ)st−d

Forecasting (Time Series) Chapter 5 16 / 36


...
Holt-Winters: n
Yn+h = `n + hbn + sn+h−dk

Level: `t = α(Yt − st−d ) + (1 − α)(`t−1 + bt−1 )


Trend: bt = β(`t − `t−1 ) + (1 − β)bt−1
Seasonality: st = γ(Yt − `t ) + (1 − γ)st−d , i = 1, . . . , d
Initialization:
`d+1 = Yd+1
bd+1 = d1 (Yd+1 − Y1 )
si = Yi − (Y1 + bd+1 (i − 1))
Parameter Estimation: minimizing Squared Prediction Error:
n
(Yt − Ytt−1 )2
X
(α̂, β̂, γ̂) = arg min
α,β,γ
t=d+1

Other choices: Pn
|Yt −Ytt−1 |
MASE (mean absolute scaled error): Pt=d+1
n
|Yt −Yt−d |
t=d+1

1
Pn |Yt −Ytt−1 |
SMAPE (symmetric mean abs. % error): n t=d+1 (|Yt |+|Y t−1 |)/2
t
n
1
|Yt − Ytt−1 |
P
MAE (mean absolute error) t−d t=d+1

Forecasting (Time Series) Chapter 5 17 / 36


...
Agenda

1 Introduction

2 Box and Jenkins Approach


ARMA models
ARIMA models

3 Holt-Winters Approach

4 Summary: Time Series Analysis

5 Treasury Bill Example

6 Accident Death Example

Forecasting (Time Series) Chapter 5 18 / 36


...
Time Series Analysis: Standard Procedure
1 Exploratory Data Analysis
1) TS/ACF/PACF plots for observations Yt
2) Estimate/Remove trend and seasonal effect by least
squares/filtering/differencing ⇒ obtain noise Zt for further analysis
2 Model Identification/Fitting
1) TS/ACF/PACF plots for noise Zt to ensure stationarity
2) Fit models by MM, YW, LSE, CLS, MLE... and select model by
FPE/AIC/BIC...
3 Model Checking/Diagnostics
1) Residual analysis (TS/ACF/PACF plots for residuals êt = Zt − Z
bt )
2) Portmanteau test
4 Prediction
n
1) Box-Jenkins Approach: Zn+h ; P.I. for Zn+h and Yn+h
n
2) Holt-Winters Approach Yn+h = `n + hbn + sn+h−dk
5 Output:
1) Time Series = Trend + Seasonal effect + ARMA model
2) Time Series = ARIMA model
Forecasting (Time Series) Chapter 5 19 / 36
...
Agenda

1 Introduction

2 Box and Jenkins Approach


ARMA models
ARIMA models

3 Holt-Winters Approach

4 Summary: Time Series Analysis

5 Treasury Bill Example

6 Accident Death Example

Forecasting (Time Series) Chapter 5 20 / 36


...
Treasury Bill Example

Monthly interest rate on three-month government Treasury bills from


1950-1988
ustbill.dat
Exploratory Data Analysis:

R-code:
ttbill=read.table("D://ustbill.dat")
ttbill=ttbill[,-1]
ttbill=as.vector(t(ttbill))

par(mfrow=c(2,2))
plot.ts(ttbill)
acf(ttbill)
plot.ts(log(ttbill))
acf(log(ttbill))

Forecasting (Time Series) Chapter 5 21 / 36


...
Treasury Bill Example
From the plot, the data are nonstationary in both mean and variance
Consider the difference in the log of the data

R-code:
lntbill=log(ttbill)
dlntbill=diff(lntbill)

par(mfrow=c(2,2))
plot.ts(dlntbill)
acf(dlntbill)
pacf(dlntbill,30)

Both ACF and PACF suggest strong correlations at lags 1,6


Try AR(6), MA(6) and ARMA(6,6) (AIC and diagnostic tests)
Forecasting (Time Series) Chapter 5 22 / 36
...
Fitting of AR(6)
R-code:
d3=arima(dlntbill,order=c(6,0,0))
tsdiag(d3)
d3$aic
AIC = -1056.251

Forecasting (Time Series) Chapter 5 23 / 36


...
Fitting of MA(6)
R-code:
d4=arima(dlntbill,order=c(0,0,6))
tsdiag(d4)
d4$aic
AIC = -1038.066

Forecasting (Time Series) Chapter 5 24 / 36


...
Fitting of ARMA(6,6)
R-code:
d5=arima(dlntbill,order=c(6,0,6))
tsdiag(d5)
d5$aic
AIC = -1055.556

Forecasting (Time Series) Chapter 5 25 / 36


...
Treasury Bill Example: Prediction
From AIC and diagnostic tests, AR(6) seems to be the best

Model: Xt = log(tbillt ), Yt = (1 − B)Xt

(1 + 0.44B − 0.19B 2 + 0.09B 3 + 0.04B 4 − 0.01B 5 − 0.21B 6 )(Yt − 0.0039) = Zt

Forecasting procedure:
1. Fit an AR(6) to {Yt }t=1,...,n and obtain forecasts Ybn+h
2. Recover X
b t+h from Ybt by “integrating”:

X
b n+h = Ybn+h + X
b n+h−1

3. Recover tbill
d
n+h as

tbill
d
n+h = exp(Xn+h ) = exp(Yn+h ) exp(Xn+h−1 )
b b b
= exp(Ybn+h )tbill
d
n+h−1

Forecasting (Time Series) Chapter 5 26 / 36


...
Treasury Bill Example: Prediction

Model: Xt = log(tbillt ), Yt = (1 − B)Xt , Yt ∼ AR(6)


Forecast: tbill
d n+h = exp(Ybn+h )tbill
d n+h−1

R-code: (Use days 1 to 456 to forecast days 457 to 462)


fit=arima(lntbill[1:456],order=c(6,1,0))
tfore=exp(predict(fit,n.ahead=6)$pred[1:6])
tfore: 5.871463 5.776399 5.639398 5.663790 5.783611 5.797992

ttbill=as.ts(ttbill);tfore=as.ts(tfore)
ts.plot(ttbill[457:462],tfore,lty=c(1:2)) # 1-solid, 2-dashed, 3-dotted
leg.names=c("Actual","Forecast") # Draw legend
legend("topleft",leg.names,lty=c(1:2))

Forecasting (Time Series) Chapter 5 27 / 36


...
Treasury Bill Example: Prediction Intervals

The forecasts for the first four months are reasonably well
The later forecasts get worse as the prediction variability grows with
time
Forecasting (Time Series) Chapter 5 28 / 36
...
Treasury Bill Example: Prediction Intervals
library(forecast)
par(mfrow=c(3,1))
plot(forecast(fit))
fore=exp(as.vector(forecast(fit)$mean))
lower=exp(forecast(fit)$lower[,2]); upper=exp(forecast(fit)$upper[,2])
ts.plot(c(ttbill,fore)); lines(c(ttbill,lower),lty=2); lines(c(ttbill,upper),lty=2)

HW=HoltWinters(ttbill);HW=HoltWinters(ttbill,gamma=F)
plot(HW,predict(HW,6, prediction.interval = TRUE))

Top: Forecasts for Xt


where Yt = (1 − B)Xt
Middle: Forecasts for
tbillt = eXt

Bottom: Holt-Winters
forecasts for tbillt

Forecasting (Time Series) Chapter 5 29 / 36


...
Agenda

1 Introduction

2 Box and Jenkins Approach


ARMA models
ARIMA models

3 Holt-Winters Approach

4 Summary: Time Series Analysis

5 Treasury Bill Example

6 Accident Death Example

Forecasting (Time Series) Chapter 5 30 / 36


...
Accident Death Example

Number of accident deaths on U.S. highways between 1973 and 1978


accdeaths.dat
Read data:
R-code:
par(mfrow=c(2,2))
accdeaths=scan("D://accdeaths.dat")
ts.plot(accdeaths)
acf(accdeaths,30)
pacf(accdeaths,30)

The ACF graph shows a periodic component (seasonal pattern) at lag


12,24,36,. . .

Forecasting (Time Series) Chapter 5 31 / 36


...
Accident Death Example: Estimating Trend and Seasonal
Effect
Data: 1973-1978 (n = 72)
Use 1973-1977 for model fitting, 1978 for evaluation
R: automated decomposition of trend and seasonal effect
stl(data,s.window="periodic")
R-code:
test=accdeaths[61:72] # 1978
x=ts(accdeaths[1:60],frequency=12)
# 1973-77
decomp=stl(x,s.window="periodic")
plot(decomp)
# Store the results
trend=decomp$time.series[,2]
seasonal=decomp$time.series[,1]
y=decomp$time.series[,3] # Noise

Forecasting (Time Series) Chapter 5 32 / 36


...
Accident Death Example: ARMA model fitting
After filtering out trend and seasonal effect, fit ARMA model for noise
R: automated ARMA model selection and parameter estimation
auto.arima(data,ic=c("aicc")) # "aic" or "bic"
library(forecast)
par(mfrow=c(1,3));ts.plot(y);acf(y);pacf(y)
arma.fit=auto.arima(y,ic=c("aic"),allowmean=F)
ar1 ar2 ar3 ma1
1.0323 -0.1086 -0.2014 -0.9603
s.e. 0.1307 0.1845 0.1289 0.0586
sigma∧2 estimated as 41981: log likelihood=-403.19 AIC=816.39 AICc=817.5 BIC=826.86

ARMA(3,1): Yt = 1.03Yt−1 − 0.11Yt−2 − 0.20Yt−2 + Zt − 0.96Zt−1 ,


Zt ∼ N (0, 41981).
Forecasting (Time Series) Chapter 5 33 / 36
...
Accident Death Example: Model diagnostic

R: Model diagnostic test and plots


tsdiag(arma.fit)

library(tseries)
tsdiag(arma.fit)
ACF-pass!
Ljung-Box test-pass!

Forecasting (Time Series) Chapter 5 34 / 36


...
Accident Death Example: Prediction
Prediction of Trend: (an naive way)
n
1 T̂n+h = Tn+h = Tn + h(Tn − Tn−1 )
Prediction of Seasonal Effect: use the suitable S1 , . . . , S12 .
 
n
p
Prediction of ARMA: Ŷn+h = Yn+h ±1.96 Var(en (h))
Final prediction
 q 
AccDeathn+h = T̂n+h + Ŝn+h + Ŷn+h ±1.96 Var(en (h))

pred=predict(arma.fit,n.ahead=12)
inc=trend[60]-trend[59]
fore=trend[60]+inc*(1:12)+seasonal[1:12]+pred$pred
fore.up=fore+1.96*pred$se
fore.low=fore-1.96*pred$se
ts.plot(cbind(test,fore,fore.up,fore.low),col=c(1,2,4,4))

Forecasting (Time Series) Chapter 5 35 / 36


...
Accident Death Example: Summary

AccDeatht = Tt + St + Yt

Trend and Seasonal Effects:


par(mfrow=c(1,2))
ts.plot(trend); ts.plot(seasonal)

ARMA(3,1) model
Yt = 1.03Yt−1 − 0.11Yt−2 − 0.20Yt−2
+Zt − 0.96Zt−1 , Zt ∼ N (0, 41981)
Prediction
data=c(x,test);fore=c(x,fore)
up=c(x,fore.up);low=c(x,fore.low)
ts.plot(cbind(fore,up,low,data),col=c(2,4,4,1))
HW=HoltWinters(x);
plot(HW,predict(HW,12,prediction.interval=T))
Forecasting (Time Series) Chapter 5 36 / 36

You might also like