statsmodels.tsa.stattools.adfuller()结构及用法详解

statsmodels是一个Python模块,提供了大量统计模型的类和函数。主要功能有:

  1. regression: Generalized least squares (including weighted least squares and least squares with autoregressive errors), ordinary least squares.
  2. glm: Generalized linear models with support for all of the one-parameter exponential family distributions.
    discrete choice models: Poisson, probit, logit, multinomial logit
  3. rlm: Robust linear models with support for several M-estimators.
  4. tsa: Time series analysis models, including ARMA, AR, VAR
  5. nonparametric : (Univariate) kernel density estimators
  6. datasets: Datasets to be distributed and used for examples and in testing.
  7. PyDTA: Tools for reading Stata .dta files into numpy arrays.
  8. stats: a wide range of statistical tests

statsmodels.tsa.stattools.adfuller(x, maxlag=None, regression='c', autolag='AIC', store=False, regresults=False)

迪基-福勒检验Augmented Dickey-Fuller(ADF) Test

  • 参数详解

  1. x (array_like*,* 1d) 数据序列

  2. maxlag (int) – Maximum lag which is included in test, default 12*(nobs/100)^{1/4}

  3. regression ′ c ′ , ′ c t ′ , ′ c t t ′ , ′ n c ′ {'c','ct','ctt','nc'} 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
  4. autolag ′ A I C ′ , ′ B I C ′ , ′ t − s t a t ′ , N o n e {'AIC', 'BIC', 't-stat', None} AIC,BIC,tstat,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
  5. store (bool) – If True, then a result instance is returned additionally to the adf statistic. Default is False

  6. regresults (bool*,* optional) – If True, the full regression results are returned. Default is False

  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你不想使用`statsmodels.tsa.stattools.adfuller`进行adf检验,你可以使用其他的Python库来实现它。这里提供两种方法: 方法一:使用PyFlux库 PyFlux是一个Python库,可以用于时间序列分析和建模。它提供了一个函数`adf()`,可以用于计算ADF检验的结果。 首先,你需要安装PyFlux库: ``` !pip install pyflux ``` 然后,你可以使用以下代码实现ADF检验: ```python import pyflux as pf import numpy as np def adf_test(x): model = pf.ARIMA(x=x, ar=1, integ=1, ma=0, target='difference') results = model.fit() return (results.summary(), results.z_values) ``` 在这个函数中,`x`是输入的时间序列数据,`ar`、`integ`和`ma`是ARIMA模型的参数,`target`指定要进行差分的目标变量。`results.summary()`返回ADF检验的统计结果,`results.z_values`返回ADF检验的统计值。 方法二:使用NumPy库 NumPy库提供了一个函数`polyfit()`,可以用于拟合多项式。通过拟合一个一次多项式,可以计算ADF检验的结果。 以下是实现ADF检验的代码: ```python import numpy as np def adf_test(x): n = len(x) t = np.arange(n) poly = np.polyfit(t, x, 1) slope = poly[0] adf = slope / np.std(x) return adf ``` 在这个函数中,`x`是输入的时间序列数据,`np.polyfit()`用于拟合一个一次多项式,`slope`是拟合结果的斜率,`np.std(x)`是时间序列数据的标准差。`adf`是ADF检验的统计值。 以上两种方法都可以用于实现ADF检验。你可以根据自己的需要选择其中一种方法。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值