Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fit new model in statsmodel fails – RuntimeError

I have created one AR model using statsmodels . That has worked but when I tried to create new model I hav gotten RuntimeError :

RuntimeError: Model has been fit using maxlag=1, method=cmle,
ic=None, trend=c. These cannot be changed in subsequent calls to
fit. Instead, use a new instance of AR.

This is how I generated the first model:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

model=AR(df['Pop'])
AR1fit=model.fit(maxlag=1)

...
AR1fit.predict(start=start,end=end)


#the 2nd model:
AR2fit=model.fit(maxlag=2)
>>>
RuntimeError: 
Model has been fit using maxlag=1, method=cmle, ic=None, trend=c. These
cannot be changed in subsequent calls to `fit`. Instead, use a new instance of
AR.

I haven’t found any post about this specific error, my goal is to fit the new model .

>Solution :

You have to instantiate a new model for the AR(2) and then call the fit method:

model2 = AR(df['Pop'])
AR2fit = model2.fit(maxlag=2)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading