Distinguish deterministic trends (trend-stationary) from stochastic trends (difference-stationary unit roots).
Formulate the Augmented Dickey-Fuller (ADF) and KPSS tests, including their opposite null hypotheses and deterministic term specifications.
Avoid specification mismatches between feasts::unitroot_kpss() and tseries::adf.test() by aligning urca::ur.df() and urca::ur.kpss() explicitly.
1. Deterministic vs. Stochastic Trends
Visual upward drift in a time plot can arise from two fundamentally different data-generating mechanisms:
Deterministic trend (trend-stationary):\[y_t = \alpha + \beta t + \varepsilon_t, \qquad \varepsilon_t \sim \text{stationary}.\] Here shocks \(\varepsilon_t\) are transitory: the series always reverts toward the deterministic line \(\alpha + \beta t\), and forecast variance remains bounded. Removing the fitted trend yields a stationary residual.
Stochastic trend (difference-stationary / unit root):\[y_t = \delta + y_{t-1} + \varepsilon_t \implies y_t = y_0 + \delta t + \sum_{j=1}^{t} \varepsilon_j.\] Here the AR(1) root lies on the unit circle (\(\phi = 1\)). Every shock \(\varepsilon_j\) persists permanently in the level of \(y_t\), and variance grows linearly as \(t\sigma^2\). Linear detrending fails to remove the accumulated random walk \(\sum \varepsilon_j\); first differencing\(\nabla y_t = \delta + \varepsilon_t\) is required.
2. ADF and KPSS Tests: Specification Alignment Matters
Formal testing pairs two complementary procedures with reversed null hypotheses:
Augmented Dickey-Fuller (ADF) Test
Subtracting \(y_{t-1}\) from an \(\text{AR}(p)\) model yields the ADF regression:
where \(\gamma = \phi - 1\) and the \(k\) lagged differences \(\Delta y_{t-i}\) absorb residual serial correlation so \(\varepsilon_t\) approximates white noise. We test:
Under \(H_0\), the \(t\)-ratio \(\tau = \hat{\gamma}/\text{SE}(\hat{\gamma})\) does not follow a Student-\(t\) distribution; it follows a left-skewed Dickey-Fuller distribution whose critical values depend strictly on which deterministic terms appear in the regression:
type = "none": no intercept or trend (\(\alpha = \beta = 0\), tests zero-mean stationarity).
type = "drift": intercept only (\(\beta = 0\), tests level stationarity).
type = "trend": intercept and linear trend (tests trend stationarity).
KPSS Test
The Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test reverses the burden of proof by decomposing \(y_t = \xi t + r_t + \varepsilon_t\) where \(r_t = r_{t-1} + u_t\) is a random walk with variance \(\sigma_u^2\):
The specification type = "mu" (\(\xi = 0\)) tests level stationarity, while type = "tau" tests trend stationarity.
Critical Default-Mismatch Trap
A widespread mistake in R scripts is pairing tseries::adf.test() with feasts::unitroot_kpss() using default arguments:
tseries::adf.test() always includes a linear trend (type = "trend").
feasts::unitroot_kpss() wraps urca::ur.kpss() with default type = "mu" (level stationarity, no linear trend!).
For a genuinely trend-stationary series, adf.test() rejects \(H_0\) (detecting trend stationarity) while default unitroot_kpss() also rejects \(H_0\) (because a trending mean is not level-stationary!). Always match deterministic terms explicitly using urca::ur.df() paired with urca::ur.kpss():
Level stationarity check:ur.df(..., type = "drift") paired with ur.kpss(..., type = "mu").
Trend stationarity check:ur.df(..., type = "trend") paired with ur.kpss(..., type = "tau").
ADF (H0: unit root)
KPSS (H0: stationary)
Confirmatory Conclusion
Reject \(H_0\)
Fail to reject \(H_0\)
Strong evidence of stationarity (level or trend, matching spec)
Fail to reject \(H_0\)
Reject \(H_0\)
Strong evidence of a unit root (differencing required)
Fail to reject \(H_0\)
Fail to reject \(H_0\)
Insufficient power / inconclusive (short sample or near-unit root)
Reject \(H_0\)
Reject \(H_0\)
Conflict: check fractional integration, structural break, or spec mismatch
3. Worked Testing Suite Across Four Benchmarks
Let us construct a clean helper wrapping aligned urca::ur.df() and urca::ur.kpss() plus feasts::unitroot_ndiffs(), and evaluate four series: (1) simulated stationary AR(1) (\(\phi = 0.7\)), (2) simulated random walk with drift (\(\delta = 0.15\)), (3) Alphabet trading-day log(Close) and log returns (data/google.csv), and (4) annual Nile River flow (datasets::Nile).
Aligned ADF (ur.df) and KPSS (ur.kpss) unit-root diagnostics at the 5% significance level.
Series
Spec
ADF Stat
ADF 5% CV
ADF Reject
KPSS Stat
KPSS 5% CV
KPSS Reject
ndiffs
Sim AR(1) (φ = 0.7)
drift / mu
-6.612
-2.88
TRUE
0.210
0.463
FALSE
0
Sim RW + Drift
trend / tau
-1.879
-3.43
FALSE
0.461
0.146
TRUE
1
GOOG log(Close)
trend / tau
-1.822
-3.41
FALSE
2.470
0.146
TRUE
1
GOOG Log Returns
drift / mu
-26.154
-2.86
TRUE
0.111
0.463
FALSE
0
Nile Annual Flow
drift / mu
-4.049
-2.89
TRUE
0.965
0.463
TRUE
1
Look closely at the Nile River row: both ADF (drift) and KPSS (mu) reject their respective null hypotheses! Moreover, tseries::adf.test(nile_x) (which adds an unnecessary linear trend) fails to reject (\(p \approx 0.064\)), obscuring the signal further. Plotting Nile alongside Alphabet log returns immediately explains the conflict: the Nile experienced an abrupt mean drop near 1898 (the Aswan Low Dam structural break, studied in Module 6), which violates level stationarity without being a pure unit root.
Figure 1: Annual Nile River flow showing an abrupt structural mean shift around 1898 (left) alongside stationary Alphabet daily log returns (right).
Practice Exercises
Exercise 1: Confirmatory Quadrant Check on U.S. GDP
Using global_economy for the United States, apply aligned ADF and KPSS tests (under both "drift"/"mu" and "trend"/"tau") and unitroot_ndiffs() to log(GDP) and its first difference difference(log(GDP)). Interpret the confirmatory table.
Solution
For log(GDP), ADF fails to reject the unit root while KPSS strongly rejects both level and trend stationarity, confirming a stochastic trend (ndiffs = 1 or 2 under KPSS level checks). After first differencing, annual log GDP growth passes level-stationarity checks cleanly under aligned "drift"/"mu" tests.
us_gdp <- global_economy |>filter(Country =="United States") |>drop_na(GDP) |>mutate(log_gdp =log(GDP), dlog_gdp =difference(log_gdp))bind_rows(run_ur_pair(us_gdp$log_gdp, "log(US GDP)", "drift", "mu"),run_ur_pair(us_gdp$log_gdp, "log(US GDP)", "trend", "tau"),run_ur_pair(us_gdp$dlog_gdp, "Δ log(US GDP)", "drift", "mu")) |>fmt_tbl(digits =3, caption ="Confirmatory ADF and KPSS results for U.S. log GDP and annual log growth.")
Confirmatory ADF and KPSS results for U.S. log GDP and annual log growth.
Series
Spec
ADF Stat
ADF 5% CV
ADF Reject
KPSS Stat
KPSS 5% CV
KPSS Reject
ndiffs
log(US GDP)
drift / mu
-3.573
-2.89
TRUE
1.520
0.463
TRUE
2
log(US GDP)
trend / tau
0.219
-3.45
FALSE
0.379
0.146
TRUE
2
Δ log(US GDP)
drift / mu
-2.267
-2.89
FALSE
0.963
0.463
TRUE
1
Exercise 2: Seasonal and Regular Unit-Root Checks on AirPassengers
Apply unitroot_nsdiffs() (with .period = 12), unitroot_ndiffs(), and aligned ADF/KPSS tests to log(AirPassengers), its seasonal difference \(\nabla_{12} \ln y_t\), and its doubly differenced form \(\nabla \nabla_{12} \ln y_t\).
Solution
unitroot_nsdiffs() flags 1 seasonal difference on log(AirPassengers). Once seasonally differenced, unitroot_ndiffs() reports 0, and adding a regular first difference yields clear agreement between ADF (rejecting unit root) and KPSS (failing to reject level stationarity).
log_ap <-log(as.numeric(AirPassengers))sdiff_ap <-diff(log_ap, lag =12)both_ap <-diff(sdiff_ap, lag =1)tibble(Check =c("nsdiffs on log(AP)", "ndiffs on ∇_12 log(AP)", "ndiffs on ∇∇_12 log(AP)"),Order =c(unname(unitroot_nsdiffs(log_ap, .period =12)),unname(unitroot_ndiffs(sdiff_ap)),unname(unitroot_ndiffs(both_ap)) )) |>fmt_tbl(caption ="Automated seasonal and regular differencing orders for log(AirPassengers).")
Automated seasonal and regular differencing orders for log(AirPassengers).
Check
Order
nsdiffs on log(AP)
1
ndiffs on ∇_12 log(AP)
0
ndiffs on ∇∇_12 log(AP)
0
bind_rows(run_ur_pair(log_ap, "log(AP)", "trend", "tau"),run_ur_pair(sdiff_ap, "∇_12 log(AP)", "drift", "mu"),run_ur_pair(both_ap, "∇∇_12 log(AP)", "drift", "mu")) |>fmt_tbl(digits =3, caption ="Aligned ADF and KPSS checks across differencing stages of log(AirPassengers).")
Aligned ADF and KPSS checks across differencing stages of log(AirPassengers).
Series
Spec
ADF Stat
ADF 5% CV
ADF Reject
KPSS Stat
KPSS 5% CV
KPSS Reject
ndiffs
log(AP)
trend / tau
-6.995
-3.43
TRUE
0.113
0.146
FALSE
1
∇_12 log(AP)
drift / mu
-3.342
-2.88
TRUE
0.368
0.463
FALSE
0
∇∇_12 log(AP)
drift / mu
-9.304
-2.88
TRUE
0.084
0.463
FALSE
0
Key Takeaways
Trend-stationary series revert to a deterministic line after shocks, whereas unit-root series accumulate shocks permanently and require differencing.
ADF tests \(H_0\): unit root against \(H_1\): stationarity; KPSS reverses the hypotheses (\(H_0\): stationary against \(H_1\): unit root).
Always align deterministic specifications (ur.df(..., type = "drift") with ur.kpss(..., type = "mu"), or "trend" with "tau") rather than mixing default tseries::adf.test() and feasts::unitroot_kpss().
When ADF and KPSS both reject, inspect the time plot for structural breaks or regime shifts (as in datasets::Nile).