-
Notifications
You must be signed in to change notification settings - Fork 22
Explanatory Variables
This page documents how to include external regressors (explanatory variables) in smooth models.
Note: This is not yet supported in Python.
Read more about the implementation in ADAM and different options in Chapter 10 of Svetunkov (2023).
Smooth models support explanatory variables (exogenous regressors) that can improve forecasts when external factors influence the time series. This creates models like ETSX (ETS with regressors) or ARIMAX (ARIMA with regressors).
| Parameter | Type (R) | Type (Python) | Description |
|---|---|---|---|
formula |
formula | - | R formula for variable relationships |
xreg |
matrix/data.frame | - | External regressors matrix |
regressors |
character | - | How to handle regressors: "use", "select", "adapt" |
The formula parameter allows specifying relationships between the response and explanatory variables using R's formula syntax. This only works with adam().
# Data with explanatory variables
data <- cbind(y, x1, x2, x3)
# Use all variables
model <- adam(data, model="AAN", formula=y ~ x1 + x2 + x3)
# Use subset of variables
model <- adam(data, model="AAN", formula=y ~ x1 + x2)
# Include deterministic trend. Generated automatically, no need to have it in the data.
model <- adam(data, model="AAN", formula=y ~ x1 + x2 + trend)| Term | Description |
|---|---|
trend |
Adds a global deterministic trend to the model |
. |
All variables in the data |
-1 |
Remove intercept |
# All variables plus trend
model <- adam(data, model="AAN", formula=y ~ . + trend)
# Without specific variable
model <- adam(data, model="AAN", formula=y ~ . - x3)For simpler cases, the xreg parameter accepts a matrix of explanatory variables directly. This is implemented in es(), ssarima(), msarima(), ces(), and gum().
# Create regressor matrix
X <- cbind(promo=promo_data, holiday=holiday_dummy)
# ETS with regressors
model <- es(y, model="AAN", xreg=X)
# ARIMA with regressors
model <- ssarima(y, orders=c(1,1,1), xreg=X)- Columns should contain variables, rows should contain observations
- Number of rows should equal either in-sample size or total series length
- If
xreghas only in-sample observations, holdout values are extrapolated using ES during the forecasting step - For forecasting, new
xregvalues must be provided vianewdataparameter inforecast()
The regressors parameter controls how explanatory variables are treated:
| Value | Description | Use Case |
|---|---|---|
"use" |
Use all provided regressors as-is | When you're confident in your variable selection |
"select" |
Select regressors based on information criterion | When unsure which variables are useful |
"adapt" |
Make regressor coefficients time-varying | When relationships change over time |
# Automatic selection of regressors
model <- adam(data, model="AAN", formula=y ~ x1 + x2 + x3, regressors="select")
# Check which were selected
coef(model)With regressors="adapt", the coefficients of explanatory variables are updated over time using a smoothing mechanism similar to ETS states:
# Time-varying coefficients
model <- adam(data, model="AAN", formula=y ~ x1 + x2, regressors="adapt")This is useful when the effect of a regressor changes over time (e.g., price elasticity varying with market conditions).
# Provide initial values for regressor coefficients
model <- adam(data, model="AAN", formula=y ~ x1 + x2,
initial=list(xreg=c(0.5, -0.3)))# Initial values for xreg in ES
model <- es(y, model="AAN", xreg=X, initialX=c(0.5, -0.3))The formula() method extracts the formula used for explanatory variables.
model <- adam(data, model="AAN", formula=y ~ x1 + x2)
formula(model)
# y ~ x1 + x2For models without explicit formula, a decorative formula showing the measurement equation is returned.
When forecasting, future values of explanatory variables must be provided:
# Fit model
model <- adam(data, model="AAN", formula=y ~ x1 + x2)
# Forecast with new regressor values
new_data <- data.frame(x1=new_x1, x2=new_x2)
fc <- forecast(model, h=12, newdata=new_data)| Function | formula |
xreg |
regressors |
|---|---|---|---|
| ADAM | Yes | NA | ("use", "select", "adapt") |
| ES | NA | Yes | ("use", "select") |
| SSARIMA | NA | Yes | ("use", "select", "adapt") |
| MSARIMA | NA | Yes | ("use", "select", "adapt") |
| CES | NA | Yes | ("use", "select") |
| GUM | NA | Yes | ("use", "select", "adapt", "integrate") |
GUM supports an additional regressors="integrate" option, which applies integrated updating to the explanatory variables parameters. In that case, the transition matrix for the regressors will be estimated.
| Feature | R | Python |
|---|---|---|
formula |
Yes | TBA |
xreg |
Yes | TBA |
regressors |
Yes | TBA |
| Forecasting with X | Yes | TBA |
-
Variable selection: Start with
regressors="select"if unsure which variables are useful -
Adaptive coefficients: Use
regressors="adapt"when relationships might change over time - Future values: Ensure you have reliable forecasts or known values for regressors for the holdout period
- Multicollinearity: Check for correlation among regressors; selection can help here
- Svetunkov, I. (2023). Forecasting and Analytics with the Augmented Dynamic Adaptive Model (ADAM). Online book: https://openforecast.org/adam/
- Hyndman, R.J., et al. (2008). Forecasting with Exponential Smoothing: The State Space Approach. Springer.
- ADAM - Main ADAM function
- Loss-Functions - Including LASSO/RIDGE regularization
- Initialisation - Setting initial values for regressors
- Model-Information - Extracting model components