Discussion:
[pystatsmodels] How to do in-sample prediction of SVAR model?
Bingjie Han
2017-11-29 11:48:45 UTC
Permalink
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?
j***@gmail.com
2017-11-29 14:45:58 UTC
Permalink
Post by Bingjie Han
I tried to do in-sample prediction of SVAR model after I fitted the SVAR
model by SVAR().fit().
'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?
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
2018-02-02 00:34:59 UTC
Permalink
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...
Post by j***@gmail.com
Post by Bingjie Han
I tried to do in-sample prediction of SVAR model after I fitted the SVAR
model by SVAR().fit().
'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?
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
j***@gmail.com
2018-02-02 01:15:14 UTC
Permalink
Post by rriveral
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
Post by rriveral
Post by j***@gmail.com
Post by Bingjie Han
I tried to do in-sample prediction of SVAR model after I fitted the SVAR
model by SVAR().fit().
'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?
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
j***@gmail.com
2018-02-02 02:05:02 UTC
Permalink
Post by j***@gmail.com
Post by rriveral
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
Post by j***@gmail.com
Josef
Post by rriveral
Post by j***@gmail.com
Post by Bingjie Han
I tried to do in-sample prediction of SVAR model after I fitted the
SVAR model by SVAR().fit().
'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?
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
Chad Fulton
2018-02-02 03:06:55 UTC
Permalink
Post by j***@gmail.com
Post by j***@gmail.com
Post by rriveral
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.)
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.
rriveral
2018-02-02 00:36:05 UTC
Permalink
Did you make it work ?? Bingjie ?
Post by Bingjie Han
I tried to do in-sample prediction of SVAR model after I fitted the SVAR
model by SVAR().fit().
'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?
Bingjie Han
2018-11-20 08:19:48 UTC
Permalink
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写道
Post by rriveral
Did you make it work ?? Bingjie ?
Post by Bingjie Han
I tried to do in-sample prediction of SVAR model after I fitted the SVAR
model by SVAR().fit().
'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?
Loading...