library(readxl)
library(tseries)
library(zoo)
library(forecast)
setwd("C:/Users/User/Google 雲端硬碟/政治大學ECO/時間序列/作業3")
ts<-read_excel("ARCHQ6.xlsx")
Estimate the {yt} sequence using the Box–Jenkins methodology. Try to improve on the model.
a.ma<-arima(ts$y,order = c(0,0,6),transform.pars = F,fixed = c(0,0,NA,0,0,NA,NA))
acf(a.ma$residuals)
pacf(a.ma$residuals)
acf(ts)
By the acf and pacf of residuals, we find the residual are not very clean.By the ACF of sequence, I think the model MA(||3,6||) not actually catch all imformation of the sequence. We can find the values of lag(9) and lag(13) are over critical values. Maybe we can change model to MA(||3,6,9,13||).
a.ma2<-arima(ts$y,order = c(0,0,13),transform.pars = F,fixed = c(0,0,NA,0,0,NA,0,0,NA,0,0,0,NA,NA))
acf(a.ma2$residuals)
pacf(a.ma2$residuals)
By the new model, the residuals are more clean.
Examine the ACF and the PACF of the residuals from the MA(∥3, 6∥) model above.Why might someone conclude that the residuals appear to be white noise? Now examine the ACF and PACF of the squared residuals.Perform the LM test for ARCH errors.
ma.r2<-a.ma$residuals^2
ma.r2.acf<-acf(ma.r2)
ma.r2.pacf<-pacf(ma.r2)
figure<-matrix(c(ma.r2.acf$acf[2:7],ma.r2.pacf$acf[1:6]),nrow = 2)
row.names(figure)<-c("ACF","PACF")
colnames(figure)<-c(1,2,3,4,5,6)
figure
## 1 2 3 4 5 6
## ACF 0.4980978 0.2921198 0.04671571 0.498097771 0.21432750 -0.03897722
## PACF 0.2555712 0.1625981 0.12106327 0.009934568 -0.08799931 0.10623009
i<-5
LM.test<-lm(ma.r2[i:100]~ma.r2[(i-1):99]+
ma.r2[(i-2):98]+ma.r2[(i-3):97]+
ma.r2[(i-4):96])
summary(LM.test)
##
## Call:
## lm(formula = ma.r2[i:100] ~ ma.r2[(i - 1):99] + ma.r2[(i - 2):98] +
## ma.r2[(i - 3):97] + ma.r2[(i - 4):96])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.88067 -0.15165 -0.08010 0.05116 2.03431
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.09505 0.04895 1.942 0.0552 .
## ma.r2[(i - 1):99] 0.51142 0.10456 4.891 4.3e-06 ***
## ma.r2[(i - 2):98] -0.10674 0.11442 -0.933 0.3533
## ma.r2[(i - 3):97] 0.26014 0.11443 2.273 0.0254 *
## ma.r2[(i - 4):96] -0.08829 0.10463 -0.844 0.4010
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3958 on 91 degrees of freedom
## Multiple R-squared: 0.2889, Adjusted R-squared: 0.2576
## F-statistic: 9.241 on 4 and 91 DF, p-value: 2.596e-06
We conduct the LM test for ARCH error using four lag. We find the p-values of lag(1) and lag(3) are very low and we reject the null hypothesis. Meanwhile the F-statistic is 9.241 on the DF=(4,91) ,we reject the null hypothesis. There are arch effect.