ARIMA Models — Complete Guide
Statistics
Combining Autoregression, Integration, and Moving Average
ARIMA models unify three powerful concepts — autoregressive dependence, differencing for stationarity, and moving average error correction — into a flexible framework for modeling and forecasting time series.
-
Financial Forecasting — Predict stock volatility and returns
-
Supply Chain — Forecast demand with seasonal patterns and trends
-
Energy — Model electricity consumption for grid management
The three parameters (p,d,q) encode the memory, trend, and noise structure of any time series.
ARIMA (Autoregressive Integrated Moving Average) models combine autoregression, differencing, and moving average components to model and forecast time series data.
DfARIMA(p,d,q) Model
An ARIMA(p,d,q) model is defined as:
ARIMA(p,d,q)
Here,
- =Order of the autoregressive (AR) part
- =Degree of differencing
- =Order of the moving average (MA) part
- =Backshift operator: $BY_t = Y_{t-1}$
- =AR polynomial: $1 - \phi_1 B - \cdots - \phi_p B^p$
- =MA polynomial: $1 + \theta_1 B + \cdots + \theta_q B^q$
- =White noise error term
Component Models
AR(p) — Autoregressive
AR(p) Model
Here,
- =AR coefficient at lag i
- =Constant (drift)
Stationarity Condition
An AR(p) process is stationary if all roots of lie outside the unit circle.
MA(q) — Moving Average
MA(q) Model
Here,
- =MA coefficient at lag i
- =Mean of the process
Invertibility
An MA(q) process is invertible if all roots of lie outside the unit circle.
ARMA(p,q)
ARMA(p,q) Model
Here,
- =Number of AR terms
- =Number of MA terms
Model Identification Steps
| Step | Action |
|------|--------|
| 1 | Plot the series — look for trend, seasonality |
| 2 | Test stationarity — ADF and KPSS tests |
| 3 | Difference if needed — determine d |
| 4 | Examine ACF/PACF — identify p and q |
| 5 | Estimate model parameters |
| 6 | Diagnostics — check residuals |
| 7 | Forecast and evaluate |
AR vs MA
-
ACF cuts off -> MA model; look at ACF lag for q
-
PACF cuts off -> AR model; look at PACF lag for p
-
Both tail off -> ARMA; use AIC/BIC to compare models
Information Criteria
AIC and BIC
Here,
- =Maximized likelihood value
- =Number of parameters
- =Sample size
Lower AIC/BIC indicates a better model. BIC penalizes complexity more heavily.
Residual Diagnostics
After fitting, check that residuals are white noise:
-
Ljung-Box test: No autocorrelation in residuals
-
Normality test: Residuals approximately normal
-
Plot: No patterns in residuals vs. fitted values
Ljung-Box Statistic
Here,
- =Sample size
- =Number of lags tested
- =Sample ACF at lag k
Python Implementation
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.arima.model import ARIMA
from statsmodels.tsa.stattools import adfuller
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
np.random.seed(42)
# Simulate AR(1) process
n = 300
y = np.zeros(n)
for t in range(1, n):
y[t] = 0.7 * y[t-1] + np.random.randn()
# Stationarity test
adf = adfuller(y)
print(f"ADF p-value: {adf[1]:.4f}")
# Fit ARIMA(1,0,0) = AR(1)
model = ARIMA(y, order=(1, 0, 0))
results = model.fit()
print(results.summary())
# Diagnostics
print(f"\nLjung-Box p-value: {results.test_serial_correlation('ljungbox', lags=[10])[0]['lb_pvalue'].values[0]:.4f}")
# Forecast
forecast = results.forecast(steps=10)
print(f"\n10-step forecast: {forecast[:5].round(3)}")
Worked Example
Example: Fitting ARIMA(1,1,1)
Given a non-stationary time series with 200 observations:
-
ADF test: p-value = 0.45 -> non-stationary
-
First difference : ADF p-value = 0.001 -> stationary, so d = 1
-
ACF of differenced series: Significant spike at lag 1, then cuts off -> q = 1
-
PACF of differenced series: Exponential decay -> p = 1
-
Fit ARIMA(1,1,1): AIC = 450.2
-
Compare with ARIMA(0,1,1): AIC = 455.8 -> ARIMA(1,1,1) is preferred
-
Ljung-Box test on residuals: p-value = 0.35 -> residuals are white noise
-
Conclusion: ARIMA(1,1,1) provides a good fit
Forecasting
Point Forecast
Here,
- =Forecast horizon
- =Last observation time
Forecast accuracy is measured by:
| Metric | Formula | Interpretation |
|--------|---------|---------------|
| MAE | | Average absolute error |
| RMSE | | Penalizes large errors |
| MAPE | | Percentage error |
Key Takeaways
Summary: ARIMA Models
-
ARIMA(p,d,q) combines AR, differencing, and MA components
-
Use ACF/PACF to identify p and q; use ADF/KPSS to determine d
-
AR(p): PACF cuts off at lag p
-
MA(q): ACF cuts off at lag q
-
Always check residual diagnostics (Ljung-Box, normality)
-
Use AIC/BIC to compare non-nested models
-
Over-differencing can introduce unnecessary dependence
Related Topics
-
See ACF and PACF for identifying model orders
-
See Stationarity for testing stationarity
-
See Seasonal Decomposition for seasonal ARIMA (SARIMA)