as part of a time series analysis for my master thesis I want to test whether a time series is stationary with the Augmented Dickey-Fuller test in Python. I attached the result for one time series. While I do understand that this result means that the series is stationary, I do not get what the # of lags are. Does this mean that the series is only stationary if 13 lags are used? Do I need to transform the data? Help would be highly appreciated!

ADF Result

import statsmodels
from statsmodels.tsa.stattools import adfuller
import pandas as pd
import statsmodels.api as sm
from statsmodels.tsa.filters.hp_filter import hpfilter

class StationaryTests:
    def __init__(self, significance=.05):
        self.pValue = None
        self.isStationary = None
    def ADF_Stationarity_Test(self, timeseries, printResults = True):
        #Dicky-Fuller tests:
        #adfTest = adfuller(timeseries, maxlag = 1)
        adfTest = adfuller(timeseries, autolag='AIC')
        self.pValue = adfTest[1]
        if (self.pValue<self.SignificanceLevel):
            self.isStationary = True
            self.isStationary = False
        if printResults:
            dfResults = pd.adfTest[0:4], index=['ADF Test Statistic', 'P-Value', '# Lags Used', '# Observations Used'])
            #Add Critical Values
            for key,value in adfTest[4].items():
                dfResults['Critical Value (%s)' %key] = value
            print('Augmented Dickey-Fuller Test Results:')
  • $\begingroup$ Are you using the adfuller() function in statsmodels? Can you update the question to include the arguments that you used or else describe what implementation of the test you're running $\endgroup$
    – vigos
    Dec 11, 2019 at 10:44
  • $\begingroup$ I added the code I used. $\endgroup$
    – Alina
    Dec 11, 2019 at 19:05
  • $\begingroup$ Hi, there are blind and visually impaired users of this site who interact with it using screen readers. The screen readers can't handle the equation in your screenshot. Please edit the post to include the equation as LaTeX. If it helps, we have some resources on using LaTeX on Cross Validated. $\endgroup$ Nov 20, 2021 at 5:35
  • $\begingroup$ Please include your code as text rather than an image of the code. I have tried to transcribe it, but may have introduced typos of my own. Please check and correct as necessary. $\endgroup$
    – Galen
    Apr 20, 2022 at 20:28
  • $\begingroup$ Please run PyLint on your code... You'll see a bunch of issues with your code style. $\endgroup$
    – Galen
    Apr 20, 2022 at 20:29

1 Answer 1


The lags are the reason for the word "Augmented" in the Augmented Dickey Fuller test. Without the lags, you'd be doing a Dickey Fuller test, like this one: $\Delta y_t=\alpha+\theta y_{t-1}+e_t$ testing whether $\theta=0$ where $\theta=\rho-1$ obtained by subtracting $y_{t-1}$ from both sides of the following equation $y_t=\alpha+\rho y_{t-1}+e_t$, in which we want to test for unit root (i.e. $\rho=1$). Under the null hypothesis $H_0:\theta=0$, the left side is $I(0)$ while the right side is $I(1)$, therefore this is an unbalanced regression so we already get the sense that $\theta$ may not have a t-distribution. The distribution of $\theta$ under the $H_0$ in a one-tailed test is called the $\tau$ distribution. Some values of this distribution have been tabulated under the assumption that the error terms are normally and identically distributed, but most crucially - under the assumption that the error terms are serially uncorrelated. So if in the Dickey Fuller equation the errors $e_t$ are normally and identically distributed and serially uncorrelated then you can compute the value of your sample's $\tau$ statistic and compare it to the $\tau$ critical values to decide if you reject the null of a unit root. But what if the errors $e_t$ are serially correlated? Well, then the distribution of $\theta$ will not be $\tau$. It will be some other distribution; perhaps an unnamed one. So, how do we fix it? We have to change the regression model $\Delta y_t=\alpha+\theta y_{t-1}+e_t$ so that $e_t$ are serially uncorrelated. How do we do that? With the ADF test, under the assumption that $e_t$ is an invertible ARMA process, which recall means that the process has an AR representation, we can just add AR terms one at a time until $e_t$ are serially uncorrelated. Once we've added n AR terms where n is the order of the AR representation of the assumed ARMA process for $e_t$, we are back to the conditions under which the $\tau$ distribution has been tabulated so we can use the $\tau$ distribution once again. While the ADF test introduced AR terms to correct for serial correlation in $e_t$ other tests address it differently (for example the Phillips-Perron test makes a non-parametric correction to the t-test statistic). What if our assumption that $e_t$ follows an invertible ARMA process (in which the MA polynomial does not have a large negative root) is incorrect? Then the ADF test will overreject the null hypothesis of a unit root.

So, returning to your question. You've added the lags in the ADF test because you want the estimator of interest to follow a known (i.e. $\tau$ distribution). Your conclusion here pertains to whether your series has a unit root or not. Note that a series may not have a unit root but may still not be stationary due to, for example, non-constant variance. If you reject the null hypothesis of the ADF test, you conclude that your series does not have a unit root, or in other words is $I(0)$ or Integrated of order 0.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.