【发布时间】:2017-09-05 10:23:15
【问题描述】:
我正在尝试确定时间序列(例如,一个浮点数列表)是否与自身相关。我已经玩过 statsmodels (http://statsmodels.sourceforge.net/devel/generated/statsmodels.tsa.stattools.acf.html) 中的 acf 函数,现在我正在研究 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 by k?
那么我应该在这里做什么?我是否希望通过data 两次,
还是自己手动滞后,或者?
谢谢!
【问题讨论】:
标签: python numpy statistics correlation statsmodels