我正在试验以决定是否与自身相关的时间序列(如在,一个浮点列表)。我已经在statsmodels(http://statsmodels.sourceforge.net/devel/generated/statsmodels.tsa.stattools.acf.html)中使用了acf
函数,现在我正在研究Durbin-Watson统计是否有任何价值。一维时间序列数据的Durbin-Watson统计
好像这种事情应该工作:
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/)的相关性,所以我认为问题是我没有通过另一个时间序列比较。也许这应该通过exog
参数传递给OLS
?
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
两次, 或手动延迟自己,还是?
谢谢!
谢谢。你能否确认将数据与自身关联起来,我不需要自己拖延数据?只传递数据作为独立变量和一个常量向量作为因变量。对? –
在这种情况下,OLS将仅仅贬低数据。像DW或类似的残差然后诊断测试然后可以使用,例如http://www.statsmodels.org/stable/stats.html#module-statsmodels.stats.stattools http://www.statsmodels.org/stable/diagnostic.html#autocorrelation-tests – user333700
谢谢!我还贴出了代码示例。 –