Fitted values and residuals

Forecasting in R

Rob J. Hyndman

Professor of Statistics at Monash University

Fitted values and residuals

A fitted value is the forecast of an observation using all previous observations

  • That is, they are one-step forecasts

  • Often not true forecasts since parameters are estimated on all data

A residual is the difference between an observation and its fitted value

  • That is, they are one-step forecast errors
Forecasting in R

Example: oil production

fc <- naive(oil)
autoplot(oil, series = "Data") + xlab("Year") +
  autolayer(fitted(fc), series = "Fitted") +
  ggtitle("Oil production in Saudi Arabia")

ch2_vid2_oil.png

Forecasting in R

Example: oil production

autoplot(residuals(fc))

ch2_vid2_oil_residuals.png

Forecasting in R

Residuals should look like white noise

Essential assumptions

  • They should be uncorrelated

  • They should have mean zero

Useful properties (for computing prediction intervals)

  • They should have constant variance

  • They should be normally distributed

We can test these assumptions using the checkresiduals() function.

Forecasting in R

checkresiduals()

checkresiduals(fc)
    Ljung-Box test
data:  residuals
Q* = 12.59, df = 10, p-value = 0.2475
Model df: 0.   Total lags used: 10

ch2_vid2_check_residuals.png

Forecasting in R

Let's practice!

Forecasting in R

Preparing Video For Download...