Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 40 ยท ARIMA and SARIMA

SARIMA: Seasonal ARIMA

Add seasonality to ARIMA with SARIMA(p,d,q)(P,D,Q)s: understand seasonal differencing, fit SARIMAX in statsmodels, compare candidates by AIC, and forecast monthly data.

Real series rarely have only a trend. Electricity use peaks every winter, ice cream sales every summer, web traffic every weekday. A plain ARIMA model sees this as a long, awkward pattern of correlations and needs a huge number of lags to describe it. SARIMA (Seasonal ARIMA) adds a second set of terms that act on the seasonal lags directly, so a yearly pattern in monthly data costs just a few parameters.

The full notation is SARIMA(p, d, q)(P, D, Q)s. The first bracket is the familiar non-seasonal part; the second bracket has the same meaning but works at lags that are multiples of the seasonal period s (s = 12 for monthly data with a yearly cycle, s = 7 for daily data with a weekly cycle, s = 24 for hourly data with a daily cycle).

The seasonal terms

Term Meaning
D number of seasonal differences: y[t] - y[t-s]
P seasonal AR: depends on y[t-s], y[t-2s], ...
Q seasonal MA: depends on shocks e[t-s], e[t-2s], ...
s the length of the season

A seasonal difference subtracts the value from one full cycle ago, which wipes out a stable seasonal pattern the way ordinary differencing wipes out a trend.

Python Seasonal differencing removes the cycle

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.

After the seasonal difference every month averages about the same (roughly the trend's yearly gain, 0.4 x 12 = 4.8), so the cycle is gone. Notice that the first 12 values are lost, so seasonal differencing needs at least a few seasons of data.

Fit a SARIMA model

In statsmodels, SARIMA is available through SARIMAX (the X is for exogenous regressors, covered in the next lesson). The seasonal_order argument takes (P, D, Q, s).

The "airline model", SARIMA(0,1,1)(0,1,1)12, is a classic that fits many monthly series with trend and multiplicative seasonality (after a log transform). It is a good first thing to try.

Python The airline model on a seasonal series

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.

You get an ma.L1 (non-seasonal MA) and an ma.S.L12 (seasonal MA) coefficient. Both are typically negative for this model, and both should be significant.

If the seasonal swings grow with the level of the series, model the log of the data (as above) and exponentiate the forecasts afterwards. Log-transforms are covered in the transformations chapter.

Forecast and invert the log

Forecasts from the log model come back on the log scale. Apply np.exp to return to the original units.

Python Forecast 12 months ahead

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 forecast repeats the seasonal shape of the previous year, lifted by the trend. The interval is exponentiated too, so it is asymmetric on the original scale: that is correct for a log model.

Choosing the seasonal orders

Follow the same Box-Jenkins logic as before, but look at the seasonal lags (12, 24, 36 for monthly data) in the ACF and PACF of the doubly-differenced series.

  1. Pick s from the domain (not from the data): 12 for monthly, 4 for quarterly, 7 for daily-with-weekly-cycle.
  2. Set D = 1 if the seasonal pattern is stable; D = 0 if it is weak. Almost never use D = 2.
  3. A spike at lag s in the ACF that dies out suggests a seasonal MA term (Q = 1); a spike at lag s in the PACF suggests a seasonal AR term (P = 1).
  4. Keep P and Q at 0 or 1 for a start; compare by AIC.
Python Compare seasonal candidates

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 model with no seasonal terms is far worse, which confirms that the seasonal part earns its keep.

flowchart TD
    A["Plot the series and its seasonal lags"] --> B["Choose s from the domain"]
    B --> C["Difference: d for trend, D for season"]
    C --> D["Read ACF/PACF at lags 1..3 and s, 2s"]
    D --> E["Fit a few small candidates"]
    E --> F{"Residuals white noise?"}
    F -->|"no"| D
    F -->|"yes"| G["Forecast"]

Seasonal Box-Jenkins: the same loop, with extra lags to inspect.

Practical limits

  • Long periods are expensive. SARIMA with s = 365 for daily data is impractical: the state space is huge. Use Fourier terms as regressors instead (see the Fourier regression lesson).
  • Several seasonalities at once (daily and weekly and yearly) cannot be expressed with a single s. Use regressors or the machine-learning approach.
  • Few seasons of data. You need several full cycles. Two years of monthly data is thin for a seasonal model.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In SARIMA(1,1,1)(0,1,1)12, what does the (0,1,1)12 part do?

    The seasonal bracket is (P, D, Q) at period s: here no seasonal AR, one seasonal difference (y[t] minus y[t-12]), and one seasonal MA term.
  2. 2. Which seasonal period s fits daily sales data with a weekly pattern?

    The period is the number of observations in one full cycle: seven days in a week.
  3. 3. Seasonal swings grow as the level of the series rises. What is the usual remedy?

    A log transform turns multiplicative seasonality into additive seasonality, which SARIMA handles.
  4. 4. Why does seasonal differencing need several seasons of data?

    Subtracting the value one cycle earlier loses s observations, and estimating seasonal structure requires seeing it repeat several times.

Summary

  • SARIMA(p,d,q)(P,D,Q)s adds seasonal AR, differencing and MA terms at multiples of the period s.
  • Use SARIMAX(y, order=..., seasonal_order=(P, D, Q, s)); the airline model (0,1,1)(0,1,1)12 is a strong first try.
  • Log-transform multiplicative seasonality, and exponentiate forecasts and intervals afterwards.
  • Compare small candidates by AIC; avoid huge s and multiple seasonalities, where regressors work better.

Next: ARIMAX and Exogenous Regressors