Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yule_walker (from `statsmodels.regression`) raises exception when given an integer array #1869

WarrenWeckesser opened this issue Aug 4, 2014 · 1 comment


None yet
2 participants
Copy link

commented Aug 4, 2014

For example:

In [53]: x = np.array([1, -1, 2, 2, 0, -2, 1, 0, -3, 0, 0])

In [54]: yule_walker(x, 3)
LinAlgError                               Traceback (most recent call last)
<ipython-input-54-469606f4fbdf> in <module>()
----> 1 yule_walker(x, 3)

/Users/warren/local_scipy/lib/python2.7/site-packages/statsmodels-0.6.0-py2.7-macosx-10.5-x86_64.egg/statsmodels/regression/linear_model.pyc in yule_walker(X, order, method, df, inv, demean)
    906     R = toeplitz(r[:-1])
--> 908     rho = np.linalg.solve(R, r[1:])
    909     sigmasq = r[0] - (r[1:]*rho).sum()
    910     if inv==True:

/Users/warren/local_scipy/lib/python2.7/site-packages/numpy/linalg/linalg.pyc in solve(a, b)
    379     signature = 'DD->D' if isComplexType(t) else 'dd->d'
    380     extobj = get_linalg_error_extobj(_raise_linalgerror_singular)
--> 381     r = gufunc(a, b, signature=signature, extobj=extobj)
    383     return wrap(r.astype(result_t))

/Users/warren/local_scipy/lib/python2.7/site-packages/numpy/linalg/linalg.pyc in _raise_linalgerror_singular(err, flag)
     89 def _raise_linalgerror_singular(err, flag):
---> 90     raise LinAlgError("Singular matrix")
     92 def _raise_linalgerror_nonposdef(err, flag):

LinAlgError: Singular matrix

Convert to floating point, and it works fine:

In [55]: yule_walker(1.0*x, 3)
Out[55]: (array([ 0.06383878, -0.3374662 ,  0.35104014]), 1.2893596257735698)

The code should probably ensure that the input is floating point at the same time it ensures it is an array. Otherwise, even the following code that is supposed to demean the array will not work:

    if demean:
        X -= X.mean()

Version info:

In [59]: statsmodels.__version__
Out[59]: ''

In [60]: np.__version__
Out[60]: '1.9.0b1'

In [61]: scipy.__version__
Out[61]: ''

@josef-pkt josef-pkt added this to the 0.6 milestone Aug 4, 2014


This comment has been minimized.

Copy link

commented Aug 4, 2014

at least float32, or at least float64 ? or only convert ints ?
we never decided on dtype requirements, and don't enforce any yet.

I think float64 is fine here until someone complains and then we can change it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.