我正在进行一项实验,以确定时间序列(例如,一个包含浮点数的列表)是否与自身相关。我已经使用statsmodels中的acf函数进行了试验(http://statsmodels.sourceforge.net/devel/generated/statsmodels.tsa.stattools.acf.html),现在我正在研究Durbin-Watson统计量是否有价值。
看起来这种方法应该行得通:
如果您运行此代码,会得到以下结果:
似乎D/W通常用于比较两个时间序列(例如http://connor-johnson.com/2014/02/18/linear-regression-with-python/)以进行相关性分析,所以我认为问题在于我没有传递另一个时间序列进行比较。也许这应该通过
看起来这种方法应该行得通:
from statsmodels.regression.linear_model import OLS
import numpy as np
data = np.arange(100) # this should be highly correlated
ols_res = OLS(data)
dw_res = np.sum(np.diff(ols_res.resid.values))
如果您运行此代码,会得到以下结果:
Traceback (most recent call last):
...
File "/usr/lib/pymodules/python2.7/statsmodels/regression/linear_model.py", line 165, in initialize
self.nobs = float(self.wexog.shape[0])
AttributeError: 'NoneType' object has no attribute 'shape'
似乎D/W通常用于比较两个时间序列(例如http://connor-johnson.com/2014/02/18/linear-regression-with-python/)以进行相关性分析,所以我认为问题在于我没有传递另一个时间序列进行比较。也许这应该通过
OLS
的exog
参数传递?exog : array-like
A nobs x k array where nobs is the number of observations and k is
the number of regressors.
(来自http://statsmodels.sourceforge.net/devel/generated/statsmodels.regression.linear_model.OLS.html)
顺便说一下:我不确定“nobs x k”数组是什么意思。也许是一个 x
乘以 k
的数组吗?
那么我应该在这里做什么呢?我需要两次传递 data
吗,还是手动滞后它呢?
谢谢!