library(TSA) data(lynx) acf(lynx) pacf(lynx) eacf(lynx) arma.l=arima(lynx,order=c(2,0,2)) arma.l arma.l2=arima(lynx,order=c(2,0,2),fixed=c(NA,NA,0,NA,NA)) arma.l2 tsdiag(arma.l2,gof.lag=30) plot(arma.l2$residuals) qqnorm(arma.l2$residuals);qqline(arma.l2$residuals) plot(y=as.vector(arma.l2$residuals),x=as.vector(fitted(arma.l2))) BoxCox.ar(lynx) # log transformation, then fit an ARMA(3,1) arma.31=arima(log(lynx),order=c(3,0,1)) arma.31 Rsq=1-.2652/var(log(lynx)) Rsq tsdiag(arma.31,gof.lag=40) qqnorm(arma.31$residuals);qqline(arma.31$residuals) shapiro.test(arma.31$residuals) plot(y=as.vector(arma.31$residuals)/sqrt(.2652),x=as.vector(fitted(arma.31))) abline(h=0) #overfitting for appreciating the goodnesf of fit # increase either the AR order or the MA order by 1. arma.41=arima(log(lynx),order=c(4,0,1)) tsdiag(arma.41,gof.lag=40) arma.51=arima(log(lynx),order=c(5,0,1)) arma.51 arma.32=arima(log(lynx),order=c(3,0,2)) arma.32 ar11=arima(log(lynx),order=c(11,0,0)) ar11 tsdiag(ar11,gof.lag=25) ar11b=arima(log(lynx),order=c(11,0,0),fixed=c(NA,NA,rep(0,8),NA,NA)) ar11b tsdiag(ar11b) #don't overfit both AR and MA, because of possible redundancy. arma.52=arima(log(lynx),order=c(5,0,2)) arma.52 arma.41 ar(log(lynx))$aic