# fit recruits library(ts) rec_scan("E:\\Stat207\\Class\\Examples\\Ch2\\recruit.dat") x_ts(rec) # x is the time series object par(mfrow=c(3,1)) ts.plot(x, gpars=list(main="Recruits (x)")) acf(x) acf(x,type="partial") #indicates AR(2) fit but we'll also fit an ARMA(1,1) rec.ar2_ar(x, order.max = 10) # type help(ar) #to see what you get, e.g. rec.ar2$ar #gives parameters rec.ar2$aic # gives AIC from lag 0 to order.max # NOTE arima DOES FIT A CONSTANT rec.ar2_arima0(x, order=c(2,0,0)) # some results rec.ar2$var.coef rec.ar2$aic rec.ar2$sigma2 # now the ARMA(1,1) fit rec.arma_arima0(x, order=c(1,0,1)) rec.arma$var.coef rec.arma$aic # Forecast 12 time units ahead for AR(2) model rec.ar2.fore_predict(rec.arma,n.ahead=12) cbind(rec.ar2.fore$pred,rec.ar2.fore$se) par(mfrow=c(1,1)) ts.plot(x,rec.ar2.fore$pred,rec.ar2.fore$pred+2*rec.ar2.fore$se, rec.ar2.fore$pred-2*rec.ar2.fore$se)