Method · Statistics Library

ARIMA forecast

ARIMA(p,d,q) models a time-ordered series through autoregression, differencing, and a moving-average error term, then forecasts forward with widening confidence intervals and a Ljung-Box check that nothing predictable is left in the residuals.

Chapter 6: Quality, processes and timeReading 6.6

Understand the idea

ARIMA builds a forecast out of three simple ingredients. The AR part says today's value is a weighted echo of the last few values. The MA part says today's value also reacts to how wrong the last few forecasts were, a kind of self-correction. The I (integration) part means the model often works on the DIFFERENCES between consecutive values rather than the raw levels, which is a simple way to strip out a trend so the leftover pattern is easier to model.

Picking how many terms of each ingredient to use (p, q) and how many times to difference (d) is part science, part comparison: fit a few candidate orders and compare them by AIC or BIC, where a lower number means a better balance of fit against complexity.

Once the model is fit, one very useful check is whether anything predictable is left over in what the model could NOT explain (the residuals). The Ljung-Box test asks exactly that question, and a large p-value is the reassuring answer: it means the leftovers look like structureless noise. But a large p-value only says this one check found nothing wrong; it is not proof the model is exactly right, and it says nothing at all about how well the forecast will hold up on data the model hasn't seen yet.

ARIMA stands for autoregressive integrated moving average; it is often called a Box-Jenkins model after the two statisticians who set out how to build one, and it is a workhorse of time series forecasting.

Practitioner explanation

