Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 40 ยท Stationarity and Transformations

Stationarity and Random Walks

Learn what stationarity means, why models need it, and how white noise, random walks with drift, trends and changing variance differ, with simulations you can run.

Most classical forecasting theory assumes the series is stationary. That word sounds abstract, but the idea is simple: the statistical behaviour of the series does not depend on when you look. If you cut out any window of the same length, it should look about the same. In this lesson you will define stationarity, meet the two most important simple processes (white noise and the random walk), and learn to recognise non-stationarity by eye and by simple numbers.

Why stationarity matters

To learn from the past you need the past to resemble the future. If the mean keeps climbing or the variance keeps exploding, averages computed over history say little about tomorrow. Models such as ARMA estimate a fixed mean, a fixed variance and fixed correlations from the data, and that only makes sense for stationary input. Non-stationary series are therefore transformed (differenced, logged, detrended) first; see differencing.

The definition

A series is weakly (covariance) stationary if:

  1. The mean is constant over time.
  2. The variance is constant over time.
  3. The autocovariance between y(t) and y(t+h) depends only on the lag h, not on t.

Stationary or not?

Constant mean No trend, no level shifts.
Constant variance Same spread all along.
Stable correlation Depends on lag only.

Trend, seasonality and growing variance all break it.

1 / 2

Seasonality also breaks stationarity because the mean depends on the time of year. A cycle with no fixed period does not.

White noise

White noise is the building block: independent draws with constant mean (usually 0) and constant variance. It is stationary, has no correlation between values, and cannot be forecast beyond its mean. The residuals of a good model should look like white noise.

The random walk

A random walk adds a fresh shock to the previous value:

y(t) = y(t-1) + e(t)

It is the sum of all past shocks, so the variance grows with time and the series has no home level to return to. A random walk with drift adds a constant each step: y(t) = c + y(t-1) + e(t). Stock prices and many cumulative measures behave roughly like this.

Python Simulate white noise and a random walk

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The noise series has about the same mean and spread in every third. The random walk's mean drifts away from 0 and the walk with drift marches steadily up: neither is stationary.

Spurious behaviour: why the eye is fooled

Random walks produce convincing "trends" and "cycles" by chance. Two completely independent random walks often show a high correlation and a significant regression, the famous spurious regression problem. This is why you test and fix non-stationarity before regressing one series on another.

Python Two unrelated random walks look related

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A large share of unrelated random walks correlate strongly, yet their differences, which are plain white noise, never do.

Trend-stationary versus difference-stationary

Two different kinds of "non-stationary trend" need different fixes:

Type Model Fix
Trend-stationary y(t) = a + b*t + stationary noise fit and remove the trend (detrending)
Difference-stationary (unit root) y(t) = y(t-1) + stationary noise difference the series

Detrending a random walk does not make it stationary, and differencing a trend-stationary series over-differences it and adds artificial correlation. Formal unit root tests help you choose.

Quick checks for stationarity

  • Plot the series with a rolling mean and rolling standard deviation: flat lines suggest stationarity.
  • Compare summary statistics of the first and second half.
  • Look at the autocorrelation plot: for non-stationary series the autocorrelations decay very slowly.
Python Rolling statistics reveal non-stationarity

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The trending series has a wide range of rolling means, and the growing-variance series has a wide range of rolling standard deviations. The stationary one keeps both ranges small.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which is NOT required for weak stationarity?

    Weak stationarity says nothing about the distribution being normal.
  2. 2. What happens to the variance of a random walk over time?

    A random walk accumulates shocks, so its variance grows with t.
  3. 3. A series is a random walk with drift. How do you make it stationary?

    It is difference-stationary: the first difference is constant drift plus white noise.
  4. 4. Why can regressing one random walk on another be misleading?

    Shared wandering behaviour produces high correlations and significant coefficients by chance.

Summary

  • Stationary means constant mean, constant variance and lag-only autocovariance.
  • White noise is stationary and unpredictable; a random walk is the cumulative sum of noise and is not stationary.
  • Trend, seasonality and changing variance are the usual causes of non-stationarity.
  • Trend-stationary series are detrended; difference-stationary series are differenced.
  • Rolling statistics and plots are the first diagnostic; formal tests follow.

Next: Differencing and Detrending