SARIMA (Seasonal ARIMA) › Example

Michael BrenndoerferAugust 11, 20255 min read
Machine Learning from ScratchAll chapters
Part 8 of 9Time Series
Chapter 58SARIMA (Seasonal ARIMA) › Example
Reading section 5 of 9 · Example · 5 minSection 5 of 9 · 5 min

Book contents

Section 5 of 9 · 5 min read

SARIMA (Seasonal ARIMA) › ExampleOne section · Sections in this chapter5 / 9 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Let's work through a concrete example using monthly sales data to see how the SARIMA formula translates into practice. We'll trace each component of the model to understand how they work together to produce forecasts.

The Data: Monthly Sales with Clear Patterns

Suppose we have monthly sales data for a retail store over 3 years (36 months). The sales show two clear patterns:

  • An upward trend: sales gradually increase over time
  • Strong seasonality: December sales consistently spike due to holiday shopping, then drop in January

For the first 12 months, our data (in thousands of dollars) looks like:

  • January: 45, February: 48, March: 52, April: 55, May: 58, June: 62
  • July: 65, August: 68, September: 70, October: 75, November: 85, December: 120

The December spike (120) is nearly three times the January value (45), and we see a steady upward progression throughout the year. These patterns.trend and seasonality.are exactly what SARIMA is designed to handle.

Step 1: Understanding Why We Need Differencing

The first challenge is that our data is non-stationary. The mean changes over time (trending upward), and the variance changes (December values are much higher). To apply ARMA components, we need a stationary series.

Non-seasonal differencing addresses the trend. We compute first differences: ∇Xt=Xt−Xt−1\nabla X_t = X_t - X_{t-1}. For example:

  • February difference: 48 - 45 = 3
  • March difference: 52 - 48 = 4
  • December difference: 120 - 85 = 35

The differenced series has a more stable mean, but we still see the December spike because seasonal patterns remain.

Seasonal differencing addresses the seasonality. We compute seasonal differences: ∇12Xt=Xt−Xt−12\nabla_{12} X_t = X_t - X_{t-12}. This compares each month to the same month last year:

  • January 2021 vs January 2020
  • December 2021 vs December 2020

After both types of differencing, we have a stationary series where the statistical properties are constant, making it suitable for ARMA modeling.

Step 2: Identifying the Model Structure

To determine which SARIMA model fits our data, we examine the autocorrelation structure of the differenced series using ACF (Autocorrelation Function) and PACF (Partial Autocorrelation Function) plots.

From these plots, we observe:

  • Non-seasonal patterns: The ACF cuts off after lag 1, suggesting q=1 (one moving average term). The PACF cuts off after lag 1, suggesting p=1 (one autoregressive term).
  • Seasonal patterns: Significant spikes at lags 12 and 24 in both ACF and PACF suggest we need both seasonal AR (P=1) and seasonal MA (Q=1) terms.

This analysis leads us to a SARIMA(1,1,1)(1,1,1)12 model. The notation tells us:

  • (1,1,1): One AR term, first-order differencing, one MA term (non-seasonal)
  • (1,1,1): One seasonal AR term, first-order seasonal differencing, one seasonal MA term
  • 12: The seasonal period (12 months = 1 year)

Step 3: Understanding the Model Equation

For our SARIMA(1,1,1)(1,1,1)12 model, the general equation:

ϕ(B)Φ(B12)∇∇12Xt=θ(B)Θ(B12)ϵt\phi(B) \Phi(B^{12}) \nabla \nabla_{12} X_t = \theta(B) \Theta(B^{12}) \epsilon_t

expands to:

(1−ϕ1B)(1−Φ1B12)∇∇12Xt=(1+θ1B)(1+Θ1B12)ϵt(1 - \phi_1 B)(1 - \Phi_1 B^{12}) \nabla \nabla_{12} X_t = (1 + \theta_1 B)(1 + \Theta_1 B^{12}) \epsilon_t

Let's break down what each part does:

  1. (1−ϕ1B)(1 - \phi_1 B): The non-seasonal AR term. This captures how this month's sales relate to last month's sales. If ϕ1=0.6\phi_1 = 0.6, it means 60% of this month's deviation from the mean is explained by last month's deviation.

  2. (1−Φ1B12)(1 - \Phi_1 B^{12}): The seasonal AR term. This captures how this month's sales relate to the same month last year. If Φ1=0.8\Phi_1 = 0.8, it means December 2021 sales are strongly influenced by December 2020 sales.

  3. ∇∇12Xt\nabla \nabla_{12} X_t: The differenced series. This is the stationary series the model uses.

  4. (1+θ1B)(1 + \theta_1 B): The non-seasonal MA term. This captures how this month's forecast error relates to last month's forecast error.

  5. (1+Θ1B12)(1 + \Theta_1 B^{12}): The seasonal MA term. This captures how this month's forecast error relates to the forecast error from the same month last year.

The multiplicative structure means these effects interact. For example, the interaction term ϕ1Φ1\phi_1 \Phi_1 captures how the December-to-December relationship might be different from the January-to-January relationship.

Step 4: How Forecasting Works

Once we've estimated the parameters (typically using maximum likelihood), we can generate forecasts. The forecasting process involves three steps:

  1. Apply differencing: Transform the original series to the differenced, stationary series
  2. Forecast the differenced series: Use the ARMA components to predict future values of the differenced series
  3. Reverse the differencing: Transform the forecasted differenced values back to the original scale

For a one-step-ahead forecast, the formula becomes:

X^t+1=ϕ1Xt+Φ1Xt−11−ϕ1Φ1Xt−12+θ1ϵt+Θ1ϵt−11+θ1Θ1ϵt−12\hat{X}_{t+1} = \phi_1 X_t + \Phi_1 X_{t-11} - \phi_1 \Phi_1 X_{t-12} + \theta_1 \epsilon_t + \Theta_1 \epsilon_{t-11} + \theta_1 \Theta_1 \epsilon_{t-12}

This equation shows how the forecast combines multiple sources of information:

  • ϕ1Xt\phi_1 X_t: The non-seasonal AR contribution.how last month's value influences this month
  • Φ1Xt−11\Phi_1 X_{t-11}: The seasonal AR contribution.how the same month last year influences this month
  • −ϕ1Φ1Xt−12-\phi_1 \Phi_1 X_{t-12}: The interaction term.how the combined seasonal and non-seasonal effects interact
  • θ1ϵt\theta_1 \epsilon_t: The non-seasonal MA contribution.adjusting for last month's forecast error
  • Θ1ϵt−11\Theta_1 \epsilon_{t-11}: The seasonal MA contribution.adjusting for the forecast error from the same month last year
  • θ1Θ1ϵt−12\theta_1 \Theta_1 \epsilon_{t-12}: The interaction of error terms

Why This Example Illustrates the Formula

This example demonstrates how each component of the SARIMA formula addresses a specific aspect of seasonal time series:

  • Differencing removes the non-stationary elements (trend and seasonality), creating a stable foundation
  • Non-seasonal AR/MA terms capture short-term dependencies and error patterns
  • Seasonal AR/MA terms capture long-term seasonal dependencies and seasonal error patterns
  • The multiplicative structure allows these effects to interact, capturing the complex relationships in real seasonal data

The result is a model that can forecast both the short-term progression (month-to-month changes) and the long-term seasonal patterns (year-to-year cycles) simultaneously, which makes SARIMA effective for seasonal forecasting.