You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pandas has removed OLS support, breaking DynamicVAR #3866
The DynamicVAR class relies on Pandas' rolling OLS, which was removed in version 0.20. Calling fit() throws AttributeError: 'module' object has no attribute 'ols'. The source of the problem is below.
def equations(self):
eqs = {}
for col, ts in iteritems(self.y):
# TODO: Remove in favor of statsmodels implemetation
model = pd.ols(y=ts, x=self.x, window=self._window,
window_type=self._window_type,
min_periods=self._min_periods)
eqs[col] = model
return eqs
If there aren't any deeper issues with DynamicVAR fitting that I'm not aware of, I can submit a quick PR for this.
Until recently (until after getting the deprecation/removal issues) I didn't know that DynamicVAR is even in use.
The main problem is zero unit test coverage. (It was implemented by Wes for AQR, and I thought it was never finished.)
The second problem is that nobody stepped forward yet to replace the windowing version MovingOLS in statsmodels. #2302
(AFAIK, it is mainly the fiance community that is using this type of models and so far I haven't seen any support or contributions from that side.)
In general I'm interested in any type of PRs, either quick fixes to account for the pandas removals or full rewrite or (re)implementation. It doesn't look like it's currently a priority issue for any existing contributors.
I'm not sure a full rewrite would be a great use of time. VAR has been mostly superseded by VARMAX, so it might be more useful to write a proper dynamic prediction function for MLEModel. Right now, I've been doing the following loop to do a dynamic fit of VARMAX(p, q):
import pandas.util.testing as ptest
import warnings
ptest.N = 500
data = ptest.makeTimeDataFrame().cumsum(0)
var = sm.tsa.VARMAX(data[:10], order=(1, 0))
res = var.fit(disp=False)
params = res.params
predictions = []
for i in range(10, len(data)):
new_model = sm.tsa.VARMAX(data[:i], order=(1, 0))
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
res2 = new_model.fit(start_params=params, disp=False,
maxiter=1, method='lbfgs')
predictions.append(res2.predict().tail(1))
params = res2.params
This is really slow for any reasonably sized dataset. Since we're fitting with a Kalman filter, we should be able to perform the update using max(p, q)-sized batches instead of using everything up to the current time. That would allow statespace models to perform both dynamic predictions on past data, as well as online prediction.
I don't think so. VAR is based on a closed form linear algebra least squares estimate, while VARMAX is based on the full MLE with nonlinear optimization. For the plain VAR use case, VAR should always be faster than VARMAX.
For recursive/expanding estimation the statespace setup is an obvious choice, but it would not work for any windowed version. Chad added RecursiveOLS for the expanding case which should have a similar structure and results as expanding OLS.
RecursiveVAR could use a similar structure but for the multivariate endog case.
The advantage of a least squares based DynamicVAR is in that the regressor matrix (lagged endog plus exog) only needs to be created once, and then windowing or expanding OLS/SUR just needs to work on slices similar to MovingOLS.
statespace models would also have an advantage for short windows in that the "prior" information can be used for the initialization of the state.
DynamicVAR should be either updated or deprecated, but should not sit in limbo indefinitely. IIRC it doesn't even get imported in the test suite, so does not show up in test coverage.
@josef-pkt Is the RecursiveOLS implementation you're talking about this? I'm confused about why it takes a RegressionResult instead of just accepting endog and exog, like a normal model class.
I think keeping DynamicVAR around is only really useful if someone adds support for exog as was done for VAR as part of the VECM pull (super excited for that!), but it'd still be a lot of work to get it properly updated. I'm leaning towards adding a dynamic prediction method (or argument to fit()) to MLEModel instead, since that could be applied to any statespace model and wouldn't require basically doing a clean rewrite of the DynamicVAR class.
I'm going to close this issue. Finally had time to take another look at this, and given the progress of the statespace module, it would take a large amount of work to get this even close to usable. Depreciation is a much better option here.
@jengelman You mean deprecating statsmodels DynamicVAR?
Sounds fine with me, especially also given the lack of support and maintenance for it.
I reopen this issue for the deprecation.
And just to confirm DynamicVAR worked for you before pandas 0.20? So we still want to deprecate instead of just removing it in case somebody is still running older pandas.
@josef-pkt Yep, deprecating statsmodels DynamicVAR. I rebuilt with an older version of pandas and successfully ran the example notebook to check.
Given the improvements in Kalman filter performance, the only feature this really removes from statsmodels is an easy way to inspect/visualize how VAR coefficients change over time, along the lines of RecursiveLS. That'd be a nice addition to MLEModel, but I'll open a separate issue for that.
Activity
josef-pkt commentedon Aug 13, 2017
Until recently (until after getting the deprecation/removal issues) I didn't know that DynamicVAR is even in use.
The main problem is zero unit test coverage. (It was implemented by Wes for AQR, and I thought it was never finished.)
The second problem is that nobody stepped forward yet to replace the windowing version MovingOLS in statsmodels. #2302
(AFAIK, it is mainly the fiance community that is using this type of models and so far I haven't seen any support or contributions from that side.)
In general I'm interested in any type of PRs, either quick fixes to account for the pandas removals or full rewrite or (re)implementation. It doesn't look like it's currently a priority issue for any existing contributors.
jengelman commentedon Aug 15, 2017
I'm not sure a full rewrite would be a great use of time. VAR has been mostly superseded by VARMAX, so it might be more useful to write a proper dynamic prediction function for MLEModel. Right now, I've been doing the following loop to do a dynamic fit of VARMAX(p, q):
This is really slow for any reasonably sized dataset. Since we're fitting with a Kalman filter, we should be able to perform the update using max(p, q)-sized batches instead of using everything up to the current time. That would allow statespace models to perform both dynamic predictions on past data, as well as online prediction.
josef-pkt commentedon Aug 15, 2017
I don't think so. VAR is based on a closed form linear algebra least squares estimate, while VARMAX is based on the full MLE with nonlinear optimization. For the plain VAR use case, VAR should always be faster than VARMAX.
RecursiveVAR could use a similar structure but for the multivariate endog case.
The advantage of a least squares based DynamicVAR is in that the regressor matrix (lagged endog plus exog) only needs to be created once, and then windowing or expanding OLS/SUR just needs to work on slices similar to MovingOLS.
statespace models would also have an advantage for short windows in that the "prior" information can be used for the initialization of the state.
jbrockmendel commentedon Aug 16, 2017
DynamicVAR should be either updated or deprecated, but should not sit in limbo indefinitely. IIRC it doesn't even get imported in the test suite, so does not show up in test coverage.
jengelman commentedon Aug 21, 2017
@josef-pkt Is the RecursiveOLS implementation you're talking about this? I'm confused about why it takes a RegressionResult instead of just accepting endog and exog, like a normal model class.
I think keeping DynamicVAR around is only really useful if someone adds support for exog as was done for VAR as part of the VECM pull (super excited for that!), but it'd still be a lot of work to get it properly updated. I'm leaning towards adding a dynamic prediction method (or argument to fit()) to MLEModel instead, since that could be applied to any statespace model and wouldn't require basically doing a clean rewrite of the DynamicVAR class.
josef-pkt commentedon Aug 21, 2017
No, that was written as post-estimation diagnostic, mainly for CUSUM test for stability/structural breaks
The new version by Chad based on the statespace framework is
http://www.statsmodels.org/dev/generated/statsmodels.regression.recursive_ls.RecursiveLS.html
jengelman commentedon Dec 26, 2017
I'm going to close this issue. Finally had time to take another look at this, and given the progress of the statespace module, it would take a large amount of work to get this even close to usable. Depreciation is a much better option here.
josef-pkt commentedon Dec 26, 2017
@jengelman You mean deprecating statsmodels DynamicVAR?
Sounds fine with me, especially also given the lack of support and maintenance for it.
I reopen this issue for the deprecation.
And just to confirm DynamicVAR worked for you before pandas 0.20? So we still want to deprecate instead of just removing it in case somebody is still running older pandas.
jengelman commentedon Dec 26, 2017
@josef-pkt Yep, deprecating statsmodels DynamicVAR. I rebuilt with an older version of pandas and successfully ran the example notebook to check.
Given the improvements in Kalman filter performance, the only feature this really removes from statsmodels is an easy way to inspect/visualize how VAR coefficients change over time, along the lines of RecursiveLS. That'd be a nice addition to MLEModel, but I'll open a separate issue for that.
josef-pkt commentedon Dec 26, 2017
@jengelman Thanks for coming back to this.
I relabeled and added to 0.9 milestone for adding the deprecation.
jengelman commentedon Apr 25, 2018
Closed by #4539