Skip to main content

ARIMA Models

AnoFox implements 3 ARIMA variants: classic ARIMA with manual (p,d,q) specification, AutoARIMA with automatic order selection up to p=5 and q=5, and ARIMAX for incorporating exogenous variables like temperature, promotions, or economic indicators. Seasonal ARIMA extends these with (P,D,Q) seasonal components. AutoARIMA is the recommended choice for production pipelines -- it tests candidate models using information criteria and handles both seasonal and non-seasonal patterns.

ARIMA (AutoRegressive Integrated Moving Average) is a time-series forecasting model that combines three components: autoregression (AR), which models the relationship between an observation and a number of lagged observations; differencing (I), which makes the series stationary by subtracting consecutive values; and moving average (MA), which models the dependency between an observation and residual errors from past predictions. ARIMA models dependencies between observations.

ModelDescription
ARIMAClassic ARIMA with manual parameter specification
AutoARIMAAutomatic ARIMA with (p,d,q) selection
ARIMAXARIMA with exogenous variables
Showing 3 of 3

ARIMA

Classic ARIMA model with manual parameter specification.

Parameters

ParameterTypeRequiredDescription
pINTEGERYesAR (autoregressive) order
dINTEGERYesDifferencing order
qINTEGERYesMA (moving average) order
seasonal_periodINTEGERNoFor seasonal ARIMA
PINTEGERNoSeasonal AR order
DINTEGERNoSeasonal differencing
QINTEGERNoSeasonal MA order

Example

-- Non-seasonal ARIMA(1,1,1)
SELECT * FROM ts_forecast_by(
'sales_data', NULL, date, sales,
'ARIMA', 28, '1d',
MAP{'p': '1', 'd': '1', 'q': '1'}
);

-- Seasonal ARIMA(1,1,1)(1,1,1)[7]
SELECT * FROM ts_forecast_by(
'weekly_data', NULL, date, value,
'ARIMA', 28, '1d',
MAP{'p': '1', 'd': '1', 'q': '1', 'P': '1', 'D': '1', 'Q': '1', 'seasonal_period': '7'}
);

Best for: Complex patterns when you know the appropriate order.


AutoARIMA

Automatic ARIMA with (p,d,q) parameter selection using information criteria.

Parameters

ParameterTypeDefaultDescription
seasonal_periodINTEGER-Seasonal period (detect with ts_detect_periods_by first)
max_pINTEGER5Maximum AR order
max_dINTEGER2Maximum differencing order
max_qINTEGER5Maximum MA order

Example

SELECT * FROM ts_forecast_by(
'sales_data', NULL, date, sales,
'AutoARIMA', 28, '1d',
MAP{'seasonal_period': '7'}
);

Best for: Complex patterns, long-term forecasts, automatic tuning.

Seasonality Not Auto-Detected

Seasonality is NOT auto-detected. You must detect the period first with ts_detect_periods_by and pass it explicitly via seasonal_period.


Parameter Selection Guide

Scenariopdq
Stationary data1-201-2
Trending data1-211-2
Strong trend1-221-2
Random walk010

When to Use ARIMA vs AutoARIMA

ScenarioRecommended
Known order from domain expertiseARIMA
Exploratory analysisAutoARIMA
Production pipelineAutoARIMA
Performance-criticalARIMA (faster)
Many time seriesAutoARIMA
External predictorsARIMAX

ARIMAX

ARIMA with exogenous (external) variables. Incorporates external predictors like temperature, promotions, or economic indicators.

Parameters

ParameterTypeDefaultDescription
seasonal_periodINTEGER-Seasonal period (detect with ts_detect_periods_by first)
max_pINTEGER5Maximum AR order
max_dINTEGER2Maximum differencing order
max_qINTEGER5Maximum MA order

Example

-- Create future exogenous values
CREATE TABLE future_exog AS
SELECT * FROM (VALUES
('2024-01-08'::DATE, 22.0, 1),
('2024-01-09'::DATE, 20.0, 0),
('2024-01-10'::DATE, 21.0, 1)
) AS t(date, temperature, promotion);

-- Forecast with exogenous variables
SELECT * FROM ts_forecast_exog_by(
'sales_data', NULL, date, sales,
['temperature', 'promotion'],
'future_exog', date, ['temperature', 'promotion'],
'ARIMAX', 3,
MAP{}, '1d'
);

Best for: Complex patterns with external drivers, weather-adjusted demand, promotion planning.

ARIMAX is one of 3 exogenous-capable models in AnoFox Forecast (alongside ThetaX and MFLESX). All 3 use the ts_forecast_exog_by function, which requires both historical and future values for each external predictor. This makes ARIMAX particularly effective for demand planning where promotional calendars, weather forecasts, or pricing schedules are known in advance.

See Exogenous Variables for detailed usage


Frequently Asked Questions

What do the (p, d, q) parameters mean in practice?

p (AR order) controls how many past values influence the current prediction. d (differencing order) controls how many times the series is differenced to achieve stationarity -- use d=1 for trending data, d=2 for strong trends. q (MA order) controls how many past forecast errors influence the current prediction. For seasonal ARIMA, (P, D, Q) are the same concepts applied at the seasonal frequency.

Why does AutoARIMA not auto-detect seasonality?

Seasonal period detection and model fitting are separate concerns. AutoARIMA optimizes the (p,d,q) orders given a seasonal period, but it does not search for the period itself. Run ts_detect_periods_by first to find the seasonal period, then pass it to AutoARIMA via MAP{'seasonal_period': '7'}. This separation gives you explicit control and avoids silent misdetection.

When should I use ARIMAX instead of AutoARIMA?

Use ARIMAX when you have external predictors (temperature, promotions, pricing) that you believe influence the target variable and for which you can provide future values. ARIMAX models the relationship between these external variables and your target while also capturing the autoregressive and moving average dynamics. If you have no external data, stick with AutoARIMA.

ARIMA is slow on my large dataset. How can I speed it up?

AutoARIMA's search over candidate models is inherently slower than simpler methods. To speed things up: (1) reduce max_p and max_q from the default of 5 to 2-3 if you do not expect high-order dependencies, (2) use the Theta method for comparable accuracy with faster execution, or (3) use AutoETS which typically runs faster than AutoARIMA for seasonal data.


🍪 Cookie Settings