How to do in-sample prediction of SVAR model?

65 views
Skip to first unread message

Bingjie Han

unread,
Nov 29, 2017, 7:30:57 AM11/29/17
to pystatsmodels
I tried to do in-sample prediction of SVAR model after I fitted the SVAR model by SVAR().fit().

However, when I was trying to do prediction, I got an error message:  'SVARResults' object has no attribute 'predict'

This is so weird because I just did the similar thing with VARX model by using VARMAXResults.predict(). So, how should I do if I want to do in-sample prediction of SVAR model?

josef...@gmail.com

unread,
Nov 29, 2017, 9:46:03 AM11/29/17
to pystatsmodels
I have no idea how to do prediction or forecasting in SVAR. We don't have an issue for it and, AFAIR, it never came up. The Stata manual doesn't mention how prediction and forecasting is done and just refers to the general forecast function.

I'm not sure that there is anything extra in doing prediction with SVAR compared to using VAR. The lag coefficients are the same, or maybe an equivalent reparameterization. That is, I'm not sure whether using SVAR changes the forecasts or just the forecast error decomposition.
Even if that's the case we need a predict function or at least some answers in the docs. A brief google search for "forecasting with SVAR" doesn't find anything that provides a quick answer, AFAICS.

SVAR is partially unfinished and has never been fully reviewed. There are known problems and missing unit tests in at least some of the SVAR IRF code.


(SVAR is one area where I never tried to figure out the theory.)


Josef

rriveral

unread,
Feb 1, 2018, 7:34:59 PM2/1/18
to pystatsmodels
Is it possible to develop, would make sense? and if it does, how long you think it would take? just to evaluate if I can offer some help in order to get it fully devloped...

rriveral

unread,
Feb 1, 2018, 7:36:05 PM2/1/18
to pystatsmodels
Did you make it work ?? Bingjie ?

josef...@gmail.com

unread,
Feb 1, 2018, 8:15:18 PM2/1/18
to pystatsmodels
On Thu, Feb 1, 2018 at 7:34 PM, rriveral <rrodolf...@gmail.com> wrote:
Is it possible to develop, would make sense? and if it does, how long you think it would take? just to evaluate if I can offer some help in order to get it fully devloped...

My guess would be that it is theoretically easy, for the actual code it's necessary to check how easy it is to wire it up, i.e. connect the pieces.

AFAIK, SVAR is just VAR with parameter restrictions. So after the SVAR parameters have been estimated, we can just reuse the existing VAR post estimation tools.
thinking again: SVAR is in general a simultaneous equation system, so we might need to find the reduced form first to bring it into the VAR representation. 
I'm not sure this is just premultiplying by inv(A). but it seems like it https://en.wikipedia.org/wiki/Vector_autoregression#Reduced-form_VAR

I haven't looked at this area since I merged VECM, so I need to check to figure out how this can work or to answer questions about the implementation.
For example VECM has a helper method to create the short term VAR model, but might reestimate the model which we cannot do for SVAR.

how long it would take is difficult to tell
One day to figure out what to do. One day coding, One to five days of getting all the pieces to work correctly and unit tests. Maybe double or triple that if there are unforseen problems, bugs, corner cases, .... Maybe less if all pieces fit together well.
(And possibly 3 weeks getting lost in background readings about other things that would be useful to add. Maybe that part is just me.)


Josef

josef...@gmail.com

unread,
Feb 1, 2018, 9:05:06 PM2/1/18
to pystatsmodels
On Thu, Feb 1, 2018 at 8:15 PM, <josef...@gmail.com> wrote:


On Thu, Feb 1, 2018 at 7:34 PM, rriveral <rrodolf...@gmail.com> wrote:
Is it possible to develop, would make sense? and if it does, how long you think it would take? just to evaluate if I can offer some help in order to get it fully devloped...

My guess would be that it is theoretically easy, for the actual code it's necessary to check how easy it is to wire it up, i.e. connect the pieces.

AFAIK, SVAR is just VAR with parameter restrictions. So after the SVAR parameters have been estimated, we can just reuse the existing VAR post estimation tools.
thinking again: SVAR is in general a simultaneous equation system, so we might need to find the reduced form first to bring it into the VAR representation. 
I'm not sure this is just premultiplying by inv(A). but it seems like it https://en.wikipedia.org/wiki/Vector_autoregression#Reduced-form_VAR

I haven't looked at this area since I merged VECM, so I need to check to figure out how this can work or to answer questions about the implementation.
For example VECM has a helper method to create the short term VAR model, but might reestimate the model which we cannot do for SVAR.

