liveBook · Manning

Arima

As explained in Statistics Every Programmer Needs

An ARIMA model is an autoregressive integrated moving-average time-series model that represents temporal dependence using autoregression, differencing, and moving averages.

ARIMA—autoregressive integrated moving average—forecasts a time series from its temporal structure. Unlike methods for unordered observations, it accounts for the possibility that a value depends on earlier values. It is useful when that dependence, including trends, matters to a forecasting decision. section 7.1

The order (p, d, q) specifies three components:

  • Autoregression (p) uses a specified number of earlier observations; p = 1 uses one lag. section 7.3.1
  • Integration (d) specifies how many times to difference the series to make it stationary. First-order differencing subtracts the preceding observation from each value. section 7.3.4 section 7.3.9
  • Moving average (q) specifies how many lagged forecast errors enter the model; q = 0 excludes them. section 7.3.9

Choose d first, using only the training period: inspect the series and its autocorrelation function (ACF), then test stationarity. Examine the ACF and partial autocorrelation function (PACF) of the differenced series when selecting p and q. Fit the model to the original training series—the order tuple specifies the differencing—and reserve later observations for an out-of-sample check. section 7.3.4 section 7.3.7

>>> adf_test_diff = adfuller(train_diff)
>>> print('p-value:', adf_test_diff[1])
p-value: 1.2486140415792743e-16

The augmented Dickey–Fuller test returns a very small p-value after first-order differencing, supporting the choice of d = 1 for this training series. section 7.3.7

Forecast a held-out month of closing prices

For daily Apple closing prices, train covers October 2023 through March 2024; test contains April’s 22 trading days. The selected order uses one autoregressive lag, one difference, and no moving-average terms: from statsmodels.tsa.arima.model import ARIMA model_fit = ARIMA(train, order=(1, 1, 0)).fit() forecast_test = model_fit.forecast(len(test)) Compare forecast_test with the withheld closing prices rather than judging the fitted model alone. The April forecast was approximately $173.51 per day, versus an actual April average near $169.43. The forecast was nearly flat while actual prices varied. section 7.3.7 section 7.3.9 section 7.3.11

Check residual plots and their ACF/PACF for remaining patterns; compare candidate models’ fit and complexity using criteria such as AIC, BIC, and HQIC. A plausible fit does not guarantee an accurate forecast: stock-price volatility and unpredictable influences limit what historical patterns can predict. Exponential smoothing offers a simpler alternative that weights recent observations more heavily, particularly for short-term forecasting; compare forecasts on the same held-out period. section 7.3.10 section 7.0 section 7.4.5

How Statistics Every Programmer Needs covers it

How deep it goes
Defines the three components, selects an order through stationarity and correlation checks, fits a model, and evaluates residuals and held-out forecasts.
Examples
Fits ARIMA(1, 1, 0) to Apple closing prices through March 2024 and compares its April forecast with observed prices.
What it assumes
Introduces stationarity, differencing, and ACF/PACF before fitting; uses Python data subsets and plots in the worked example.
What you can do after
Apply it via Python statsmodels to fit an ARIMA model, forecast held-out observations, and inspect residuals.
How it connects
Connects stationarity, differencing, ACF/PACF, residual diagnostics, and exponential smoothing to time-series model selection.

Also explained in

Compare how 2 books explain arima →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.