SARIMA (Seasonal ARIMA) › Example
Machine Learning from ScratchAll chapters 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: . 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: . 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:
expands to:
Let's break down what each part does:
-
: The non-seasonal AR term. This captures how this month's sales relate to last month's sales. If , it means 60% of this month's deviation from the mean is explained by last month's deviation.
-
: The seasonal AR term. This captures how this month's sales relate to the same month last year. If , it means December 2021 sales are strongly influenced by December 2020 sales.
-
: The differenced series. This is the stationary series the model uses.
-
: The non-seasonal MA term. This captures how this month's forecast error relates to last month's forecast error.
-
: 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 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:
- Apply differencing: Transform the original series to the differenced, stationary series
- Forecast the differenced series: Use the ARMA components to predict future values of the differenced series
- Reverse the differencing: Transform the forecasted differenced values back to the original scale
For a one-step-ahead forecast, the formula becomes:
This equation shows how the forecast combines multiple sources of information:
- : The non-seasonal AR contribution.how last month's value influences this month
- : The seasonal AR contribution.how the same month last year influences this month
- : The interaction term.how the combined seasonal and non-seasonal effects interact
- : The non-seasonal MA contribution.adjusting for last month's forecast error
- : The seasonal MA contribution.adjusting for the forecast error from the same month last year
- : 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.