Panda-in-Code
Panda-in-Code

Reputation: 31

Different results in using Augmented Dickey Fuller test in Python

I want to check whether data is stationary or not. I applied ADF test with different inputs for parameters as seen as below:

from statsmodels.tsa.stattools import adfuller
Y = df.values
result = adfuller(Y, maxlag=15, autolag=None, regression='ct')

I got the first result:

adf              -16.057
p                1.12e-22
crit. val.       1%: -3.959, 5%: -3.411, 10%: -3.127
stationary?      true

The next one:

result = adfuller(Y) # use standard values for all parameters in adfuller() method

The result showed that my data is not stationary. It is opposite with the previous result:

ADF Statistic: -1.391000
p-value: 0.586583 
Critical Values:
        1%: -3.431
        5%: -2.862
        10%: -2.567

Should you help me explain why is it so different between both of results?

Upvotes: 2

Views: 2494

Answers (2)

Dauren A
Dauren A

Reputation: 1

In python I tried to use adfuller(x, autolag = "AIC", regression='ct', maxlag=np.round((len(x) - 1) ** (1/3))) where np.round((len(x) - 1) ** (1/3))) is the k in adf.test(x, k=trunc(length(x)-1)^(1/3))

Upvotes: 0

Echan
Echan

Reputation: 1415

I think there are two reasons

  1. Lags:

You set the autolag=None in your first test. With autolag=None The algorithm will use the maxlag as the lag in Augmented Dickey-Fuller test. So in result = adfuller(Y, maxlag=15, autolag=None, regression='ct'), it tests the stationary using data with 15 lags.

While default setting is autolag = "AIC" , it will chose the lag numbers to minimize the AIC. The chosen lag is in the 3rd of the test result result[2].

So check whether the lag of two test is the same.

  1. Regression:

    1). ‘ct’ : constant and trend

    2). default: constant only

The detail of adfuller in python: adfuller

Upvotes: 1

Related Questions