ML Systems Lab Open interactive version →
Foundational 35 min read stationarityunit-rootdifferencingcointegrationADF

Stationarity & Differencing

Unit root tests, spurious regression, integration order, cointegration

Regress two independent random walks against each other and you'll get R² near 1 and t-statistics in double digits — not because they're related, but because both are trending. That's spurious regression, and it invalidates every downstream conclusion.

It's the reason stationarity matters: non-stationary series have growing variance and shifting means, so the statistical tests that assume constant moments produce completely unreliable results. The ADF and KPSS tests tell you whether you have a unit root; differencing removes trends; seasonal differencing removes periodicity. The flip side of non-stationarity is cointegration — two non-stationary series can share a long-run equilibrium whose spread is stationary, and error correction models exploit that structure rather than discarding it.

Key points

Takeaway

Stationarity is not a box to check once at model training time — spurious regression is the immediate consequence of skipping it, and structural breaks mean a series that was stationary at training time may not be stationary in production. The most important inference to demonstrate is knowing when two non-stationary series should be modelled jointly (cointegration + ECM preserves the long-run relationship) versus separately in first differences (when no cointegrating vector exists and the long-run relationship is meaningless).

Recap

Check your understanding

Q1. You regress daily revenue on daily temperature for 3 years and get R² = 0.72 with t-stat = 18. The DW statistic is 0.12. What is wrong and how do you fix it?

Q2. Which TWO of the following statements about ADF and KPSS are correct?

Q3. You have two financial time series (stock price and its futures contract price) that are both I(1). How do you decide whether to model them separately in first differences or jointly?

Q4. Your revenue series passes ADF stationarity test. You fit an ARIMA(1,0,1) and the residuals look clean. Six months later the model performance degrades sharply. What likely happened and how do you detect it earlier?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →