8 · ARIMA
ARIMA(p,d,q) glues AR, differencing (I), and MA into one model. The Box-Jenkins loop — identify, estimate, check — is how you pick the orders and trust the result.
ARIMA(p,d,q) = AR(p) + d rounds of differencing (the Integrated part, to remove trend) + MA(q). You choose the orders with the Box-Jenkins loop: identify candidate orders from ACF/PACF and stationarity, estimate by maximum likelihood, then check residuals and compare AIC.
Without this:
Without the I (differencing) you can't model trended series at all, and without the identify→estimate→check loop you'd guess orders at random and overfit or underfit silently.
ARIMA(p, d, q) stitches the previous lesson together with one new piece:
- AR(p) — the autoregressive order (lagged values).
- I(d) — Integrated: difference the series
dtimes to remove trend and make it stationary (Chapter 2).d=1models the change day-to-day;d=2models the change of the change. - MA(q) — the moving-average order (lagged errors).
So a random walk with drift is ARIMA(0,1,0); a trended series whose changes are autocorrelated might be ARIMA(1,1,1). The d is what lets ARIMA handle non-stationary, trending data that pure AR/MA cannot.
The Box-Jenkins method is the disciplined recipe for choosing (p,d,q):
- Identify. Pick
dby differencing until an ADF test says the series is stationary. Then read candidatepandqfrom the PACF (cuts off after lag p for an AR process) and ACF (cuts off after lag q for an MA process). - Estimate. Fit the candidate model by maximum likelihood;
statsmodelsreturns the coefficients and the AIC (Akaike Information Criterion — fit penalised by number of parameters; lower is better). - Check. Inspect the residuals: they should look like white noise (no leftover autocorrelation). If not, revise the orders and loop. Among models that pass, prefer the lowest AIC.
Below we split a synthetic trended series by time, fit ARIMA(1,1,1) on the training portion, forecast the held-out horizon, and report forecast-vs-actual, an error metric, and the AIC.
Python (in browser)
A time-respecting train/test split, an ARIMA(1,1,1) fit on the training portion, then a multi-step forecast compared to the held-out actuals, with MAE/RMSE and the model AIC.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
In ARIMA(p, d, q), what does the middle term d represent?
- ARIMA(p,d,q) = AR(p) + d differencings (Integrated, removes trend) + MA(q); the d is what handles non-stationary, trended data.
- Box-Jenkins loop: identify orders (ADF for d, ACF/PACF for p,q) → estimate by MLE → check residuals are white noise → compare AIC.
- Always split train/test by time, forecast the future horizon, and judge with an error metric (MAE/RMSE) plus AIC for model selection.
ARIMA is the default classical baseline for univariate forecasting — demand, inventory, web traffic — and the foundation auto-ARIMA tools (pmdarima) automate.
If you remove it: Without ARIMA you have no interpretable, fast, well-understood baseline to beat before reaching for heavier ML/DL models.