# Example for model identification and forecasting # # Generate some training data from ARIMA(2,1,2) set.seed(1) series2 <- arima.sim(model=list(order=c(2,1,2), ar=c(.4, .2), ma=c(.3,.1)), , n=100) series1 <- ts(series2[1:90]) # Graph the data. par(mfrow=c(3,2)) plot(series1) title("ARIMA(2,1,2)") plot(diff(series1)) title("Differenced") acf(series1) acf(diff(series1)) acf(series1, type="partial") acf(diff(series1), type="partial") # fit ARIMA model to first 90 observations fit <- arima(series1, order=c(2,1,2)) # and compute forecasts for last 10. pred <- predict(fit, n.ahead=10) # graph them. par(mfrow=c(1,1)) plot(c(series1,pred$pred), ylim=c(-3,50), type="n") lines(1:90,series1, lty=1) points(91:100, pred$pred, pch=3) #These are the forecasts lines(91:100, pred$pred + 2*pred$se, lty=2) #These are the forecast intervals lines(91:100, pred$pred - 2*pred$se, lty=2) points(91:100, series2[91:100], pch=1) #This is the data that was "held out" title("95% Forecast intervals")