简体   繁体   中英

Setting maxlag for ADF test with python statsmodels not working?

I've tried setting the maxlag with the ADF test in statsmodels but the number of lags being used by the test is not what I set it as. It is almost always less. Here's a small example of what I mean.

import numpy as np
import statsmodels.tsa.stattools as ts

x = np.array([1,2,3,4,3,4,2,3])
result = ts.adfuller(x, 1) # maxlag is now set to 1

>>> result
(-2.6825663173365015, 0.077103947319183241, 0, 7, {'5%': -3.4775828571428571, '1%': -4.9386902332361515, '10%': -2.8438679591836733}, 15.971188911270618)

The maxlag is set to one, but in the result it says the max lags used is 0 corresponding to the third entry in result.

Can anyone explain why this is happening and possibly how to fix this?

The maxlag parameter is the maximum parameter adfuller will try, but not necessarily use. If none is specified it determines the maxpar by computing [ceil(12*(n/100)^(1/4))], so that for longer data sets it assumes that higher order lags could be present (n is amount of observations here).

It then uses an information criterion to decide which lag gives the best model. An information criterion tries the balance the goodness of fit while minimizing the complexity of the model. You can specify which algorithm should be used to determine which model is the best by using the autolag parameter of the adfuller function. The default is Akaike information criterion.

If you would want to force the model to use the specified 'maxlag', you should turn off the determination of the best model by using autolag=None . Are you sure you want to do this?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM