4 · Stationarity & the ADF test
AR and ARIMA assume the series is stationary — its statistics don't drift over time. The Augmented Dickey-Fuller test gives you a hard number to check it.
A series is stationary when its mean, variance, and autocovariance stay constant over time. AR/ARIMA require it, and the Augmented Dickey-Fuller (ADF) test checks it: p < 0.05 rejects the unit root → stationary.
Without this:
Fit ARIMA to a trending (non-stationary) series without checking, and the model chases the drift instead of the dynamics — forecasts that look fine in-sample and diverge out-of-sample.
Almost every classical forecasting model — AR, MA, ARMA, ARIMA — assumes the series is stationary. A series is (weakly) stationary when three statistics stay constant no matter where you look in time:
- Constant mean — no upward or downward trend.
- Constant variance — the spread doesn't grow or shrink over time.
- Constant autocovariance — the correlation between two points depends only on the gap between them (the lag), not on when they occur.
Why does it matter? These models learn one fixed set of coefficients that describe how the past relates to the present. If the mean is drifting (a trend) or the variance is exploding, there is no single fixed relationship to learn — the rules keep changing. A trending series has a unit root: today's value is essentially yesterday's value plus a shock, so shocks never fade and the level wanders without bound.
The Augmented Dickey-Fuller (ADF) test turns "does it look stationary?" into a number. Its null hypothesis is "the series has a unit root (is non-stationary)." A small p-value lets you reject that null:
- p < 0.05 → reject the unit root → treat the series as stationary.
- p ≥ 0.05 → fail to reject → likely non-stationary, you'll need to difference it (next lessons).
The more negative the ADF statistic (and the further below the critical values), the stronger the evidence. Below we build one clearly non-stationary series (a strong linear trend) and one clearly stationary series (noise around a fixed mean), then run adfuller on each and read the verdict.
Python (in browser)
adfuller on a trending series vs a noise-around-mean series: the trend gives a high p-value (non-stationary), the noise a tiny one (stationary).
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
An ADF test returns a p-value of 0.62. What does that tell you about the series?
- Stationary = constant mean, variance, and autocovariance over time; AR/ARIMA assume it.
- The ADF test's null is 'has a unit root (non-stationary)'; p < 0.05 rejects it → stationary.
- A trend gives a high ADF p-value; fix it by differencing (the 'd' in ARIMA) and re-test.
Every ARIMA/SARIMA workflow runs an ADF (or KPSS) check first to decide how much differencing the data needs.
If you remove it: Skip the stationarity check and you fit models to drifting data, producing forecasts that diverge once you predict beyond the trend you accidentally memorized.