Creating an ARIMA model

After determining the optimum p, d, and q parameters for an ARIMA model, we can now create an ARIMA model with the Arima function.

Getting ready

Ensure you have completed the previous recipe by generating a time series object and storing it in a variable, ts.sim.

How to do it…

Please perform the following steps to build an ARIMA model:

  1. First, we can create an ARIMA model with time series ts.sim, with parameters p=1, d=1, q=0:
    > library(forecast)
    > fit <- Arima(ts.sim, order=c(1,1,0))
    > fit
    Series: ts.sim 
    ARIMA(1,1,0)                    
    
    Coefficients:
             ar1
          0.7128
    s.e.  0.0685
    
    sigma^2 estimated as 0.7603:  log likelihood=-128.04
    AIC=260.09   AICc=260.21   BIC=265.3
    
  2. Next, use the accuracy function to print the training set errors of the model:
    > accuracy(fit) ...

Get R for Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.