# Problem 1. > da=read.table("m-mortg.txt") > dim(da) % Find the dimension of the data matrix [1] 370 4 > da[1,] % View the first row of the data V1 V2 V3 V4 1 1976 6 1 8.85 > mort=log(da[,4]) > acf(mort) > acf(diff(mort)) > m1=arima(mort,order=c(0,1,3)) > m1 arima(x = mort, order = c(0, 1, 3)) Coefficients: ma1 ma2 ma3 0.5269 -0.0491 -0.1362 s.e. 0.0512 0.0576 0.0509 sigma^2 estimated as 0.0006853: log likelihood = 820.43, aic = -1632.85 > tsdiag(m1) > Box.test(m1$residuals,lag=12,type='Ljung') Box-Ljung test data: m1$residuals X-squared = 9.652, df = 12, p-value = 0.6465 > 1-pchisq(9.652,9) % Take into account the number of fitted coefficients [1] 0.3793851 > predict(m1,4) $pred Time Series: Start = 371 End = 374 Frequency = 1 [1] 1.804799 1.805716 1.808650 1.808650 $se Time Series: Start = 371 End = 374 Frequency = 1 [1] 0.02617852 0.04778130 0.06147972 0.07080488 #Problem 2 > da=read.table("m-gs2.txt") > dim(da) > da[1,] > gs2=log(da[,4]) > > plot(gs2,mort) > m2=lm(mort~gs2) > summary(m2) lm(formula = mort ~ gs2) Residuals: Min 1Q Median 3Q Max -0.24264 -0.10086 -0.01074 0.09251 0.31197 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.23309 0.02422 50.91 <2e-16 *** gs2 0.52823 0.01279 41.30 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.1239 on 368 degrees of freedom Multiple R-Squared: 0.8225, Adjusted R-squared: 0.8221 F-statistic: 1706 on 1 and 368 DF, p-value: < 2.2e-16 > acf(m2$residuals,lag=12) > y=diff(mort) > x=diff(gs2) > m2=lm(y~x) > summary(m2) lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -0.087185 -0.012493 -0.001316 0.010620 0.127094 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.0005758 0.0010942 -0.526 0.599 x 0.3445959 0.0177031 19.465 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.02101 on 367 degrees of freedom Multiple R-Squared: 0.508, Adjusted R-squared: 0.5066 F-statistic: 378.9 on 1 and 367 DF, p-value: < 2.2e-16 > acf(m2$residuals,lag=12) > m3=arima(y,order=c(0,0,3),xreg=x) > m3 arima(x = y, order = c(0, 0, 3), xreg = x) Coefficients: ma1 ma2 ma3 intercept x 0.3251 -0.0722 -0.1174 -0.0006 0.3161 s.e. 0.0532 0.0541 0.0498 0.0012 0.0189 sigma^2 estimated as 0.0003914: log likelihood = 923.88, aic = -1835.76 > tsdiag(m3,gof.lag=12) > Box.test(m3$residuals,lag=12,type='Ljung') Box-Ljung test data: m3$residuals X-squared = 7.9935, df = 12, p-value = 0.7856 > 1-pchisq(7.9935,8) [1] 0.4341053 # Problem 3 > da=read.table("m-dec1-8006.txt") > dim(da) > da[1,] > jan=rep(c(1,rep(0,11)),27) > dec1=da[,2] > acf(dec1,lag=36) > m4=arima(dec1,order=c(0,0,1),xreg=jan) > m4 arima(x = dec1, order = c(0, 0, 1), xreg = jan) Coefficients: ma1 intercept jan 0.2483 0.0077 0.1224 s.e. 0.0519 0.0045 0.0121 sigma^2 estimated as 0.003975: log likelihood = 435.74, aic = -863.48 > tsdiag(m4,gof.lag=24) > Box.test(m4$residuals,lag=24,type='Ljung') Box-Ljung test data: m4$residuals X-squared = 24.3446, df = 24, p-value = 0.442 > 1-pchisq(24.34,22) [1] 0.329663 #Problem 4 > m5=arima(dec1,order=c(0,0,1),seasonal=list(order=c(1,0,1),period=12)) > m5 arima(x = dec1, order = c(0, 0, 1), seasonal = list(order = c(1, 0, 1), period = 12)) Coefficients: ma1 sar1 sma1 intercept 0.2409 0.9995 -0.9830 0.0179 s.e. 0.0517 0.0014 0.0241 0.0131 sigma^2 estimated as 0.00409: log likelihood = 420.42, aic = -830.83 > tsdiag(m5,gof.lag=24) > Box.test(m5$residuals,lag=24,type='Ljung') Box-Ljung test data: m5$residuals X-squared = 23.9223, df = 24, p-value = 0.466 > 1-pchisq(23.92,21) [1] 0.2969509 #Problem 5 > da=read.table("q-aa-earn.txt") > dim(da) > aa=da[,4] > plot(aa,type='l') > acf(aa) > pacf(aa) > m6=arima(aa,order=c(1,0,0)) % Lag-1 PACF is clearly significant > m6 arima(x = aa, order = c(1, 0, 0)) Coefficients: ar1 intercept 0.8004 0.2908 s.e. 0.0776 0.0713 sigma^2 estimated as 0.01390: log likelihood = 43.34, aic = -80.68 > acf(m6$residuals) % Shows a seasonal lag > pacf(m6$residuals) % Also shows a seasonal lag % First, entertain an seasonal MA model. > m7=arima(aa,order=c(1,0,0),seasonal=list(order=c(0,0,1),period=4)) > m7 arima(x = aa, order = c(1, 0, 0), seasonal = list(order = c(0, 0, 1), period = 4)) Coefficients: ar1 sma1 intercept 0.7573 0.5574 0.3015 s.e. 0.0850 0.1142 0.0804 sigma^2 estimated as 0.01089: log likelihood = 49.97, aic = -91.94 > tsdiag(m7,gof.lag=12) > Box.test(m7$residuals,lag=12,type='Ljung') Box-Ljung test data: m7$residuals X-squared = 3.56, df = 12, p-value = 0.9901 > predict(m7,4) $pred Time Series: Start = 62 End = 65 Frequency = 1 [1] 0.5452940 0.6766207 0.7408668 0.5678639 $se ... [1] 0.1043482 0.1308912 0.1439203 0.1508851 % Next, entertain a seasonal AR model. > m8=arima(aa,order=c(1,0,0),seasonal=list(order=c(1,0,0),period=4)) > m8 arima(x = aa, order = c(1, 0, 0), seasonal = list(order = c(1, 0, 0), period = 4)) Coefficients: ar1 sar1 intercept 0.7206 0.6992 0.3204 s.e. 0.0893 0.1346 0.1311 sigma^2 estimated as 0.01005: log likelihood = 51.82, aic = -95.64 > tsdiag(m8,gof.lag=12) > Box.test(m8$residuals,lag=12,type='Ljung') Box-Ljung test data: m8$residuals X-squared = 6.8164, df = 12, p-value = 0.8695 > predict(m8,4) $pred Time Series: Start = 62 End = 65 Frequency = 1 [1] 0.5521602 0.7379300 0.8352861 0.6088761 $se ... [1] 0.1002715 0.1235951 0.1341167 0.1392674