[时间序列模型] python做adf检验

adf检验是用来检验序列是否平稳的方式,一般来说是时间序列中的一种检验方法。
python中可使用现成的工具statsmodels来实现adf检验。

方法及参数:

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

x = np.array([1, 2, 3, 4, 5, 6, 7])
result = ts.adfuller(x, 1)
print result
(-2.6825663173365015, 0.077103947319183241, 0, 7, {'5%': -3.4775828571428571, '1%': -4.9386902332361515, '10%': -2.8438679591836733}, 15.971188911270618)
statsmodels.tsa.stattools.adfuller(x, maxlag=None, regression='c', autolag='AIC', store=False, regresults=False)[source]¶
 x: 序列,一维数组
 maxlag:差分次数
 regresion:{c:只有常量,
            ct:有常量项和趋势项,
            ctt:有常量项、线性和二次趋势项,
            nc:无任何选项}
 autolag:{aic or bic: default, then the number of lags is chosen to minimize the corresponding information criterium,
          None:use the maxlag,
          t-stat:based choice of maxlag. Starts with maxlag and drops a lag until the t-statistic on the last lag length is significant at the 95 % level.}

 ADF检验总结一句话:如果序列是平稳的,则不存在单位根, 否则就会存在单位根。

同时,源数据不平稳(大多肉眼可见),可以做一阶差分、二阶差分这样子,看是否差分后平稳。

ADF检验的原假设是存在单位根,因此如果得到的统计量显著小于3个置信度(1%,5%,10%)的临界统计值时,说明是拒绝原假设的。另外是看P-value是否非常接近0(4为小数基本即可。)

原文地址:https://www.cnblogs.com/wynlfd/p/8862482.html