Skip to content

DPredict · Guide test 200

KPSS test

Tests level or trend stationarity as the null, unlike unit root null tests such as ADF.

Runs in CodeSplashPython example validatedR example validated Corrected in edition 2

Do it in CodeSplash

In the app, set it up in Analyze with this method:

  • Unit-root and stationarity tests — Does the series wander like a random walk (a unit root), or return to a mean or trend — and how many differences make it stationary?

In Unit-root and stationarity tests, choose Test = KPSS.

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · KPSS test

60
0.000
0.30

Each error carries φ × the previous one; 1 is a random walk.

0.0
0.050

Your data

Simulated with a known ρ

If H₀ were true

η = 0.09
  1. The reference: how η varies across samples when H₀ is true, KPSS η of n = 60 stationary values (Monte Carlo null: 1,999 samples simulated under H₀ (seed 20261107)).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .707).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

η=n−2∑tSt2λ^2,St=∑s≤t(ys−yˉ)\eta = \dfrac{n^{-2}\sum_{t} S_t^2}{\hat\lambda^2},\qquad S_t = \sum_{s \le t}(y_s - \bar y)

With your numbers

η=0.09,ℓ=3, n=60\eta = 0.09,\qquad \ell = 3,\ n = 60
StS_t
partial sums of the demeaned series
λ^2\hat\lambda^2
long-run variance with ℓ Bartlett lags

The verdict

η = 0.093, p = .707

p > α = .050: compatible with H₀

The roles are reversed: stationarity is H0. Pair it with a unit-root test; rejecting both suggests a break or long memory.

Statistic
0.093
p-value
0.7065
KPSS test on 60 (x, y) pairs: η = 0.093, p = .707. The p-value is above α = .050, so the data are compatible with H0.

KPSS test on 60 (x, y) pairs: η = 0.093, p = .707. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: level or trend stationarity; H1: a stochastic unit-root component.

Assumptions

A regularly ordered time series with a specified deterministic component (none, intercept, or trend); innovations satisfy the selected unit-root test’s weak-dependence/moment conditions. Lag/bandwidth choices and breaks affect calibration.

Formula

KPSS=∑t=1TSt2T2ω^2St=∑s=1te^s\begin{gathered}KPSS=\frac{\sum_{t=1}^{T}S_t^2}{T^2\widehat\omega^2}\\[5pt] S_t=\sum_{s=1}^{t}\widehat e_s\end{gathered}

Parameters and notation

ê are residuals after fitting an intercept or intercept+trend; ω̂² is their HAC long-run variance.

Structure of the method

Remove an intercept or intercept-plus-trend, accumulate the resulting residuals over time, and compare the sum of squared cumulative residuals with a long-run variance estimate. The null is stationarity about the specified deterministic component, the reverse direction of ADF/PP's unit-root null. Its critical values are correspondingly different.

Estimated and nuisance parameters

Deterministic coefficients, residuals, and a HAC long-run variance are estimated. The cumulative residual path is a derived stochastic process, not a fitted state sequence from a neural or hidden-state model. Long-run variance captures allowed weak stationary dependence under the null.

Settings and design choices

Choose level versus trend stationarity, kernel/bandwidth or automatic rule, and missing-data treatment. The displayed Python 'legacy' and R 'short' options are implementation-specific bandwidth rules and should not be assumed numerically identical; set/report actual truncation lags for a controlled comparison.

Fitting and adaptation

Fit the deterministic component and long-run variance on the defined sample. A valid null bootstrap must preserve stationary dependence and repeat these estimates. Repeatedly changing bandwidth until the stationarity null survives is invalid tuning. If detrending or structural-break adjustment is revised, document the new null and recalibrate accordingly.

Sensitivity and robustness

Too-small bandwidths may understate persistent stationary variation, while large bandwidths can reduce power. Breaks, long memory, short series, and strong persistence complicate interpretation. ADF and KPSS may both reject because neither simple model is adequate or both fail through low information; do not force agreement by selecting favorable settings.

How to use and calibrate

Reject for large values using KPSS-specific critical values; state level/trend and bandwidth.

Example application

Complement an ADF analysis with a test whose null is stationarity.

Interpretation and pitfalls

Watch out

ADF and KPSS can both reject or both fail to reject. Breaks and bandwidth choices strongly affect results.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
  • Rewritten in the review: assumptions.
  • Assumptionssearch.r-project.org

    The inherited generic wording referred to a selected unit-root test and allowed a no-deterministic-term option; this entry instead has a stationarity null with level/trend variants.

    Corrected text

    A regularly ordered series that is level-stationary or trend-stationary under the specified null; the stationary disturbance component satisfies the weak-dependence and moment conditions needed for consistent long-run variance estimation. Specify intercept-only versus intercept-plus-trend detrending and the HAC bandwidth/kernel. Structural breaks and long memory require additional care.

Python and R

Read the unit-root/stationarity statistic and its nonstandard critical values, not the auxiliary regression coefficient’s ordinary t p-value. Deterministic terms, bandwidth and lag selection must match before comparing implementations.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy, statsmodels

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x=np.cumsum(rng.normal(size=160))
from statsmodels.tsa.stattools import kpss
print(kpss(x,regression="c",nlags="legacy"))
Output
(np.float64(0.4566709583841167), np.float64(0.05272803517926005), 14, {'10%': 0.347, '5%': 0.463, '2.5%': 0.574, '1%': 0.739})
R

Validated — Executed successfully in the validation environment · needs urca

set.seed(2026)
x<-cumsum(rnorm(160))
library(urca)
print(summary(ur.kpss(x,type="mu",lags="short")))
Output
####################### 
# KPSS Unit Root Test # 
####################### 

Test is of type: mu with 4 lags. 

Value of test-statistic is: 0.4688 

Critical value for a significance level of: 
                10pct  5pct 2.5pct  1pct
critical values 0.347 0.463  0.574 0.739

Sources

Statistics guide v4 (historical):
Python: Executed successfully in the validation environment · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Unavailable local dependencies: statsmodels. Python: Not run in the reference's review: Unavailable local dependencies: statsmodels. No installation attempted. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 200, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT200.