Forecasting any of the models we saw until now was straightforward: we used the forecast function from the forecast package in a similar manner to how we used it in the previous chapter. For instance, the following code demonstrates the forecast of the next 100 observations of the AR model we trained previously in The AR process section with the ar function:
ar_fc <- forecast(md_ar, h = 100)
We can use plot_forecast to plot the forecast output:
plot_forecast(ar_fc,
title = "Forecast AR(2) Model",
Ytitle = "Value",
Xtitle = "Year")
We get the following output: