logic of indexing in .predict() mehod in tsa.ar_model.AutoReg 0.12.2

22 views
Skip to first unread message

Carlo

unread,
Jul 24, 2021, 6:17:20 AMJul 24
to pystatsmodels
Hello to everybody.

Could anybody explain to me the logic behind indexing in the .predict() mehod of tsa.ar_model.AutoReg ?

I'm working on a project where an error on the precise autoregression lag to be used
is crucial.

Hereafter I attach a snippet code of what I get in an
ultra-simplified setting.
I include the outputs, which I don't understand at all.

#------------------------
import numpy as np
from statsmodels.tsa.ar_model import AutoReg
# version 0.12.2

train = np.array([0.,1.,0.,1.,0.,1.,0.,1.,0.,1.])
m_ord = 2
model = AutoReg(train, m_ord, trend='n', old_names=False)
res_ar = model.fit()

# statsmodels manual page for start and end in predict:
# 'Zero-indexed observation number...'
# https://www.statsmodels.org/stable/generated/statsmodels.tsa.ar_model.AutoReg.predict.html#statsmodels.tsa.ar_model.AutoReg.predict
#
# STRANGE behavior, if 0 is the start index
res_ar.predict(0,0) # array([1., 0., 1., 0., 1., 0.])
res_ar.predict(0,1) # array([])
res_ar.predict(0,2) # array([0.])
# if start is 1, is end actually end-1 ?
res_ar.predict(1,2) # array([0.])
res_ar.predict(1,3) # array([0., 1.])
# or, end is end?
res_ar.predict(2,4) # array([0., 1., 0.])
res_ar.predict(2,5) # array([0., 1., 0., 1.])
# why the same output as above?
res_ar.predict(1,5) # array([0., 1., 0., 1.])

Thank you.

Carlo


Kevin Sheppard

unread,
Jul 26, 2021, 7:13:45 AMJul 26
to pystatsmodels
There are a number of bugs in AutoReg's predict in 0.12.x. They are expecially bad when using predict with values less than the ar order.  These have been fixed in master, so if you can, upgrade to a recent build.

Carlo Lucheroni

unread,
Jul 26, 2021, 8:25:09 AMJul 26
to pystat...@googlegroups.com
I get the bug upon running 0.12.2, the latest available release I found in the repository.

Dou you mean that I should yet upgrade to code newer than that
like 0.13.0.dev0?

The only way I found to do that upgrade (except compiling) is through a scypy wheel
Is it this what you mean ?

Carlo

--
You received this message because you are subscribed to the Google Groups "pystatsmodels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pystatsmodel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pystatsmodels/d4807cb0-1ce6-45db-9052-7a485536f505n%40googlegroups.com.




--
Carlo Lucheroni                                         
School of Sciences and Technologies
Universita' di Camerino                                  
via Madonna delle Carceri 9                             
62032 Camerino (MC)                                     
Italy                                                   
Office phone: 39-0737402552                                                                             
                                                        
--                                                      
Ask me for  my Mathematical Finance and
Stochastic Dynamic Optimization courseware:
'Take the Chance!'      

View and download my papers on Finance and Physics from ResearchGate:
https://www.researchgate.net/profile/Carlo_Lucheroni/publications

View and download my research on power markets on my SSRN Author page:
http://ssrn.com/author=1390778

You can also check IDEAS/RePEc for my name:
https://ideas.repec.org/f/plu234.html

Kevin Sheppard

unread,
Jul 27, 2021, 3:20:00 AMJul 27
to pystatsmodels
That is right.  You can either install using the nightly channel from anaconda.org or you can build from source, assuming you have a compiler installed using a command like


Kevin

Carlo Lucheroni

unread,
Jul 28, 2021, 10:17:31 AMJul 28
to pystat...@googlegroups.com
Same problem (nothing changes) with 0.12.2
build py37h2bbff1b_0.
In the conda repository, the wheel for 0.13.0.dev0 doesn't work (win10, py37).

I noticed another error in 0.12.2, in .df_model.

In both cases
model_ar_n = AutoReg(train, ar_ord, old_names=False, trend='n') # no trend
model_ar_c = AutoReg(train, ar_ord, old_names=False, trend='c') # constant

the number of degrees of freedom is the same, 2:

res_ar_n = model_ar_n.fit()
res_ar_n.df_model # 2
res_ar_c= model_ar_c.fit()
res_ar_c.df_model # 2, shouldn't be 3 ?

Kevin Sheppard

unread,
Jul 28, 2021, 10:54:39 AMJul 28
to pystatsmodels
This also is fixed in master.


On Wednesday, July 28, 2021 at 3:17:31 PM UTC+1 Carlo wrote:
Same problem (nothing changes) with 0.12.2
build py37h2bbff1b_0.
In the conda repository, the wheel for 0.13.0.dev0 doesn't work (win10, py37).

I noticed another error in 0.12.2, in .df_model.

In both cases
model_ar_n = AutoReg(train, ar_ord, old_names=False, trend='n') # no trend
model_ar_c = AutoReg(train, ar_ord, old_names=False, trend='c') # constant

the number of degrees of freedom is the same, 2:

res_ar_n = model_ar_n.fit()
res_ar_n.df_model # 2
res_ar_c= model_ar_c.fit()
res_ar_c.df_model # 2, shouldn't be 3 ?

Reply all
Reply to author
Forward
0 new messages