Simple forecasts from an estimated MA model
Now that you've estimated a MA model with your Nile
data, the next step is to do some simple forecasting with your model. As with other types of models, you can use the predict()
function to make simple forecasts from your estimated MA model. Recall that the $pred
value is the forecast, while the $se
value is a standard error for that forecast, each of which is based on the fitted MA model.
Once again, to make predictions for several periods beyond the last observation you can use the n.ahead = h
argument in your call to predict()
. The forecasts are made recursively from 1 to h-steps ahead from the end of the observed time series. However, note that except for the 1-step forecast, all forecasts from the MA model are equal to the estimated mean (intercept
).
In this exercise, you'll use the MA
model derived from your Nile
data to make simple forecasts about future River Nile flow levels. Your MA
model from the previous exercise is available in your environment.
This exercise is part of the course
Time Series Analysis in R
Exercise instructions
- Use
predict()
to make a forecast for River Nile flow level in 1971. Store the forecast inpredict_MA
. - Use
predict_MA
along with$pred[1]
to obtain the 1-step forecast. - Use another call to
predict()
to make a forecast from 1971 through 1980. To do so, set then.ahead
argument equal to10
. - Run the pre-written code to plot the
Nile
time series plus the forecast and 95% prediction intervals.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Make a 1-step forecast based on MA
predict_MA <-
# Obtain the 1-step forecast using $pred[1]
# Make a 1-step through 10-step forecast based on MA
# Plot the Nile series plus the forecast and 95% prediction intervals
ts.plot(Nile, xlim = c(1871, 1980))
MA_forecasts <- predict(MA, n.ahead = 10)$pred
MA_forecast_se <- predict(MA, n.ahead = 10)$se
points(MA_forecasts, type = "l", col = 2)
points(MA_forecasts - 2*MA_forecast_se, type = "l", col = 2, lty = 2)
points(MA_forecasts + 2*MA_forecast_se, type = "l", col = 2, lty = 2)