adf测试 python_Python中statsmodels中的ADF测试

I am trying to run a Augmented Dickey-Fuller test in statsmodels in Python, but I seem to be missing something.

This is the code that I am trying:

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)

I get the following error:

Traceback (most recent call last):

File "C:\Users\Akavall\Desktop\Python\Stats_models\stats_models_test.py", line 12, in

result = ts.adfuller(x)

File "C:\Python27\lib\site-packages\statsmodels-0.4.1-py2.7-win32.egg\statsmodels\tsa\stattools.py", line 201, in adfuller

xdall = lagmat(xdiff[:,None], maxlag, trim='both', original='in')

File "C:\Python27\lib\site-packages\statsmodels-0.4.1-py2.7-win32.egg\statsmodels\tsa\tsatools.py", line 305, in lagmat

raise ValueError("maxlag should be < nobs")

ValueError: maxlag should be < nobs

My Numpy Version: 1.6.1

My statsmodels Version: 0.4.1

I am using windows.

I am looking at the documentation here but can't figure what I am doing wrong. What am I missing?

Thanks in Advance.

解决方案

I figured it out. By default maxlag is set to None, while it should be set to integer. Something like this works:

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

Output:

>>> result

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值