Professional Documents
Culture Documents
Time Series Analysis: Example: Stationary ARIMA
Time Series Analysis: Example: Stationary ARIMA
Time Series Analysis: Example: Stationary ARIMA
4/19/2011
flu.shgls$residuals
4/19/2011
Choosing a TS model
Model fitting
> flu.ar<-arima(flu.shgls$residuals, order=c(2,0,0))
> flu.ar$aic
[1] -349.0261
> flu.ma<-arima(flu.shgls$residuals, order=c(0,0,1))
> flu.ma$aic
[1] -354.4418
> flu.arma<-arima(flu.shgls$resid, order=c(1,0,1))
> flu.arma$aic
[1] -352.8236
> flu.arma2<-arima(flu.shgls$resid, order=c(0,0,2))
> flu.arma2$aic
[1] -352.9634
4/19/2011
Results
> best.arma
Series: resid(flu.shgls)
ARIMA(0,0,1) with non-zero mean
Call: arima(x = resid(flu.shgls), order = best.order)
Coefficients:
s.e.
ma1
intercept
0.7003
0.0001
0.0696
0.0091
AICc = -354.25
4/19/2011
4/19/2011
best.arma$resid
Forecasting
>
>
>
>
4/19/2011
Forecasting
> ts.plot(cbind(flu, flu.pred),lty=1:2, col=1:2)
Feb
Mar
Apr
May
Jun
Jul
Sep
Oct
Nov
Dec
4/19/2011
Example: non-stationary TS
4/19/2011
Logged series
4/19/2011
lngas
10
4/19/2011
Results
Series: x.ts
ARIMA(0,1,1)
Call: arima(x = x.ts, order = c(p, d, q))
Coefficients:
ma1
0.5243
s.e.
0.0646
AICc = -628.99
A caution about R
xreg=t or xreg=1:length(lngas)
http://www.stat.pitt.edu/stoffer/tsa3/Rissues.htm
11
4/19/2011
Correct results
> gas.arima<-arima(lngas, ord=c(0,1,1), xreg=1:length(gas))
Series: lngas
ARIMA(0,1,1)
Call: arima(x = lngas, order = c(0, 1, 1), xreg = 1:length(gas))
Coefficients:
s.e.
ma1
1:length(gas)
0.5181
0.0068
0.0654
0.0046
AICc = -629.04
12
4/19/2011
13
4/19/2011
Forecasting
> plot(gas, xlim=c(1973,1991))
> nobs=length(gas)
> gas.pred <- predict(gas.arima, n.ahead=36,
newxreg=(nobs+1):(nobs+36))
> lines(exp(gas.pred$pred), col="red")
14
4/19/2011
Results
15
4/19/2011
s.e.
ar1
ar2
ma1
0.5114
0.2923
-1.0000
0.0014
0.0464
0.0467
0.0062
0.0002
AICc = -885.08
1:length(newGTS)
16
4/19/2011
Forecast
> tsdiag(gts.arima)
> plot(newGTS,xlim=c(1970,2010))
> nobs=length(newGTS)
> gts.pred<-predict(gts.arima, n.ahead=60,
newxreg=(nobs+1):(nobs+60))
> lines(gts.pred$pred,col="red")
17
4/19/2011
ARIMA(p, d, q)x(P, D, Q)
18
4/19/2011
Don't use more than ONE seasonal difference or more than TWO total
differences (seasonal + non-seasonal)
Do notmix SAR and SMA terms in the same model, and avoid using more
than one of either kind
19
4/19/2011
Seasonal ARIMA
> flu.s<-arima(flu, order=c(0,0,0), seas=list(order=c(0,1,0), 12))
acf(flu.s$resid)
pacf(flu.s$resid)
MA signature?
20
4/19/2011
21
4/19/2011
Results
> flu.s
Call:
arima(x = flu, order = c(0, 0, 1), seasonal = list(order = c(0,
1, 1), 12))
Coefficients:
s.e.
ma1
sma1
0.7294
-0.5825
0.0678
0.1015
22
4/19/2011
Prediction
> predict<-predict(flu.s, n.ahead=36)
> predict
$pred
Jan
Feb
Mar
Apr
May
Jun
Jul
Prediction
23
4/19/2011
24
4/19/2011
Linear models
Moving averages (MA) and autoregressive (AR) processes
Specification/identification of ARMA/ARIMA models
SARIMA models
Estimation/prediction
For linear models and ARIMA models and combination of the two
25