how long it would take is difficult to tell
One day to figure out what to do. One day coding, One to five days of getting all the pieces to work correctly and unit tests. Maybe double or triple that if there are unforseen problems, bugs, corner cases, .... Maybe less if all pieces fit together well.
(And possibly 3 weeks getting lost in background readings about other things that would be useful to add. Maybe that part is just me.)


AFAICS, after browsing the code a bit:

SVARResults should have all the required intermediates as attributes If there are some missing, then they need to be attached.

First step is to get the VAR representation, i.e. depending only on past values.

then for forecast it looks like there are two options

- full support by creating a VARResults instance, similar to the last lines of VAR._estimate_var or
- support only forecasting using the standalone function in var_model.py. The predict method in VECMResults that does this is quite large because it needs to prepare all the special arrays for the explanatory variables, I think in SVAR it would be shorter.


one question: in-sample prediction or out of sample forecasting
in-sample prediction are just the residuals of the equivalent OLS/linear equation
out of sample forecasting requires the handling of the new regressors and needs to be recursive for h-step ahead prediction.


aside: I still don't find the naming in the VAR/SVAR neighborhood easy to understand, as a casual, hit-and-run developer.

Josef

Chad Fulton

unread,
Feb 1, 2018, 10:07:20 PM2/1/18
to Statsmodels Mailing List
On Thu, Feb 1, 2018 at 9:05 PM, <josef...@gmail.com> wrote:


On Thu, Feb 1, 2018 at 8:15 PM, <josef...@gmail.com> wrote:


On Thu, Feb 1, 2018 at 7:34 PM, rriveral <rrodolf...@gmail.com> wrote:
Is it possible to develop, would make sense? and if it does, how long you think it would take? just to evaluate if I can offer some help in order to get it fully devloped...

My guess would be that it is theoretically easy, for the actual code it's necessary to check how easy it is to wire it up, i.e. connect the pieces.

AFAIK, SVAR is just VAR with parameter restrictions. So after the SVAR parameters have been estimated, we can just reuse the existing VAR post estimation tools.
thinking again: SVAR is in general a simultaneous equation system, so we might need to find the reduced form first to bring it into the VAR representation. 
I'm not sure this is just premultiplying by inv(A). but it seems like it https://en.wikipedia.org/wiki/Vector_autoregression#Reduced-form_VAR

I haven't looked at this area since I merged VECM, so I need to check to figure out how this can work or to answer questions about the implementation.
For example VECM has a helper method to create the short term VAR model, but might reestimate the model which we cannot do for SVAR.

how long it would take is difficult to tell
One day to figure out what to do. One day coding, One to five days of getting all the pieces to work correctly and unit tests. Maybe double or triple that if there are unforseen problems, bugs, corner cases, .... Maybe less if all pieces fit together well.
(And possibly 3 weeks getting lost in background readings about other things that would be useful to add. Maybe that part is just me.)


AFAICS, after browsing the code a bit:

SVARResults should have all the required intermediates as attributes If there are some missing, then they need to be attached.

First step is to get the VAR representation, i.e. depending only on past values.

then for forecast it looks like there are two options

- full support by creating a VARResults instance, similar to the last lines of VAR._estimate_var or
- support only forecasting using the standalone function in var_model.py. The predict method in VECMResults that does this is quite large because it needs to prepare all the special arrays for the explanatory variables, I think in SVAR it would be shorter.


one question: in-sample prediction or out of sample forecasting
in-sample prediction are just the residuals of the equivalent OLS/linear equation
out of sample forecasting requires the handling of the new regressors and needs to be recursive for h-step ahead prediction.



Another alternative: once you have the reduced form VAR representation for the SVAR, you could pass the parameters into `smooth` or `filter` methods of the VARMAX model to get a VARMAXResults object, and then use the `predict` or `forecast` methods there.

Bingjie Han

unread,
Nov 20, 2018, 3:19:49 AM11/20/18
to pystatsmodels
sorry for mu quite late response. A year ago, I moved to someplace people can't use google.  
So, in Statsmodels, there is an attribute, called: VARResults.fittedvalues. You may wonder why it's VARResults, not SVARResults, because SVARResults just inherit this attribute from VARResults. I used this attribute and it worked fine.  
I would highly recommend you read the source code of Statsmodels, since it's documentation is messy when comes to SVAR models.



在 2018年2月2日星期五 UTC+8上午8:36:05,rriveral写道:
Reply all
Reply to author
Forward
0 new messages