Get startedGet started for free

Forecasting residuals

1. Forecasting residuals

So it seemed like our residuals might be related across time. When this happens we can use time series models to predict them! This might seem a little weird forecasting residuals so let's take a look at why we might do this.

2. Regression Pieces

The errors are what we have left after our regression is done. That doesn't mean we have to stop there. If there is a pattern in these errors over time, we can use time series models to predict them and remove some of that pattern. Essentially, we are trying to squueze even more predictability out of our model. In a way we are combining the techniques of regression with time series. However, we will talk more on that in the next video. For now, let's just focus on forecasting our residuals.

3. ARIMA on Residuals

We are going to approach this forecast much the same way we approached it in chapter one. We are going to use the auto dot arima function to do this. Again, we are using this time series modeling function on the residuals from our regression model. Let's use the summary function to examine what model might be good at forecasting our residuals. It looks like we have two AR terms and one MA term for an ARIMA(2 0 1) model. Perfect!

4. Forecasting Residuals

Similar to before, we are going to use the forecast function to give us forecasted values from our time series model. We need to forecast 22 observations into the future since that is the length of our validation data set. This is done with the h equals option. Net we are going to transform these forecasts into an xts object with the dates underscaore valid object being our dates in the validation data set. Let's take a quick peak at these residuals. Remember that we are predicting residuals here, not demand itself, so don't let the values scare you. Also, we are predicting the log of demand. We will need to change that!

5. Visualizing Forecasted Residuals

Let's visualize the forecast of our residuals. Looks like it has a wave going through it! Good to see since our plot of the residuals themselves seem to also have a wave going it. The wave seems to disipate here in our forecast which is to be expected. As time goes on, our best forecast is just the mean itself.

6. Let's practice!

Before we actually combine our regression forecast with our residual forecast, you should try to forecast the residuals from your own model!