Series series0.4ACF-0.20.00.2510Lag15
第八章 模型诊断
8.7(a) data(hare);model=arima(sqrt(hare),order=c(3,0,0))
win.graph(width=6.5,height=3,pointsize=8);acf(rstandard(model)) 残差的样本自相关图
Series rstandard(model)0.3ACF-0.3-0.10.1246Lag8101214
(b) LB.test(model,lag=9) Box-Ljung test
data: residuals from model
X-squared = 6.2475, df = 6, p-value = 0.396 JB统计量结果表明不拒绝误差项的独立性。 (c)对残差进行检验。 runs(rstandard(model)) $pvalue [1] 0.602
$observed.runs [1] 18
$expected.runs [1] 16.09677 $n1 [1] 13 $n2 [1] 18 $k [1] 0
P值为0.602,不拒绝误差项的独立性。
(d) win.graph(width=3,height=3,pointsize=8) qqnorm(residuals(model)) 残差的正态QQ图
Normal Q-Q PlotSample Quantiles-2-101-2-1012
QQ图看出有一点小的曲率,但是这种现象可能是俩个极端值造成的。 (e)对残差的正态性进行shapiro-wilk检验 shapiro.test(residuals(model))
Shapiro-Wilk normality test data: residuals(model)
W = 0.93509, p-value = 0.06043
结果表明,我们不会拒绝通常意义水平的正态性。 第九章 预测
9.2(a)Y2007(1)?5?1.1Y2007?0.5Y2006?5?1.1(10)?0.5(11)?10.5 所以,Y2007(2)?5?1.1Y2008?0.5Y2007?5?1.1(10.5)?0.5(10)?11.55 (b)从上式中看出?1?1.1 ,?1-?1?0?0,?0?1 ,?1??1?1.1 (c)Y2007(1)?2?7.67-13.33.
???(d)因为有,Yt?1(t)?Yt?1(t?1)??tYt?1?Yt(1)
???????所以,Y2008(1)?Y2007(2)??1Y2008?Y2007(1)?11.55?1.1?12?10.5??13.2
?????????Theoretical Quantiles?????10.5?222?10.5?2.83即2008年预测的95%预测极限为
第十章 季节模型
10.12(a) data(boardings);series=boardings[,1]
plot(series,type='l',ylab='Light Rail&Bus Boardings')
points(series,x=time(series),pch=as.vector(season(series)))
12.70SONSSSONFJJJDMJSOAMNJAJDMD200120022003Time200420052006FAMAJJDNJSOOMAMFAJJDNAFMAMJFMLight Rail&Bus Boardings12.6012.65J12.5512.50OMNFAJAAMJJD12.4012.45
(b) acf(as.vector(series),ci.type='ma')
Series as.vector(series)ACF-0.4-0.20.00.20.4510Lag15
滞后期为1,5,6,12,时候,存在显著的自相关。
(c) model=arima(series,order=c(0,0,3),seasonal=list(order=c(1,0,0),period=12));model Call:
arima(x = series, order = c(0, 0, 3), seasonal = list(order = c(1, 0, 0), period = 12)) Coefficients:
ma1 ma2 ma3 sar1 intercept 0.7290 0.6116 0.2950 0.8776 12.5455 s.e. 0.1186 0.1172 0.1118 0.0507 0.0354
sigma^2 estimated as 0.0006542: log likelihood = 143.54, aic = -277.09 所有的变量都是显著的。
(d) model2=arima(series,order=c(0,0,4),seasonal=list(order=c(1,0,0),period=12));model2 Call:
arima(x = series, order = c(0, 0, 4), seasonal = list(order = c(1, 0, 0), period = 12)) Coefficients:
ma1 ma2 ma3 ma4 sar1 intercept 0.7277 0.6686 0.4244 0.1414 0.8918 12.5459 s.e. 0.1212 0.1327 0.1681 0.1228 0.0445 0.0419 sigma^2 estimated as 0.0006279: log likelihood = 144.22, aic = -276.45
模型2中AIC=-276.45,模型1中的AIC= -277.09,AIC越小越好,所以模型是过度拟合的。 第十二章 异方差时间序列模型 12.1 library(TSA) data(CREF)
r.cref=diff(log(CREF))*100
win.graph(width = 4.875,height = 2.5,pointsize = 8) plot(abs(r.cref))
win.graph(width = 4.875,height = 2.5,pointsize = 8) plot(r.cref^2)
12.9(a) > data(google) > plot(google)
收益率数据的时间序列图
> acf(google)
> pacf(google)
根据ACF和PACF可以得知,无自相关。
(b)计算google日收益率均值。
> t.test(google,alternative = 'greater') One Sample t-test data: google
t = 2.5689, df = 520, p-value = 0.00524
alternative hypothesis: true mean is greater than 0 95 percent confidence interval: 0.000962967 Inf sample estimates: mean of x 0.002685589
x的均值为0.002685589,备择假设为:均值异于0,根据P值显示,0.00524接受备择假设。 (c)McLeod-Li检验ARCH效应。
> win.graph(width = 4.875,height = 3,pointsize = 8) > McLeod.Li.test(y=google)
根据图显示,所有滞后值在5%的水平上均显著。说明数据具有ARCH特征。 (d)识别GARCH模型,估计识别的模型并对拟合的模型进行模型诊断检验。
> eacf(google^2) 取值平方的样本EACF AR/MA
0 1 2 3 4 5 6 7 8 9 10 11 12 13 0 x x o o o o o o o x o o o x 1 x o o o o o o o o x o o o x 2 x o o o o o o o o x o o o x