Repository navigation
Description
Original Launchpad bug 800012: https://bugs.launchpad.net/statsmodels/+bug/800012
Reported by: josef-pktd (joep).
import numpy as np
import scikits.statsmodels.api as sm
singular matrix with zero autocorrelation timeseries in ARMA ?
exog = sm.add_constant(np.random.randn(100, 2), prepend=True)
endog = exog.sum(1) + 0.2 * np.random.randn(100)
modarma = sm.tsa.ARMA(endog)
resarma = modarma.fit(order=(1,1))
Optimization terminated successfully.
Current function value: 6.341930
Iterations 12
Traceback (most recent call last):
File "", line 1, in
File "sm_overview.py", line 36, in
resarma = modarma.fit(order=(1,1))
File "E:\Josef\eclipsegworkspace\statsmodels-git\statsmodels-josef\scikits\statsmodels\tsa\arima_model.py", line 375, in fit
bounds=bounds, iprint=disp)
File "C:\Python26\lib\site-packages\scipy\optimize\lbfgsb.py", line 196, in fmin_l_bfgs_b
f, g = func_and_grad(x)
File "C:\Python26\lib\site-packages\scipy\optimize\lbfgsb.py", line 142, in func_and_grad
f = func(x, args)
File "E:\Josef\eclipsegworkspace\statsmodels-git\statsmodels-josef\scikits\statsmodels\tsa\arima_model.py", line 343, in
loglike = lambda params: -self.loglike_kalman(params)
File "E:\Josef\eclipsegworkspace\statsmodels-git\statsmodels-josef\scikits\statsmodels\tsa\arima_model.py", line 203, in loglike_kalman
return KalmanFilter.loglike(params, self)
File "E:\Josef\eclipsegworkspace\statsmodels-git\statsmodels-josef\scikits\statsmodels\tsa\kalmanf\kalmanfilter.py", line 632, in loglike
Q_0 = dot(inv(identity(m*2)-kron(T_mat,T_mat)),
File "C:\Python26\lib\site-packages\numpy\linalg\linalg.py", line 445, in inv
return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
File "C:\Python26\lib\site-packages\numpy\linalg\linalg.py", line 328, in solve
raise LinAlgError, 'Singular matrix'
numpy.linalg.linalg.LinAlgError: Singular matrix
Activity
josef-pkt commentedon Oct 6, 2011
I still get the exception, the example is random, I didn't get it with order (1,1), but with (2,2)
(2011-10-06 after pandas-integration merge)
jseabold commentedon Apr 3, 2012
I can reproduce with this data on my windows machine, python 2.7, 0.4.0 rc1, numpy 1.6.1, scipy 0.10.0b1.
http://www.pastie.org/3718289
There are nans in start_params.
[Edit: This is reproducible across platforms and numpy/scipy versions]
jseabold commentedon Apr 3, 2012
There is a problem with the Hannan-Rissanen starting parameters. They are not necessarily stationary and invertible, yet calling inverse ar/ma assumes they were and can lead to NaNs. (Also I'm not sure the parameters I gave are stationary...but this doesn't seem to be the root of the problem). If you give [0,0,0,0] it converges but far away from "true" parameters. If you give "true" parameters, it's a bit closer.
I'm not sure what to do here yet. Replacing NaNs with zeros works (but converges to a non-optimal solution). Come back to this.
jseabold commentedon Apr 3, 2012
For the record, gretl and stata also choke on this data, though there's nothing really to indicate the solution is fishy, except the MA roots in gretl. So I'm not as worried about this.
If you ask gretl to be noisy (show iteration details), you can see that all the MA parameters it tries are "out of bounds" until it gets to an MA solution with a root on the unit circle and it stops.
I didn't explore too much in Stata but it arrives at the same "solution" we do if you set start_params = [0,0,0,0].
So the question is, fail early and loudly, or not at all? I'm inclined to raise a warning that there were NaNs in the starting values and that we are reseting them all to zero. But the user should try this with different start values and reach their own conclusions. Maybe even put a note about this in the docs.
Thoughts?
josef-pkt commentedon Apr 3, 2012
I was also trying out different starting values. I'm using a different example, and I also have problems if the mean is misspecified. But I haven't tried yet with a case where the model is correctly specified.
I would switch to different starting values automatically in this case, but I'm not sure yet if or how we want to issue a warning. My impression is that a specification search, e.g. minimize BIC, should reject these cases.
Also besides the roots we might want to have other checks on the estimated parameters, but haven't thought much about it yet. regression diagnostics for ARMA ?
jseabold commentedon Aug 22, 2012
Here's another one that fails, simpler test case
ENH: Check for bad values from start_params for ARMA. Closes statsmod…
ENH: Check for bad values from start_params for ARMA. Closes statsmod…