KernelStats fits the ARIMA(p,d,q) model by maximum likelihood and reports the AR/MA coefficients alongside sigma-squared, AIC, and BIC. Residuals for the Ljung-Box check are built to match R's residuals(arima) convention exactly: the first d residuals come from the diffuse Kalman start-up (not the fitted model itself) and are dropped before the test runs. The 95% forecast interval likewise follows R's predict.Arima convention (the model's own MLE sigma-squared), which is deliberately named because R's forecast() function uses a bias-adjusted sigma-squared instead and will print a very slightly different interval on the same fit, a difference of convention, not an error.

A series that is exactly constant (or becomes exactly constant after d differences, i.e. a perfect deterministic trend) leaves no random variation for ARIMA to model, so KernelStats refuses to fit it with a named error rather than reporting a coefficient table, AIC/BIC, and a Ljung-Box result that would all be undefined artifacts of a likelihood that diverges as sigma-squared to 0. This mirrors R's own arima(), which refuses the identical series for the identical reason.

Equal spacing in time is checked only when you give the optional period column (a date, 2023-01, Jan 2023, 2023Q1 or a year): the card then reads the calendar off it ('36 monthly periods from 2023-01 to 2025-12, no gaps'), flags a changing gap with the table rows where it changes, reports repeated periods as several series stacked (a panel, which no single forecast describes; forecast one group or the per-period total instead), and labels the plot axis and the forecast steps with real dates. Without a period column the spacing is assumed, not checked: rows with missing values are dropped before fitting and the remaining points are treated as evenly spaced, a limitation to know about before trusting a forecast built on a series with dropped rows. The period column never changes a number, and the forecasts, their intervals and the large statistics print in the series' own units with thousands separators, never in scientific notation. And as with any ARIMA fit, AIC/BIC and in-sample residual diagnostics describe how well the model explains data it has already seen; they say nothing about forecast accuracy on new data, which is what Forecast Backtest (Rolling-Origin) exists to measure honestly.

When to use it

Consider it when

You have a single numeric series observed in time order (equally spaced; an optional period column (a date, 2023-01, Jan 2023, 2023Q1 or a year) lets the card check the spacing and date the forecast, but is not required) and want to model its autocorrelation structure and forecast future values, especially when the pattern is more complex than a simple trend or seasonal cycle.

Use caution when

The series is dominated by a clean trend and/or seasonal cycle with little other structure (exponential smoothing is often simpler and just as accurate), you only want to see the trend/seasonal components themselves rather than a forecast (use STL decomposition), or you have not yet checked how well this kind of model actually forecasts out-of-sample (use the rolling-origin backtest before trusting the numbers here).

Formulas and symbols

ARIMA(p,d,q) model equation

ϕ(B)(1−B)dyt=θ(B)εt\phi(B)(1-B)^d y_t = \theta(B)\varepsilon_t

B is the backshift operator (B y_t = y_{t-1}), phi the AR polynomial of order p, theta the MA polynomial of order q, and d the number of nonseasonal differences.

Akaike Information Criterion

AIC=−2ln⁡(L^)+2kAIC = -2\ln(\hat L) + 2k

k the number of estimated parameters (AR + MA terms plus sigma-squared). Lower is better; used to compare candidate orders.

Bayesian Information Criterion

BIC=−2ln⁡(L^)+kln⁡(n)BIC = -2\ln(\hat L) + k\ln(n)

Penalizes extra parameters more heavily than AIC as the sample size n grows.

Ljung-Box statistic

Q=n(n+2)∑k=1Kρ^k2n−kQ = n(n+2)\sum_{k=1}^{K} \frac{\hat\rho_k^2}{n-k}

Tests jointly whether the first K residual autocorrelations rho_k are all zero (white noise). A large p-value means the test found no leftover structure.

Assumptions and checks

  • Stationarity. A non-stationary series (a trend or drifting variance that differencing has not removed) produces spurious-looking coefficients, an unreliable AIC/BIC comparison, and forecasts that can drift arbitrarily far from reality.

    In KernelStats: Not directly checked by KernelStats; only the degenerate extreme (an exactly constant series after d differences) is caught and refused; ordinary non-stationarity after the chosen d is left to the analyst to judge, typically by inspecting the series and its ACF/PACF before fitting.

  • No (residual) autocorrelation. Leftover autocorrelation in the residuals means the chosen (p,d,q) order hasn't captured all of the series' structure, which biases the forecast and understates its true uncertainty.

    In KernelStats: The Ljung-Box test on the post-startup residuals, reported directly on the card and matching R's Box.test to 4 decimals on a well-identified fit.

Alternatives

  • Exponential Smoothing. The series is dominated by trend and/or a clean seasonal cycle rather than complex autocorrelation; the two model families overlap heavily and are best compared by AIC and out-of-sample accuracy, not chosen by assumption.
  • STL Decomposition. You want to see and separate the trend and seasonal components themselves, rather than get a forecast.
  • Forecast Backtest (Rolling-Origin). You want an honest, out-of-sample judgment of this model's forecast accuracy instead of trusting in-sample AIC/BIC/SSE.

Worked example

Scenario

90 months of sales data, fit with ARIMA(1,1,1) after one difference to remove a linear trend.

Result

AR(1) coefficient = 0.392, MA(1) coefficient = 0.428, sigma-squared = 0.999; AIC = 259.17, BIC = 266.64. The 10-step forecast starts at 88.92 (95% CI [86.96, 90.88]) and widens at longer horizons; Ljung-Box on the residuals gives chi-square(10) = 10.87, p = .368.

Interpretation

The Ljung-Box p-value is comfortably above .05, so this check finds no leftover autocorrelation the model failed to capture, a reassuring sign, but not proof the model is exactly right, and not a statement about forecast accuracy on new data. Before relying on the 10-step forecast, the honest next step is Forecast Backtest (Rolling-Origin) to see how this model actually performed out-of-sample historically.

Common misconceptions

Misconception

A large Ljung-Box p-value proves the model is correctly specified and the residuals are perfectly white noise.

Correction

A non-significant result only means this particular test found no evidence of leftover autocorrelation at the lags it checked: absence of evidence is not evidence of absence. The model could still be missing structure the test has low power to detect, and a good Ljung-Box result says nothing at all about out-of-sample forecast accuracy.

Read more: Misconception: a non-significant result proves there is no effect

Misconception

A lower in-sample AIC means this model will forecast the future better.

Correction

AIC and BIC measure how well the model fits data it has already seen, not how well it predicts data it hasn't. A model can have the lowest AIC in a comparison and still forecast worse out-of-sample than a simpler alternative; judge forecast quality with Forecast Backtest (Rolling-Origin) instead.

Read more: Misconception: a model's training-set accuracy is its real-world performance

References

  1. Time Series Analysis: Forecasting and Control, Box, G. E. P., Jenkins, G. M., Reinsel, G. C. and Ljung, G. M. (1970).
  2. On a Measure of Lack of Fit in Time Series Models, Ljung, G. M. and Box, G. E. P. (1978), Biometrika, 65(2), 297-303.
  3. NIST/SEMATECH e-Handbook of Statistical Methods, §6.4.4 Univariate Time Series Models, NIST/SEMATECH (2012), §6.4.4.