6 · Differencing
Differencing — subtracting the previous value — removes a trend and is the 'd' in ARIMA. A seasonal lag-m difference removes a repeating cycle.
First differencing Δy_t = y_t − y_{t-1} removes a linear trend and usually makes a series stationary — that's the 'd' in ARIMA(p,d,q). Seasonal differencing y_t − y_{t-m} removes a repeating cycle of period m.
Without this:
Without differencing you feed a trending series straight into AR/MA models that assume stationarity, and the fit chases the drift instead of the real short-term dynamics.
When the ADF test says a series is non-stationary because of a trend, the standard cure is differencing: replace each value with the change from the previous step.
Δy_t = y_t − y_{t-1}
A constant trend (the level rising by a fixed amount each step) becomes a roughly constant differenced series — the slope is removed, the mean flattens, and the series typically passes the ADF test. The number of times you difference to reach stationarity is exactly the d in ARIMA(p, d, q). Most real series need d = 0 or d = 1; d = 2 handles a trend whose slope itself is changing. Over-differencing is a real risk — it injects artificial negative autocorrelation — so difference the minimum amount that passes ADF.
A trend is not the only repeating structure. When a series has seasonality with period m (12 for monthly-yearly, 7 for daily-weekly), ordinary differencing won't remove it. Instead use seasonal differencing, subtracting the value one full season ago:
Δ_m y_t = y_t − y_{t-m}
This cancels the repeating pattern (each value minus the same point in the previous cycle) and is the seasonal D in SARIMA(p,d,q)(P,D,Q)_m. Below we take a trending series, apply first differencing, and watch the ADF p-value collapse below 0.05; then we take a strongly seasonal series and show that a lag-m seasonal difference is what flattens it.
Python (in browser)
First differencing drops a trending series' ADF p-value below 0.05; a lag-12 seasonal difference collapses a yearly cycle's variance — the 'd' and 'D' of (S)ARIMA.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Your monthly series has a strong yearly cycle but almost no long-term trend. Which operation makes it stationary?
- First differencing Δy_t = y_t − y_{t-1} removes a linear trend and usually achieves stationarity — that's the 'd' in ARIMA.
- Seasonal differencing y_t − y_{t-m} cancels a repeating cycle of period m — the 'D' in SARIMA.
- Difference the minimum needed (re-test ADF each time); over-differencing injects artificial negative autocorrelation.
The d and D parameters of (S)ARIMA are exactly these differencing steps; auto_arima searches over them, and you also difference manually before AR/MA models.
If you remove it: Skip differencing and ARIMA tries to model a non-stationary series directly — unstable coefficients and forecasts that drift away from reality.