# Exercise 6.7 airpass.vec=scan("http://www.uio.no/studier/emner/matnat/math/STK4060/v06/airpass.tsm") airpass<-ts(log(airpass.vec[1:(length(airpass.vec)-12)]),start=1949,frequency=12) # Plot the original data: plot.ts(exp(airpass),xlab="time", ylab="airpass") # Plot the log-tranformed data: plot.ts(airpass,xlab="time", ylab="log(airpass)") acf(airpass) # I did not find any code for the tests described ins ection 6.3 # so I'll use visual inspection to choose the number of # differenciations ts.plot(diff(airpass)) acf(diff(airpass),lag=40) # Seems to have a seasonal term, but else, ok. ts.plot(diff(airpass, lag=12)) acf(diff(airpass, lag=12),lag=40) # Slow but steady decline of the acf; possible AR-model? # See which of these two candidates for differenciation # that gives the smallest model from the BIC criterion # We'll now try both seasonal and normal ARMA models # for I1=1 and I12=0: zero.I1.model=arima(airpass,order=c(0,1,0)) best.I1.model=zero.I1.model bicbest.I1.model=zero.I1.model n=length(airpass) best.I1.bic=-2*zero.I1.model$loglik+2*log(n) bicbest.I1.p=0 bicbest.I1.q=0 bicbest.I1.P=0 bicbest.I1.Q=0 for(Q in 0:3) { for(P in 0:3) { for(q in 0:3) { for(p in 0:3) { model<-arima(airpass,order=c(p,1,q),seasonal=c(P,0,Q),method="ML") curr.bic=-2*model$loglik+log(n)*(P+Q+p+q+1+1) if(curr.bic