Skip to content

Pandas has removed OLS support, breaking DynamicVAR #3866

Closed

Description

@jengelman

Statsmodels version: 0.8.0
Pandas version: 0.20.2

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.

Activity

  1. josef-pkt commented on Aug 13, 2017

    @josef-pkt
    Member

    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.

  2. jengelman commented on Aug 15, 2017

    @jengelman
    Author

    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.

  3. josef-pkt commented on Aug 15, 2017

    @josef-pkt
    Member

    VAR has been mostly superseded by VARMAX,

    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.

  4. jbrockmendel commented on Aug 16, 2017

    @jbrockmendel
    Contributor

    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.

  5. jengelman commented on Aug 21, 2017

    @jengelman
    Author

    @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.

  6. jengelman commented on Dec 26, 2017

    @jengelman
    Author

    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.

  7. josef-pkt commented on Dec 26, 2017

    @josef-pkt
    Member

    @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.

  8. jengelman commented on Dec 26, 2017

    @jengelman
    Author

    @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.

  9. added this to the 0.9 milestone on Dec 26, 2017
  10. josef-pkt commented on Dec 26, 2017

    @josef-pkt
    Member

    @jengelman Thanks for coming back to this.

    I relabeled and added to 0.9 milestone for adding the deprecation.

  11. jengelman commented on Apr 25, 2018

    @jengelman
    Author

    Closed by #4539

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions