Implementing and Interpreting the ADF Test
Instruction: Explain how you would implement the Augmented Dickey-Fuller (ADF) test in a time series analysis. Discuss what the results can tell us about the time series.
Updated
Example Answer
The Augmented Dickey–Fuller test has a unit-root null hypothesis. A small p-value gives evidence against that null within the chosen test specification; it does not prove that every kind of nonstationarity is absent. I would choose the intercept or deterministic-trend specification based on the series and the question, then select enough lagged differences to address serial correlation.
I would inspect missing values and structural breaks before running it, and report the statistic, p-value, lag count, and deterministic terms. Failing to reject does not prove a unit root, especially with a short series or low power. I would combine the result with plots, domain knowledge, and complementary diagnostics such as KPSS, whose null is different. Any differencing or detrending should serve the forecasting model rather than be repeated mechanically until a test passes.
Worked example
Synthetic stationary AR(1) example; requires NumPy and targets the statsmodels 0.15 API. It is a demonstration, not a guarantee about a real series.
import numpy as np
from statsmodels.tsa.stattools import adfuller
rng = np.random.default_rng(7)
x = np.zeros(600)
for t in range(1, len(x)):
x[t] = 0.6 * x[t - 1] + rng.normal()
result = adfuller(x[100:], regression="c", autolag="AIC", result_object=True)
print({"statistic": result.statistic, "p_value": result.pvalue, "lags": result.lags})
Why this works
It provides a reproducible invocation while keeping the test’s hypothesis and model-dependent interpretation clear.