## 5.9 Check residuals

We can do a test of autocorrelation of the residuals with Box.test() with fitdf adjusted for the number of parameters estimated in the fit. In our case, MA(1) and drift parameters.

res <- resid(fit)
Box.test(res, type = "Ljung-Box", lag = 12, fitdf = 2)

Box-Ljung test

data:  res
X-squared = 5.1609, df = 10, p-value = 0.8802

checkresiduals() in the forecast package will automate this test and show some standard diagnostics plots.

forecast::checkresiduals(fit)


Ljung-Box test

data:  Residuals from ARIMA(0,1,1) with drift
Q* = 1.0902, df = 3, p-value = 0.7794

Model df: 2.   Total lags used: 5