ADF稳定性检验
a基本原理:
使用ADF来检验时序数据中是否存在单位根,若存在单位根,则不稳定,否则稳定。
为什么存在单位根不稳定?
这个问题的答案可以参考知乎《为什么序列存在单位根是非平稳时间序列?》,解释起来有点复杂。
大致来说就是平稳的定义是一阶二阶矩阵不随时间的改变而改变,而存在单位根则代表二阶矩阵随时间的改变而改变。
b单位根检验:
单位根是什么?
单位根如何检验?
假设H0为存在单位根,Ha为不存在单位根。
如果得到的显著性检验统计量小于三个置信度(10%,5%,1%),则对应有(90%,95, 99%)的把握来拒绝原假设。
c算法入口:
ADF检验可以通过python中的 statsmodels 模块,其中用到的函数是adfuller
adfuller函数参数和返回值介绍具体如下
def adfuller(x, maxlag=None, regression="c", autolag='AIC',
store=False, regresults=False):
"""
Augmented Dickey-Fuller unit root test
The Augmented Dickey-Fuller test can be used to test for a unit root in a
univariate process in the presence of serial correlation.
Parameters
----------
x : array_like, 1d
data series
maxlag : int
Maximum lag which is included in test, default 12*(nobs/100)^{1/4}
regression : {'c','ct','ctt','nc'}
Constant and trend order to include in regression
* 'c' : constant only (default)
* 'ct' : constant and trend
* 'ctt' : constant, and linear and quadratic trend
* 'nc' : no constant, no trend
autolag : {'AIC', 'BIC', 't-stat', None}
* if None, then maxlag lags are used
* if 'AIC' (default) or 'BIC', then the number of lags is chosen
to minimize the corresponding information criterion
* 't-stat' based choice of maxlag. Starts with maxlag and drops a
lag until the t-statistic on the last lag length is significant
using a 5%-sized test
store : bool
If True, then a result instance is returned additionally to
the adf statistic. Default is False
regresults : bool, optional
If True, the full regression results are returned. Default is False
Returns
-------
adf : float
Test statistic
pvalue : float
MacKinnon's approximate p-value based on MacKinnon (1994, 2010)
usedlag : int
Number of lags used
nobs : int
Number of observations used for the ADF regression and calculation of
the critical values
critical values : dict
Critical values for the test statistic at the 1 %, 5 %, and 10 %
levels. Based on MacKinnon (2010)
icbest : float
The maximized information criterion if autolag is not None.
resstore : ResultStore, optional
A dummy class with results attached as attributes
"""
d实例参考:
from statsmodels.tsa.stattools import adfuller
def judgment(x, alpha):
result = adfuller(x)
if result[1] < alpha: # p_value值大,无法拒接原假设,有可能单位根,需要T检验
return False
else:
if result[0] < result[4]['5%']: # 代表t检验的值小于5%,置信度为95%以上,这里还有'1%'和'10%'
return False # 拒接原假设,无单位根
else:
return True # 无法拒绝原假设,有单位根
f参考文献:
知乎 为什么序列存在单位根是非平稳时间序列?
https://www.zhihu.com/question/22385598
知乎 请问单位根是什么,而且如何判断是几次单位根?
https://www.zhihu.com/question/316296812
时间序列笔记-ADF检验 https://www.jianshu.com/p/e27e5201abd4
时间序列分析之ADF检验 https://www.pianshen.com/article/5826219147/