Stationarity and unit roots
See why a wandering series breaks ordinary regression, tell a unit root from a stationary series, and run the Dickey–Fuller test with its unusual critical values.
What runs in CodeSplash
- STAT196Dickey–Fuller test Runs in CodeSplash
- Unit-root and stationarity tests Verified in Python and R
You will be able to
- Define stationarity, and tell a unit root from a stationary process and a trend-stationary one
- Explain spurious regression and how differencing helps
- Run and read a Dickey–Fuller test, including its non-standard critical values
Read first
What stationary means
ReadA series is stationaryStationarityA series whose mean, variance and autocorrelation do not change over time. when its behavior doesn't depend on when you look: same mean, same variance, and autocorrelations that depend only on the gap between times.
A stationary series returns to its level after a shock. A unit rootUnit rootA series whose shocks never fade, like a random walk; it is non-stationary until differenced. series doesn't:
This random walk adds up its shocks forever. Its variance grows with time, so "the average level" has no fixed meaning.
Unrelated series that look related
ExploreDExplorable · Unit roots and spurious regression
Why do two unrelated trending series look strongly related?
How often does this regression find a "significant" link between independent series?
φ = 1 is a random walk, which never returns to a mean.
Commit your prediction above to see the result
Make your prediction to see the result.
These two series are independent. Keep Persistence φ at 1, and read Spurious rejections. Then:
- Lower φ to 0.5.
- Back at φ = 1, raise Length.
- Turn on Regress the differences.
Which of these fixes the problem, and which makes it worse?
Predict what more data does
PredictPredict first
Two independent random walks are regressed on each other. What happens to the rate of false "significant" links as the series get longer?
Reveal
It gets worse. The t statistic grows with the length of the series even with no real relationship (Granger & Newbold, 1974; Phillips, 1986). This is spurious regressionSpurious regressionA regression between unrelated trending series that looks strong, because both wander.. Check for unit roots before you regress one series on another.
Differencing
ReadIf has one unit root, its change is stationary. The number of differencesDifferencingReplacing values with period-to-period changes to remove trends (or seasonal differences for seasonality). needed is called , the "I" in ARIMA.
A series with a deterministic trend is different. It's stationary around a line, and shocks fade away. Differencing it adds an unnecessary moving-average pattern; removing the trend is the better route. So you need to know which case you have.
The Dickey–Fuller regression
ReadSubtract from both sides of an AR(1):
A unit root means , or . Test against using the t ratio on . That ratio is called .
Note the direction: the null says "unit root". Rejecting supports stationarity.
Compare the critical values
PredictPredict first
Under a unit root, doesn't follow a t distribution, since isn't stationary under . What 5% critical value would you expect, with a constant in the model?
Reveal
About : the exact value here is −2.87. That's much further out than a one-sided t's . Using the t table would reject far too often. CodeSplash uses MacKinnon's response surfaces.
Run it
In the appA simulated random walk with 240 values:
Dickey–Fuller τ = -0.55, p = .883
- Dickey–Fuller τ
- −0.5454
- p
- 0.8829
- Recommended d
- 1
Plots
View data
| month | random_walk |
|---|---|
| 946,684,800,000 | 1.747 |
| 949,363,200,000 | 1.911 |
| 951,868,800,000 | 1.562 |
| 954,547,200,000 | 1.640 |
| 957,139,200,000 | 0.3355 |
| 959,817,600,000 | 0.8966 |
| 962,409,600,000 | 1.892 |
| 965,088,000,000 | 0.3088 |
| 967,766,400,000 | −0.0293 |
| 970,358,400,000 | 0.6194 |
| 973,036,800,000 | −0.0302 |
| 975,628,800,000 | −0.3341 |
| 978,307,200,000 | −0.6142 |
| 980,985,600,000 | −0.2019 |
| 983,404,800,000 | −1.310 |
| 986,083,200,000 | −0.5427 |
| 988,675,200,000 | −0.1884 |
| 991,353,600,000 | −0.6634 |
| 993,945,600,000 | −0.6314 |
| 996,624,000,000 | −0.2814 |
| 999,302,400,000 | 0.4781 |
| 1,001,894,400,000 | 0.9833 |
| 1,004,572,800,000 | 0.4581 |
| 1,007,164,800,000 | 0.2193 |
| 1,009,843,200,000 | 0.7159 |
| 1,012,521,600,000 | −1.047 |
| 1,014,940,800,000 | −0.5611 |
| 1,017,619,200,000 | 0.2581 |
| 1,020,211,200,000 | −0.0412 |
| 1,022,889,600,000 | −0.4028 |
| 1,025,481,600,000 | 0.3619 |
| 1,028,160,000,000 | −0.3838 |
| 1,030,838,400,000 | −1.738 |
| 1,033,430,400,000 | −3.019 |
| 1,036,108,800,000 | −3.749 |
| 1,038,700,800,000 | −1.812 |
| 1,041,379,200,000 | −2.248 |
| 1,044,057,600,000 | −2.045 |
| 1,046,476,800,000 | −1.907 |
| 1,049,155,200,000 | −3.223 |
| 1,051,747,200,000 | −3.070 |
| 1,054,425,600,000 | −1.377 |
| 1,057,017,600,000 | −2.609 |
| 1,059,696,000,000 | −4.339 |
| 1,062,374,400,000 | −2.526 |
| 1,064,966,400,000 | −1.019 |
| 1,067,644,800,000 | −0.8569 |
| 1,070,236,800,000 | −1.015 |
| 1,072,915,200,000 | −1.604 |
| 1,075,593,600,000 | −2.182 |
| 1,078,099,200,000 | −1.386 |
| 1,080,777,600,000 | −0.7097 |
| 1,083,369,600,000 | −0.9379 |
| 1,086,048,000,000 | −0.6630 |
| 1,088,640,000,000 | 0.0114 |
| 1,091,318,400,000 | 0.3179 |
| 1,093,996,800,000 | 0.2853 |
| 1,096,588,800,000 | 0.1063 |
| 1,099,267,200,000 | 0.6279 |
| 1,101,859,200,000 | 0.8456 |
First 60 of 240 rows.
View data
| random_walk |
|---|
| 1.747 |
| 1.911 |
| 1.562 |
| 1.640 |
| 0.3355 |
| 0.8966 |
| 1.892 |
| 0.3088 |
| −0.0293 |
| 0.6194 |
| −0.0302 |
| −0.3341 |
| −0.6142 |
| −0.2019 |
| −1.310 |
| −0.5427 |
| −0.1884 |
| −0.6634 |
| −0.6314 |
| −0.2814 |
| 0.4781 |
| 0.9833 |
| 0.4581 |
| 0.2193 |
| 0.7159 |
| −1.047 |
| −0.5611 |
| 0.2581 |
| −0.0412 |
| −0.4028 |
| 0.3619 |
| −0.3838 |
| −1.738 |
| −3.019 |
| −3.749 |
| −1.812 |
| −2.248 |
| −2.045 |
| −1.907 |
| −3.223 |
| −3.070 |
| −1.377 |
| −2.609 |
| −4.339 |
| −2.526 |
| −1.019 |
| −0.8569 |
| −1.015 |
| −1.604 |
| −2.182 |
| −1.386 |
| −0.7097 |
| −0.9379 |
| −0.6630 |
| 0.0114 |
| 0.3179 |
| 0.2853 |
| 0.1063 |
| 0.6279 |
| 0.8456 |
First 60 of 240 rows.
Tests
| Test | H₀ | Statistic | p | Lags / bandwidth | 5 % critical value | At α = .05 | |
|---|---|---|---|---|---|---|---|
| Dickey–Fuller τ | unit root | −0.5454 | .883 | 0 | −2.874 | unit root not rejected |
- Unit-root tests have low power near a unit root: read them with KPSS (the battery does) and a plot of the series.
- p-values come from nonstandard distributions (MacKinnon response surfaces, KPSS / ERS / Zivot–Andrews tables); a p shown at a table bound (≤ .01 or ≥ .10) means the statistic is beyond the tabulated range.
The exact R script · R R version 4.5.1 (2025-06-13)
# Unit-root and stationarity tests
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method ts.unitroot 1.1.1 · spec 77274285cd232314
# Dataset: ts_truth (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ts_truth.parquet", col_select = c("random_walk", "month")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("random_walk", "month")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("random_walk", "month")) # infinite values stop the run (registry/errors.yaml)
# %% Series
VALUE <- "random_walk"
TIME <- "month"
TEMPORAL <- TRUE
TEST <- "df"
DET <- "c"
LAG_RULE <- "aic"
LAGS <- NULL
BW <- "auto"
ZA_MODEL <- "c"
TRIM <- 0.15
REPS <- 999
SEED <- 42
s <- cs_ts_ordered(df, VALUE, TIME, TEMPORAL)
x <- s$x
labels <- s$labels
n <- length(x)
if (s$dups > 0) warnings <- c(warnings, sprintf("%d repeated time values: the tests assume one observation per evenly spaced time.", s$dups))
det <- DET
if (DET == "n" && !(TEST %in% c("adf", "df", "pp"))) {
det <- "c"
warnings <- c(warnings, "No deterministic terms is only defined for ADF, DF and PP; a constant was used.")
}
det_kpss <- if (det == "ct") "ct" else "c"
# The test regressions need at least 2 x (deterministic terms + 1) observations (as statsmodels' adfuller), and
# never fewer than 4, and a series that varies (registry/errors.yaml; the same checks in Python).
cs_check_rows(n, max(4, 2 * (c(n = 0, c = 1, ct = 2)[[det]] + 1)), "A unit-root test")
cs_check_not_constant(x, VALUE)
bw_kpss <- BW
bw <- if (BW == "auto") "short" else BW
LABELS <- list(adf = "Augmented Dickey–Fuller τ", df = "Dickey–Fuller τ", pp = "Phillips–Perron Z(τ)", dfgls = "DF-GLS τ",
za = "Zivot–Andrews t", sp = "Schmidt–Phillips Z(τ)", kpss = "KPSS η", battery = "Battery")
pf <- function(r) if (!is.null(r$bound) && nzchar(r$bound)) sprintf("p %s %.2f", r$bound, r$p) else cs_fmt_p(r$p)
run_test <- function(test) {
switch(test,
adf = cs_ts_adf(x, det, lags = LAGS, autolag = LAG_RULE),
df = cs_ts_adf(x, det, lags = 0),
pp = cs_ts_pp(x, det, bw),
dfgls = cs_ts_dfgls(x, det_kpss, lags = LAGS, autolag = LAG_RULE),
za = cs_ts_zivot_andrews(x, ZA_MODEL, TRIM, lags = LAGS, autolag = LAG_RULE),
sp = cs_ts_schmidt_phillips(x, bw, REPS, SEED),
cs_ts_kpss(x, det_kpss, bw_kpss))
}
# %% Tests
rows <- list()
values <- list(n_obs = n, test = TEST, test_label = LABELS[[TEST]])
battery <- if (TEST == "battery") c("adf", "pp", "dfgls", "kpss") else TEST
res <- list()
for (t in battery) {
r <- run_test(t)
res[[t]] <- r
crit <- if (is.null(r$crit)) list(NULL, NULL, NULL) else as.list(r$crit)
if (t == "kpss") crit <- list(r$crit[4], r$crit[2], r$crit[1])
reject <- r$p < 0.05
verdict <- if (t == "kpss") (if (reject) "reject stationarity" else "stationary") else (if (reject) "reject the unit root" else "unit root not rejected")
rows[[length(rows) + 1]] <- list(test = LABELS[[t]], h0 = if (t == "kpss") "stationary" else "unit root", statistic = r$stat, p = r$p,
p_note = if (is.null(r$bound)) "" else r$bound, lags = r$lags, crit_5 = crit[[2]], verdict = verdict)
}
main <- res[[battery[1]]]
crit <- if (is.null(main$crit)) list(NULL, NULL, NULL) else as.list(main$crit)
if (battery[1] == "kpss") crit <- list(main$crit[4], main$crit[2], main$crit[1])
values["stat"] <- list(main$stat)
values["p"] <- list(main$p)
values["lags"] <- list(main$lags)
values["crit_1"] <- list(crit[[1]])
values["crit_5"] <- list(crit[[2]])
values["crit_10"] <- list(crit[[3]])
values$reject <- as.integer(main$p < 0.05)
if (TEST == "battery") {
for (t in battery) {
values[[paste0(t, "_stat")]] <- res[[t]]$stat
values[[paste0(t, "_p")]] <- res[[t]]$p
}
values$adf_lags <- res$adf$lags
}
if (TEST == "za") values$break_index <- main$break_index
if (TEST == "sp") values$reps <- REPS
rd <- cs_ts_recommend_d(x, if (det == "ct") "ct" else "c", lags = LAGS, autolag = LAG_RULE, bandwidth = bw_kpss, detail = TRUE) # same lag settings as the tests
values$d_recommended <- rd$d
if (!rd$agreed) warnings <- c(warnings, sprintf("ADF and KPSS never agreed on stationarity up to d = %d; the recommended d is a convention, not a finding.", rd$d))
# %% Result
summary <- if (TEST == "battery") {
sprintf("Unit-root battery for %s (%d observations): ADF τ = %.2f (%s), KPSS = %.3f (%s); recommended differences d = %d.",
VALUE, n, res$adf$stat, pf(res$adf), res$kpss$stat, pf(res$kpss), values$d_recommended)
} else {
sprintf("%s for %s: %.3f, %s — %s.", LABELS[[TEST]], VALUE, main$stat, pf(main), rows[[1]]$verdict)
}
if (TEST == "za") summary <- paste0(summary, sprintf(" Most likely break after %s.", labels[main$break_index + 1]))
notes <- list("Unit-root tests have low power near a unit root: read them with KPSS (the battery does) and a plot of the series.",
"p-values come from nonstandard distributions (MacKinnon response surfaces, KPSS / ERS / Zivot–Andrews tables); a p shown at a table bound (≤ .01 or ≥ .10) means the statistic is beyond the tabulated range.")
if (TEST == "sp") notes <- c(notes, sprintf("Schmidt–Phillips p from %d simulated random walks (seed %d; identical in Python and R).", REPS, SEED))
kind <- if (TEMPORAL) "temporal" else "numeric"
charts <- list(
cs_chart("series", "series-line", sprintf("%s over time", VALUE), list(x = cs_col(if (is.null(TIME)) "index" else TIME, labels, kind = kind), y = cs_col(VALUE, x)),
controls = if (TEST == "za") list(marker = main$break_index + 1) else NULL),
cs_chart("acf", "acf", sprintf("Autocorrelation of %s", VALUE), list(y = cs_col(VALUE, x))))
cs_publish(list(
method = "ts.unitroot",
methodVersion = "1.1.1",
title = "Unit-root and stationarity tests",
engine = cs_engine_info("stats", "nanoparquet"),
n = n,
summary = summary,
apa = paste(vapply(battery, function(t) sprintf("%s = %.2f, %s", LABELS[[t]], res[[t]]$stat, pf(res[[t]])), ""), collapse = "; "),
statistics = list(list(key = "stat", label = LABELS[[battery[1]]], value = main$stat), list(key = "p", label = "p", value = main$p),
list(key = "d", label = "Recommended d", value = values$d_recommended)),
tables = list(list(
key = "tests", title = "Tests",
columns = list(list(key = "test", label = "Test", type = "string"), list(key = "h0", label = "H₀", type = "string"),
list(key = "statistic", label = "Statistic", type = "number"), list(key = "p", label = "p", type = "pvalue"),
list(key = "p_note", label = "", type = "string"), list(key = "lags", label = "Lags / bandwidth", type = "integer"),
list(key = "crit_5", label = "5 % critical value", type = "number"), list(key = "verdict", label = "At α = .05", type = "string")),
rows = rows
)),
effectSizes = list(),
assumptions = list(),
warnings = warnings,
notes = notes,
charts = charts,
values = values
))
Dickey–Fuller τ = -0.55, p = .883
- Dickey–Fuller τ
- −0.5454
- p
- 0.8829
- Recommended d
- 1
To keep this page light, the plots are shown once, under the R tab.
Tests
| Test | H₀ | Statistic | p | Lags / bandwidth | 5 % critical value | At α = .05 | |
|---|---|---|---|---|---|---|---|
| Dickey–Fuller τ | unit root | −0.5454 | .883 | 0 | −2.874 | unit root not rejected |
- Unit-root tests have low power near a unit root: read them with KPSS (the battery does) and a plot of the series.
- p-values come from nonstandard distributions (MacKinnon response surfaces, KPSS / ERS / Zivot–Andrews tables); a p shown at a table bound (≤ .01 or ≥ .10) means the statistic is beyond the tabulated range.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Unit-root and stationarity tests
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method ts.unitroot 1.1.1 · spec 77274285cd232314
# Dataset: ts_truth (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.errors import check_not_constant
from codesplash.stats import ts
# %% Data
df = pd.read_parquet("tests/parity/fixtures/ts_truth.parquet", columns=["random_walk", "month"])
n_input = len(df)
df = df.dropna(subset=["random_walk", "month"]) # listwise deletion over the analysis columns
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["random_walk", "month"]) # infinite values stop the run (registry/errors.yaml)
# %% Series
VALUE = "random_walk"
TIME = "month"
TEMPORAL = True
TEST = "df"
DET = "c"
LAG_RULE = "aic"
LAGS = None
BW = "auto"
ZA_MODEL = "c"
TRIM = 0.15
REPS = 999
SEED = 42
s = ts.ordered(df, VALUE, TIME, TEMPORAL)
x, labels = s["x"], s["labels"]
n = len(x)
if s["dups"]:
warnings.append(f"{s['dups']} repeated time values: the tests assume one observation per evenly spaced time.")
det = DET
if DET == "n" and TEST not in ("adf", "df", "pp"):
det = "c"
warnings.append("No deterministic terms is only defined for ADF, DF and PP; a constant was used.")
det_kpss = "ct" if det == "ct" else "c"
# The test regressions need at least 2 × (deterministic terms + 1) observations (as statsmodels' adfuller), and
# never fewer than 4, and a series that varies (registry/errors.yaml; the same checks in R).
cs.check_rows(n, max(4, 2 * ({"n": 0, "c": 1, "ct": 2}[det] + 1)), "A unit-root test")
check_not_constant(x, VALUE)
bw_kpss = "auto" if BW == "auto" else BW
bw = "short" if BW == "auto" else BW
LABELS = {"adf": "Augmented Dickey–Fuller τ", "df": "Dickey–Fuller τ", "pp": "Phillips–Perron Z(τ)", "dfgls": "DF-GLS τ",
"za": "Zivot–Andrews t", "sp": "Schmidt–Phillips Z(τ)", "kpss": "KPSS η", "battery": "Battery"}
def pf(r):
"""p as text, with the table bound when the statistic is beyond the tabulated range."""
b = r.get("bound") or ""
return f"p {b} {r['p']:.2f}" if b else cs.fmt_p(r["p"])
def run(test):
if test == "adf":
return ts.adf(x, det, lags=LAGS, autolag=LAG_RULE)
if test == "df":
return ts.adf(x, det, lags=0)
if test == "pp":
return ts.pp(x, det, bw)
if test == "dfgls":
return ts.dfgls(x, det_kpss, lags=LAGS, autolag=LAG_RULE)
if test == "za":
return ts.zivot_andrews(x, ZA_MODEL, TRIM, lags=LAGS, autolag=LAG_RULE)
if test == "sp":
return ts.schmidt_phillips(x, bw, REPS, SEED)
return ts.kpss(x, det_kpss, bw_kpss)
# %% Tests
rows, values = [], {"n_obs": n, "test": TEST, "test_label": LABELS[TEST]}
battery = ["adf", "pp", "dfgls", "kpss"] if TEST == "battery" else [TEST]
res = {}
for t in battery:
r = run(t)
res[t] = r
crit = r.get("crit") or [None, None, None]
if t == "kpss":
crit = [crit[3], crit[1], crit[0]] # 1 %, 5 %, 10 %
reject = (r["p"] < 0.05)
rows.append({"test": LABELS[t], "h0": "stationary" if t == "kpss" else "unit root", "statistic": r["stat"], "p": r["p"],
"p_note": r.get("bound") or "", "lags": r.get("lags"), "crit_5": crit[1],
"verdict": ("reject stationarity" if reject else "stationary") if t == "kpss" else ("reject the unit root" if reject else "unit root not rejected")})
main = res[battery[0]]
crit = main.get("crit") or [None, None, None]
if battery[0] == "kpss":
crit = [crit[3], crit[1], crit[0]]
values.update({"stat": main["stat"], "p": main["p"], "lags": main.get("lags"), "crit_1": crit[0], "crit_5": crit[1], "crit_10": crit[2],
"reject": int(main["p"] < 0.05)})
if TEST == "battery":
for t in battery:
values[f"{t}_stat"] = res[t]["stat"]
values[f"{t}_p"] = res[t]["p"]
values["adf_lags"] = res["adf"]["lags"]
if TEST == "za":
values["break_index"] = main["break_index"]
if TEST == "sp":
values["reps"] = REPS
rd = ts.recommend_d(x, "ct" if det == "ct" else "c", lags=LAGS, autolag=LAG_RULE, bandwidth=bw_kpss, detail=True) # same lag settings as the tests
values["d_recommended"] = rd["d"]
if not rd["agreed"]:
warnings.append(f"ADF and KPSS never agreed on stationarity up to d = {rd['d']}; the recommended d is a convention, not a finding.")
# %% Result
if TEST == "battery":
summary = (f"Unit-root battery for {VALUE} ({n} observations): ADF τ = {res['adf']['stat']:.2f} ({pf(res['adf'])}), "
f"KPSS = {res['kpss']['stat']:.3f} ({pf(res['kpss'])}); recommended differences d = {values['d_recommended']}.")
else:
summary = f"{LABELS[TEST]} for {VALUE}: {main['stat']:.3f}, {pf(main)} — {rows[0]['verdict']}."
if TEST == "za":
summary += f" Most likely break after {labels[main['break_index']]}."
notes = ["Unit-root tests have low power near a unit root: read them with KPSS (the battery does) and a plot of the series.",
"p-values come from nonstandard distributions (MacKinnon response surfaces, KPSS / ERS / Zivot–Andrews tables); "
"a p shown at a table bound (≤ .01 or ≥ .10) means the statistic is beyond the tabulated range."]
if TEST == "sp":
notes.append(f"Schmidt–Phillips p from {REPS} simulated random walks (seed {SEED}; identical in Python and R).")
kind = "temporal" if TEMPORAL else "numeric"
charts = [cs.chart("series", "series-line", f"{VALUE} over time", {"x": cs.col(TIME or "index", labels, kind=kind), "y": cs.col(VALUE, x)},
controls={"marker": main["break_index"] + 1} if TEST == "za" else None),
cs.chart("acf", "acf", f"Autocorrelation of {VALUE}", {"y": cs.col(VALUE, x)})]
cs.publish({
"method": "ts.unitroot",
"methodVersion": "1.1.1",
"title": "Unit-root and stationarity tests",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": n,
"summary": summary,
"apa": "; ".join(f"{LABELS[t]} = {res[t]['stat']:.2f}, {pf(res[t])}" for t in battery),
"statistics": [{"key": "stat", "label": LABELS[battery[0]], "value": main["stat"]}, {"key": "p", "label": "p", "value": main["p"]},
{"key": "d", "label": "Recommended d", "value": values["d_recommended"]}],
"tables": [{
"key": "tests", "title": "Tests",
"columns": [{"key": "test", "label": "Test", "type": "string"}, {"key": "h0", "label": "H₀", "type": "string"},
{"key": "statistic", "label": "Statistic", "type": "number"}, {"key": "p", "label": "p", "type": "pvalue"},
{"key": "p_note", "label": "", "type": "string"}, {"key": "lags", "label": "Lags / bandwidth", "type": "integer"},
{"key": "crit_5", "label": "5 % critical value", "type": "number"}, {"key": "verdict", "label": "At α = .05", "type": "string"}],
"rows": rows,
}],
"effectSizes": [],
"assumptions": [],
"warnings": warnings,
"notes": notes,
"charts": charts,
"values": values,
})
= −0.55, p = .883. The data are compatible with a unit root. Against that, a stationary AR(1), −7.40, p < .001, is hard to reconcile with one.
Compare the ACF on the two cards. Which decays slowly?
With a trend
ReflectDeterministic terms changes the test. With a constant and trend, the alternative becomes "stationary around a line". The critical value moves further out, to −3.43. A simulated trend-stationary series gives = −8.47.
Look at the plot before you choose. Would you include a trend for a share price? For a growing customer count? What would a wrong choice cost?
Check your understanding
CheckpointCheck yourself
A Dickey–Fuller test gives p = 0.45. What does that mean?
Show the answer
Answer: b
A large p-value doesn't establish the null, and these tests have low power when is close to 1.
Check yourself
An AR(1) has . In the Dickey–Fuller regression, what is ?
Show the answer
Answer: -0.2
.
Check yourself
Why can't you use the ordinary t table for ?
Show the answer
Answer: c
The non-stationary regressor changes the limit distribution, and it depends on which deterministic terms you include.
Check yourself
A series rises along a straight line with stationary noise around it. Should you difference it?
Show the answer
Answer: b
Differencing suits a stochastic trend, and detrending suits a deterministic one. That's why the test's Deterministic terms matter.
Do it in CodeSplash
In the appChoose Series, Time and Test. Set Test to Dickey–Fuller (no lags) only when the errors have no autocorrelation; the next lesson covers lags. The Stationarity step of the Series lab runs this method too.
import pandas as pd
from statsmodels.tsa.stattools import adfuller
df = pd.read_csv("series.csv")
stat, p, lags, n, crit, _ = adfuller(df["value"], maxlag=0, regression="c", autolag=None)
print(stat, p, crit)# install.packages("urca")
df <- read.csv("series.csv")
summary(urca::ur.df(df$value, type = "drift", lags = 0))Recap
Recap- Stationary series return to their level; unit-root series add up their shocks.
- Regressing one unit-root series on another can look strong with no real link, and more data make it worse.
- The Dickey–Fuller null is "unit root", with its own critical values.
- A large p-value doesn't establish a unit root. The next lessons deal with low power.
Concepts in this lesson