时间序列分析之ADF检验

ADF检验

在使用很多时间序列模型的时候,如 ARMA、ARIMA,都会要求时间序列是平稳的,所以一般在研究一段时间序列的时候,第一步都需要进行平稳性检验,除了用肉眼检测的方法,另外比较常用的严格的统计检验方法就是ADF检验,也叫做单位根检验

ADF检验全称是 Augmented Dickey-Fuller test,顾名思义,ADF是 Dickey-Fuller检验的增广形式。DF检验只能应用于一阶情况,当序列存在高阶的滞后相关时,可以使用ADF检验,所以说ADF是对DF检验的扩展。

单位根(unit root)

在做ADF检验,也就是单位根检验时,需要先明白一个概念,也就是要检验的对象——单位根。

当一个自回归过程中:y_{t} = by_{t-1} + a + \epsilon _{t} ,如果滞后项系数b为1,就称为单位根。当单位根存在时,自变量和因变量之间的关系具有欺骗性,因为残差序列的任何误差都不会随着样本量(即时期数)增大而衰减,也就是说模型中的残差的影响是永久的。这种回归又称作伪回归。如果单位根存在,这个过程就是一个随机漫步(random walk)。

ADF检验的原理

ADF检验就是判断序列是否存在单位根:如果序列平稳,就不存在单位根;否则,就会存在单位根。

所以,ADF检验的 H0 假设就是存在单位根,如果得到的显著性检验统计量小于三个置信度(10%,5%,1%),则对应有(90%,95,99%)的把握来拒绝原假设。

ADF检验的python实现

ADF检验可以通过python中的 statsmodels 模块,这个模块提供了很多统计模型。

使用方法如下:

导入adfuller函数

from statsmodels.tsa.stattools import adfuller

adfuller函数的参数意义分别是:

  1. x:一维的数据序列。
  2. maxlag:最大滞后数目。
  3. regression:回归中的包含项(c:只有常数项,默认;ct:常数项和趋势项;ctt:常数项,线性二次项;nc:没有常数项和趋势项)
  4. autolag:自动选择滞后数目(AIC:赤池信息准则,默认;BIC:贝叶斯信息准则;t-stat:基于maxlag,从maxlag开始并删除一个滞后直到最后一个滞后长度基于 t-statistic 显著性小于5%为止;None:使用maxlag指定的滞后)
  5. store:True  False,默认。
  6. regresults:True 完整的回归结果将返回。False,默认。

返回值意义为:

  1. adf:Test statistic,T检验,假设检验值。
  2. pvalue:假设检验结果。
  3. usedlag:使用的滞后阶数。
  4. nobs:用于ADF回归和计算临界值用到的观测值数目。
  5. icbest:如果autolag不是None的话,返回最大的信息准则值。
  6. resstore:将结果合并为一个dummy。
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
    """

 现在我们用一个RB1309的收盘数据来进行ADF检验,看一下结果:

result = adfuller(rb_price)
print(result)


(-0.45153867687808574, 0.9011315454402649, 1, 198, {'5%': -2.876250632135043, '1%': -3.4638151713286316, '10%': -2.574611347821651}, 1172.4579344852016)

看到 t-statistic 的值 -0.451 要大于10%,所以无法拒绝原假设,另外,p-value的值也很大。

将数据进行一阶差分滞后,看一下结果如何:

rb_price = np.diff(rb_price)
result = adfuller(rb_price)
print(result)

(-15.436034211511204, 2.90628134201655e-28, 0, 198, {'5%': -2.876250632135043, '1%': -3.4638151713286316, '10%': -2.574611347821651}, 1165.1556545612445)

 看到 t-statistic 的值 -15 要小于5%,所以拒绝原假设,另外,p-value的值也很小。

 

  • 122
    点赞
  • 698
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
时间序列是一种重要的经济数据类型,它涉及到的变量通常是连续的,而且对于一些时间序列数据,可能存在某些趋势或者季节性等特征。在进行经济学方面的研究时,我们经常需要对时间序列数据进行检验,以判断其是否具有平稳性。ADF检验是一种重要的工具,可以用来检测时间序列数据是否呈现出平稳性的特征。 Stata是一种广泛使用的统计分析软件,它提供了一整套命令,可以用来进行时间序列ADF检验。具体来说,我们可以使用命令"dfuller"或者"adf"来进行检验。这两个命令的功能都非常类似,其中"dfuller"命令提供了更加灵活的参数设置和结果呈现方式。 在使用"dfuller"命令进行ADF检验时,我们需要指定需要进行检验的数据变量。一旦命令被输入,Stata会输出一张结果表,其中包括ADF检验的统计量和相应的p值。如果p值小于0.05,我们可以拒绝零假设,并得出结论表明数据具有平稳性。否则,我们则认为数据缺乏平稳性特征。 除此之外,在Stata中进行时间序列ADF检验时,我们还可以根据实际需求对检验过程进行相应的修改。例如,我们可以使用不同的lag数或者考虑趋势项和季节因素等影响,从而得出更加客观和准确的结论。 总的来说,Stata提供的时间序列ADF检验命令非常实用和方便,可以为经济学研究提供有力的支持。但是,在进行检验时,我们也需要注意选择合适的参数设置和数据变量,以保障结果的客观和准确。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值