🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
Search courses…
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Stationarity in Time Series — Tests and Transformations

StatisticsTime Series Analysis🟢 Free Lesson

Advertisement

Stationarity in Time Series — Tests and Transformations

Statistics

Making Time Series Ready for Modeling

Stationarity — constant mean, variance, and autocorrelation over time — is a prerequisite for most forecasting models. ADF and KPSS tests detect non-stationarity, while differencing and transformations restore it.

  • Economic Forecasting — Transform non-stationary GDP data for reliable ARIMA modeling

  • Financial Analysis — Convert price series to stationary returns for volatility modeling

  • Climate Science — Remove trends from temperature data to analyze cyclical patterns

Stationary series are predictable because their statistical properties don't wander.


A time series is stationary if its statistical properties (mean, variance, autocorrelation) do not change over time. Stationarity is a key assumption for many time series models.

DfStationary Time Series

A time series {Yt}\{Y_t\} is strictly stationary if the joint distribution of (Yt1,Yt2,,Ytk)(Y_{t_1}, Y_{t_2}, \ldots, Y_{t_k}) is the same as (Yt1+τ,Yt2+τ,,Ytk+τ)(Y_{t_1+\tau}, Y_{t_2+\tau}, \ldots, Y_{t_k+\tau}) for all kk, all time indices, and all lags τ\tau.

DfWeakly Stationary

A time series is weakly (covariance) stationary if:

  1. E[Yt]=μE[Y_t] = \mu (constant mean)

  2. Var(Yt)=σ2\text{Var}(Y_t) = \sigma^2 (constant variance)

  3. Cov(Yt,Yt+h)=γ(h)\text{Cov}(Y_t, Y_{t+h}) = \gamma(h) (autocovariance depends only on lag h)


Why Stationarity Matters

Key Insight

Most time series models (AR, MA, ARIMA) are built on the assumption of stationarity. If the series is non-stationary, parameter estimates may be unreliable and forecasts may be misleading.

Non-stationary series often exhibit:

  • Trend: systematic increase or decrease in mean

  • Seasonality: periodic fluctuations

  • Heteroscedasticity: changing variance over time


Augmented Dickey-Fuller (ADF) Test

The ADF test checks for a unit root, which indicates non-stationarity.

ADF Test Regression

ΔYt=α+βt+γYt1+i=1pδiΔYti+εt\Delta Y_t = \alpha + \beta t + \gamma Y_{t-1} + \sum_{i=1}^{p} \delta_i \Delta Y_{t-i} + \varepsilon_t

Here,

  • ΔYt\Delta Y_t=First difference of Y at time t
  • γ\gamma=Coefficient on lagged level (key parameter)
  • α\alpha=Constant (intercept)
  • βt\beta t=Time trend
  • pp=Number of lagged difference terms

| Hypothesis | Meaning |

|-----------|---------|

| H0H_0: γ=0\gamma = 0 | Unit root present -> non-stationary |

| H1H_1: γ<0\gamma < 0 | No unit root -> stationary |

Interpreting ADF

If p-value < 0.05, reject H0H_0 and conclude the series is stationary. If p-value > 0.05, fail to reject — the series may be non-stationary.


KPSS Test

The KPSS test has opposite hypotheses from the ADF test.

KPSS Test

Yt=ξt+ut,ξt=ξt1+εtY_t = \xi_t + u_t, \quad \xi_t = \xi_{t-1} + \varepsilon_t

Here,

  • ξt\xi_t=Random walk component
  • utu_t=Stationary error
  • εt\varepsilon_t=White noise innovation

| Hypothesis | Meaning |

|-----------|---------|

| H0H_0: Series is stationary | Trend-stationary |

| H1H_1: Series is non-stationary | Unit root present |

Using Both Tests

Use ADF and KPSS together. If ADF rejects H0H_0 (stationary) and KPSS fails to reject H0H_0 (stationary), the series is likely stationary. If both reject, the series is borderline.


Transformations for Stationarity

Differencing

First Differencing

ΔYt=YtYt1\Delta Y_t = Y_t - Y_{t-1}

Here,

  • ΔYt\Delta Y_t=First difference — removes linear trend
  • YtY_t=Value at time t

For seasonal data, use seasonal differencing:

Seasonal Differencing

ΔsYt=YtYts\Delta_s Y_t = Y_t - Y_{t-s}

Here,

  • ss=Seasonal period (e.g., 12 for monthly data)

Log Transformation

Stabilizes variance when it increases with the level of the series.

Log Transformation

Zt=ln(Yt)Z_t = \ln(Y_t)

Here,

  • YtY_t=Original positive time series
  • ZtZ_t=Transformed series with stabilized variance

Box-Cox Transformation

A family of power transformations that includes log as a special case.

Box-Cox Transformation

Yt(λ)={Ytλ1λλ0 ln(Yt)λ=0Y_t^{(\lambda)} = \begin{cases} \frac{Y_t^\lambda - 1}{\lambda} & \lambda \neq 0 \ \ln(Y_t) & \lambda = 0 \end{cases}

Here,

  • λ\lambda=Transformation parameter (estimated from data)

Python Implementation


import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

from statsmodels.tsa.stattools import adfuller, kpss



np.random.seed(42)



# Non-stationary series (random walk + trend)

t = np.arange(200)

Y = np.cumsum(np.random.randn(200)) + 0.02 * t



# ADF test

adf_result = adfuller(Y, autolag='AIC')

print(f"ADF Statistic: {adf_result[0]:.3f}")

print(f"p-value: {adf_result[1]:.4f}")



# KPSS test

kpss_result = kpss(Y, regression='ct', nlags='auto')

print(f"KPSS Statistic: {kpss_result[0]:.3f}")

print(f"p-value: {kpss_result[1]:.4f}")



# Apply differencing

Y_diff = np.diff(Y)



adf_diff = adfuller(Y_diff, autolag='AIC')

print(f"\nAfter differencing:")

print(f"ADF p-value: {adf_diff[1]:.4f}")

Worked Example

Example: Testing Stationarity

A monthly airline passenger series shows increasing variance and trend.

  1. Log transform to stabilize variance: Zt=ln(Yt)Z_t = \ln(Y_t)

  2. ADF test on ZtZ_t: p-value = 0.85 -> non-stationary

  3. First difference: ΔZt=ZtZt1\Delta Z_t = Z_t - Z_{t-1}

  4. ADF test on ΔZt\Delta Z_t: p-value = 0.001 -> stationary

  5. Seasonal difference (s=12): Δ12Zt\Delta_{12} Z_t

  6. ADF test on Δ12Zt\Delta_{12} Z_t: p-value = 0.000 -> stationary

The series requires both seasonal and first differencing to achieve stationarity.


Key Takeaways

Summary: Stationarity

  • A stationary time series has constant mean, variance, and autocovariance over time

  • The ADF test checks for unit roots (H0H_0: non-stationary)

  • The KPSS test has opposite hypotheses (H0H_0: stationary)

  • Use both tests together for more reliable conclusions

  • Differencing removes trends; log transformation stabilizes variance

  • Most ARIMA models require a stationary input series


Related Topics

Premium Content

Stationarity in Time Series — Tests and Transformations

Unlock this lesson and 900+ advanced tutorials with a Premium plan.

🎯End-to-end Projects
💼Interview Prep
📜Certificates
🤝Community Access

Already a member? Log in

Need Expert Statistics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement