user3820991
user3820991

Reputation: 2610

statsmodels - printing summary of ARMA fit throws error

I want to fit an ARMA(p,q) model to simulated data, y, and check the effect of different estimation methods on the results. However, fitting a model to the same object like so

model = tsa.ARMA(y,(1,1))
results_mle = model.fit(trend='c', method='mle', disp=False)
results_css = model.fit(trend='c', method='css', disp=False)

and printing the results

print result_mle.summary()
print result_css.summary()

generates the following error

File "C:\Anaconda\lib\site-packages\statsmodels\tsa\arima_model.py", line 1572, in summary
smry.add_table_params(self, alpha=alpha, use_t=False)
File "C:\Anaconda\lib\site-packages\statsmodels\iolib\summary.py", line 885, in add_table_params
use_t=use_t)
File "C:\Anaconda\lib\site-packages\statsmodels\iolib\summary.py", line 475, in summary_params
exog_idx]
IndexError: index 3 is out of bounds for axis 0 with size 3

If, instead, I do this

model1 = tsa.ARMA(y,(1,1))
model2 = tsa.ARMA(y,(1,1))
result_mle = model1.fit(trend='c',method='css-mle',disp=False) 
print result_mle.summary()

result_css = model2.fit(trend='c',method='css',disp=False)
print result_css.summary()

no error occurs. Is that supposed to be or a Bug that should be fixed?

BTW the ARMA process I generated as follows

from __future__ import division

import statsmodels.tsa.api as tsa
import numpy as np
# generate arma
a = -0.7
b = -0.7
c = 2
s = 10
y1 = np.random.normal(c/(1-a),s*(1+(a+b)**2/(1-a**2)))
e = np.random.normal(0,s,(100,))

y = [y1]
for t in xrange(e.size-1):
    arma = c + a*y[-1] + e[t+1] + b*e[t] 
    y.append(arma)

y = np.array(y)

Upvotes: 1

Views: 1563

Answers (1)

Josef
Josef

Reputation: 22897

You could report this as a bug, even though it looks like a consequence of the current design.

Some attributes of the model change when the estimation method is changed, which should in general be avoided. Since both results instances access the same model, the older one is inconsistent with it in this case.

http://www.statsmodels.org/dev/pitfalls.html#repeated-calls-to-fit-with-different-parameters

In general, statsmodels tries to keep all parameters that need to change the model in the model.__init__ and not as arguments in fit, and attach the outcome of fit and results to the Results instance. However, this is not followed everywhere, especially not in older models that gained new options along the way.

trend is an example that is supposed to go into the ARMA.__init__ because it is now handled together with the exog (which is an ARMAX model), but wasn't in pure ARMA. The estimation method belongs in fit and should not cause problems like these.

Aside: There is a helper function to simulate an ARMA process that uses scipy.signal.lfilter and should be much faster than an iteration loop in Python.

Upvotes: 1

Related Questions