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為小數基本即可。)