Skip to content
Tutorials Center
My learning

Topics

Lesson 25 of 40 ยท ARIMA and SARIMA

ARIMAX and Exogenous Regressors

Add outside drivers such as price, weather or holidays to an ARIMA model with SARIMAX: dummy variables, lagged effects, the future-values requirement and how to read coefficients.

An ARIMA model forecasts a series from its own history only. But many series are driven by things you know about: a store's sales respond to promotions, electricity demand to temperature, website traffic to marketing spend, ride counts to holidays. These outside drivers are called exogenous variables (the X in SARIMAX and ARIMAX). Adding them lets the model explain part of the variation directly and leaves the ARIMA part to model what is left.

The structure is a regression with ARIMA errors:

y[t] = beta1 * x1[t] + beta2 * x2[t] + ... + n[t], where n[t] follows an ARIMA process.

This is cleaner than putting x into an AR model, because each beta keeps its plain meaning: the effect on y of a one-unit change in x, holding the autocorrelated part separate.

A simulated promotion example

We make a daily series where a promotion (a 0/1 dummy) adds 12 units of sales and the baseline is an AR(1) process. The model should recover the 12.

Python Fit SARIMAX with a promotion dummy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The promo coefficient should come out close to 12, with a tight interval. intercept is the baseline level, ar.L1 the persistence of the leftover noise, and sigma2 the noise variance.

The big catch: you need the future values of X

To forecast, the model needs the future values of every regressor. That is easy for things you control or know in advance (planned promotions, calendar holidays, day-of-week dummies) and hard for things you do not (tomorrow's temperature). For the second kind you must forecast X first (adding its error to yours) or use a weather forecast as an input.

Python Forecast with planned future promotions

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Plan B is higher on exactly the promo days, by about the estimated effect (the AR part also carries a fading echo into the days after). This ability to ask "what if?" is a major reason to use regressors.

Never feed in a regressor you would not know at forecast time. Using today's actual temperature to "forecast" today's demand gives lovely backtests and useless production forecasts. Backtest with the values you would really have had.

Calendar effects and dummies

The most common exogenous inputs are calendar features:

  • Day of week (six dummies, one level dropped), when s = 7 would be too rigid.
  • Holidays and the days around them.
  • Month, as an alternative to seasonal terms for short histories.
  • Trend break or intervention dummies, e.g. a pulse for a one-off outage, or a step for a policy change.
Python Holiday and weekend dummies

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The coefficients land near +20 for weekends and -15 for holidays. With an order of (0, 0, 0) this is just a regression; ARIMA terms only matter when the leftover noise is autocorrelated.

Lagged effects

Often an input affects the outcome with a delay: advertising today lifts sales over the next several days. Build lagged copies with shift and include them as extra columns. Remember that a lag of k means the regressor's value is known k steps ahead of time, which helps forecasting.

Python Lagged regressor columns

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Dropping the first rows with dropna keeps the regressor and the target aligned (also drop the same dates from y).

Choosing and checking regressors

  1. Start with the plain ARIMA or SARIMA model, then add regressors one group at a time.
  2. Keep a regressor only if its coefficient is significant and it improves out-of-sample error.
  3. Beware multicollinearity: weekend and a "Saturday" dummy together are redundant and make the fit unstable.
  4. Check the residuals again after adding regressors; a missing driver often shows up as a pattern in them.

For several series that influence each other, a vector autoregression is the symmetric alternative: each series is both response and driver.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the main practical requirement of an exogenous-regressor model at forecast time?

    The model cannot predict y without knowing x over the forecast horizon, so you need planned values or forecasts of x.
  2. 2. A SARIMAX model gives the coefficient 12.1 for a promotion dummy. How do you read it?

    In a regression with ARIMA errors, the coefficient is the effect of a one-unit change in the regressor on y.
  3. 3. Why is using today's actual temperature to forecast today's demand a problem in production?

    This is a form of leakage: the regressor must be available when the forecast is made.
  4. 4. You include both a 'weekend' dummy and a 'Saturday' and 'Sunday' dummy. What goes wrong?

    The weekend dummy equals the sum of the other two, so the columns are linearly dependent.

Summary

  • SARIMAX fits a regression on exogenous variables whose errors follow an ARIMA/SARIMA process.
  • Coefficients read as the effect of one unit of the regressor; calendar dummies and interventions are the typical inputs.
  • Forecasting requires future values of the regressors; never use information you would not have at forecast time.
  • Lag regressors with shift, avoid collinear dummies, and re-check residuals after adding terms.

Next: ARIMA Residual Diagnostics