Yesterday with R toss a simple time series data Arima automatic fitting and prediction. The process is not complicated, but it is not used much, in order to prevent forgetting, the author records.
Open R and install a package called "Forecast". Each time you turn on R, use the
Library (' forecast ')
Load the package.
Here I use the legendary airline model data. Load data, convert to TS format
Airdata<-read.table (' Airline.dat ')
Airts<-ts (airdata,start=1949,frequency=12)
The
then automatically fits the Arima model with the Auto.arima in the forecast package.
Arima1<-auto.arima (airts,trace=t)
Displays the following results:
Arima (2,0,2) (1,1,1) [] with drift: 974.1468
Arima (0,0,0) (0,1,0) [n] with drift:1077.823
ARIMA (1,0,0) (1,1,0) [n] with drift:974.92& nbsp
Arima (0,0,1) (0,1,1) [n] with drift:1022.198
ARIMA (2,0,2) (0,1,1) [n] with drift:967.1033
Arim A (2,0,2) (0,1,0) [] with drift:966.755
Arima (1,0,2) (0,1,0) [n] with drift:964.3004
ARIMA (1,0,1) ( 0,1,0) [] with drift:963.9208
ARIMA (1,0,1) (0,1,0) [n]: 971.225
ARIMA (1,0,1) (1,1,0) [A] with drift:972.4003
Arima (1,0,1) (0,1,1) [n] with drift:963.9781
ARIMA (1,0,1) (1,1,1) [n] with drift:97 1.7862
Arima (0,0,1) (0,1,0) [n] with drift:1022.291
ARIMA (2,0,1) (0,1,0) [n] with drift:965.183& nbsp
ARIMA (1,0,0) (0,1,0) [] with drift:966.9728
Best Model:arima (1,0,1) (0,1,0) [a] with drift
The result is an AR (1), MA (1), and seasonal differential Arima model. The key to auto-fitting the Arima model is the fixed order, which was previously used by EACF (extended (sample) autocorrelation function) to order, but now it is generally used to order by aic,aicc,bic and other statistics. For example, the above 974.1468 is the AIC of the model
Then you can predict it.
Airfore<-forecast (arima1,h=30,fan=t)
30 months were predicted, and the predicted values of confidence intervals from 50 to 99 were also calculated.
Plot (Airfore)
The final drawing. If you need to get the forecast data, you can get it by using: Airefore$mean.
There is a picture to testify, the prediction effect is good.