Search code examples
rforecastingforecast

Make out-of-sample predictions using auto.arima model R


I am trying to make out-of-sample predictions for a time series. Therefore, I estimated a arima model on train data using:

      arma_fit <- auto.arima(tsOrders)
      forecast <- forecast(arma_fit, h = 1, level=95)

where tsOrders is a time series object. Here, the forecast object contains only in-sample fitted values. I want to make predictions for a test data set, which I did not use for estimating the arima model. Does anyone know how to do this with this approach?


Solution

  • What you have gives a forecast one step ahead. Increase the value of h to forecast further ahead.

    library(forecast)
    set.seed(1)
    tsOrders <- ts(rnorm(20, 10, 4))
    arma_fit <- auto.arima(tsOrders)
    forecast <- forecast(arma_fit, h = 10, level=95)
    forecast
    #>    Point Forecast    Lo 95    Hi 95
    #> 21        10.7621 3.602318 17.92187
    #> 22        10.7621 3.602318 17.92187
    #> 23        10.7621 3.602318 17.92187
    #> 24        10.7621 3.602318 17.92187
    #> 25        10.7621 3.602318 17.92187
    #> 26        10.7621 3.602318 17.92187
    #> 27        10.7621 3.602318 17.92187
    #> 28        10.7621 3.602318 17.92187
    #> 29        10.7621 3.602318 17.92187
    #> 30        10.7621 3.602318 17.92187
    

    Created on 2020-04-17 by the reprex package (v0.3.0)