Get startedGet started for free

Forecasting simulated ARIMA

Now that you are an expert at fitting ARIMA models, you can use your skills for forecasting. First, you will work with simulated data.

We generated 120 observations from an ARIMA(1,1,0) model with AR parameter .9. The data are in y and the first 100 observations are in x. These observations are plotted for you. You will fit an ARIMA(1,1,0) model to the data in x and verify that the model fits well. Then use sarima.for() from astsa to forecast the data 20 time periods ahead. You will then compare the forecasts to the actual data in y.

The basic syntax for forecasting is sarima.for(data, n.ahead, p, d, q) where n.ahead is a positive integer that specifies the forecast horizon. The predicted values and their standard errors are printed, the data are plotted in black, and the forecasts are in red along with 2 mean square prediction error bounds as blue dashed lines.

The astsa package is preloaded and the data (x) and differenced data (diff(x)) are plotted.

This exercise is part of the course

ARIMA Models in R

View Course

Exercise instructions

  • Plot the sample ACF and PACF of the differenced data to determine a model.
  • Use sarima() to fit an ARIMA(1,1,0) to the data. Examine the output of your sarima() command to assess the fit and model diagnostics.
  • Use sarima.for() to forecast the data 20 time periods ahead. Compare it to the actual values.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Plot P/ACF pair of differenced data 


# Fit model - check t-table and diagnostics


# Forecast the data 20 time periods ahead
sarima.for(x, n.ahead = ___, p = ___, d = ___, q = ___) 
lines(y)  

 
Edit and Run Code