ADFULLER

This function applies the Augmented Dickey-Fuller (ADF) test to evaluate whether a univariate time series contains a unit root.

The null hypothesis is that the series is non-stationary with a unit root, while the alternative is stationarity.

It returns the test statistic, p-value, lag usage, sample size, and critical values used for interpretation.

Excel Usage

=ADFULLER(x, maxlag, adf_regression, adf_autolag, store, regresults)
  • x (list[list], required): Time-series observations as a 2D range.
  • maxlag (int, optional, default: null): Maximum lag included in the test regression; null uses default rule.
  • adf_regression (str, optional, default: “c”): Deterministic terms included in the test regression (c, ct, ctt, or n).
  • adf_autolag (str, optional, default: “AIC”): Automatic lag-selection criterion (AIC, BIC, t-stat, or none).
  • store (bool, optional, default: false): Return result storage object in addition to scalar outputs.
  • regresults (bool, optional, default: false): Return full regression results when available.

Returns (list[list]): 2D key-value table summarizing ADF statistics and critical values.

Example 1: ADF test with default regression and autolag

Inputs:

x maxlag adf_regression adf_autolag store regresults
1 1.2 1.1 1.3 1.25 1.35 1.3 1.4 1.38 1.45 c AIC false false

Excel formula:

=ADFULLER({1,1.2,1.1,1.3,1.25,1.35,1.3,1.4,1.38,1.45}, , "c", "AIC", FALSE, FALSE)

Expected output:

Result
adf_stat -2.1749
p_value 0.21548
usedlag 3
nobs 6
critical_1% -5.35426
critical_5% -3.64624
critical_10% -2.9012
icbest -37.0965
Example 2: ADF test with constant and trend regression

Inputs:

x maxlag adf_regression adf_autolag store regresults
2 2.1 2.05 2.2 2.15 2.25 2.3 2.35 2.32 2.4 2 ct BIC false false

Excel formula:

=ADFULLER({2,2.1,2.05,2.2,2.15,2.25,2.3,2.35,2.32,2.4}, 2, "ct", "BIC", FALSE, FALSE)

Expected output:

Result
adf_stat -5.66528
p_value 0.0000107685
usedlag 0
nobs 9
critical_1% -5.49966
critical_5% -4.07211
critical_10% -3.4935
icbest -26.0036
Example 3: ADF test using fixed lag count

Inputs:

x maxlag adf_regression adf_autolag store regresults
3 2.9 3.1 3 3.2 3.1 3.3 3.25 3.35 3.3 1 c none false false

Excel formula:

=ADFULLER({3,2.9,3.1,3,3.2,3.1,3.3,3.25,3.35,3.3}, 1, "c", "none", FALSE, FALSE)

Expected output:

Result
adf_stat -1.29158
p_value 0.633016
usedlag 1
nobs 8
critical_1% -4.66519
critical_5% -3.36719
critical_10% -2.80296
Example 4: ADF test without deterministic terms

Inputs:

x maxlag adf_regression adf_autolag store regresults
1 0.95 1.02 0.98 1.01 0.99 1.03 1 1.04 1.01 1 n AIC false false

Excel formula:

=ADFULLER({1,0.95,1.02,0.98,1.01,0.99,1.03,1,1.04,1.01}, 1, "n", "AIC", FALSE, FALSE)

Expected output:

Result
adf_stat 2.85276
p_value 0.999591
usedlag 1
nobs 8
critical_1% -2.90189
critical_5% -1.96617
critical_10% -1.57649
icbest -46.7118

Python Code

import numpy as np
from statsmodels.tsa.stattools import adfuller as sm_adfuller

def adfuller(x, maxlag=None, adf_regression='c', adf_autolag='AIC', store=False, regresults=False):
    """
    Run the Augmented Dickey-Fuller unit-root test for stationarity diagnostics.

    See: https://www.statsmodels.org/stable/generated/statsmodels.tsa.stattools.adfuller.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        x (list[list]): Time-series observations as a 2D range.
        maxlag (int, optional): Maximum lag included in the test regression; null uses default rule. Default is None.
        adf_regression (str, optional): Deterministic terms included in the test regression (c, ct, ctt, or n). Valid options: Constant, Constant+Trend, Constant+Trend+Quadratic, None. Default is 'c'.
        adf_autolag (str, optional): Automatic lag-selection criterion (AIC, BIC, t-stat, or none). Valid options: AIC, BIC, t-stat, None. Default is 'AIC'.
        store (bool, optional): Return result storage object in addition to scalar outputs. Default is False.
        regresults (bool, optional): Return full regression results when available. Default is False.

    Returns:
        list[list]: 2D key-value table summarizing ADF statistics and critical values.
    """
    try:
        def to1d(values):
            if isinstance(values, list):
                if all(isinstance(row, list) for row in values):
                    raw = [item for row in values for item in row]
                else:
                    raw = values
            else:
                raw = [values]

            out = []
            for item in raw:
                try:
                    out.append(float(item))
                except (TypeError, ValueError):
                    continue
            return out

        if adf_regression not in ("c", "ct", "ctt", "n"):
            return "Error: regression must be one of 'c', 'ct', 'ctt', or 'n'"

        if adf_autolag in ("none", "None", "", None):
            autolag_arg = None
        elif adf_autolag in ("AIC", "BIC", "t-stat"):
            autolag_arg = adf_autolag
        else:
            return "Error: autolag must be 'AIC', 'BIC', 't-stat', or 'none'"

        series = to1d(x)
        if len(series) < 4:
            return "Error: x must contain at least four numeric values"

        result = sm_adfuller(
            np.asarray(series, dtype=float),
            maxlag=maxlag,
            regression=adf_regression,
            autolag=autolag_arg,
            store=store,
            regresults=regresults,
        )

        adf_stat = float(result[0])
        p_value = float(result[1])
        usedlag = int(result[2])
        nobs_used = int(result[3])
        crit_values = result[4]

        rows = [
            ["adf_stat", adf_stat],
            ["p_value", p_value],
            ["usedlag", usedlag],
            ["nobs", nobs_used],
        ]

        if isinstance(crit_values, dict):
            for key in ("1%", "5%", "10%"):
                if key in crit_values:
                    rows.append([f"critical_{key}", float(crit_values[key])])

        if len(result) > 5 and isinstance(result[5], (int, float, np.floating)):
            rows.append(["icbest", float(result[5])])

        return rows
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Time-series observations as a 2D range.
Maximum lag included in the test regression; null uses default rule.
Deterministic terms included in the test regression (c, ct, ctt, or n).
Automatic lag-selection criterion (AIC, BIC, t-stat, or none).
Return result storage object in addition to scalar outputs.
Return full regression results when available.