Durbin-Watson statistics for one-dimensional time series data

I am experimenting to decide if the time series correlates with it (such as one list of floats). I already had a game with a function acfin statsmodels ( http://statsmodels.sourceforge.net/devel/generated/statsmodels.tsa.stattools.acf.html ), now I look to see if Durbin-Watson statistics have any value.

It seems like such work should work:

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))

If you run this, you will get:

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 ,   ?

!

+4
2

OLS - , y x ( endog exog). x , .. np.ones(len (endog), 1).

, , .. ols_res = OLS(y, x).fit().

nobs x k 2- nobs k , exog.shape (nobs, k)

. OLS. , statsmodels.

( .)

+2

user333700 , .

durbin-watson ( , , 0), ( , , 2 ):

from statsmodels.regression.linear_model import OLS
import numpy as np
from statsmodels.stats.stattools import durbin_watson



def dw(data):
    ols_res = OLS(data, np.ones(len(data))).fit()
    return durbin_watson(ols_res.resid)


print("dw of range=%f" % dw(np.arange(2000)))
print("dw of rand=%f" % dw(np.random.randn(2000)))

:

dw of range=0.000003
dw of rand=2.036162

, , :)

0

Source: https://habr.com/ru/post/1674470/


All Articles