Skip to content

DESIGN: AR, VAR, SVAR signature deprecations in 0.9 #3434

Open

Description

@ChadFulton

I think we need to start the deprecation process so we can make these models consistent with setting order in __init__.

Currently the signatures of __init__ and fit in AR is:

  • sm.tsa.AR(self, endog, dates=None, freq=None, missing='none')
  • sm.tsa.AR.fit(maxlag=None, method='cmle', ic=None, trend='c', transparams=True, start_params=None, solver='lbfgs', maxiter=35, full_output=1, disp=1, callback=None, **kwargs)

and in VAR is:

  • sm.tsa.VAR(self, endog, dates=None, freq=None, missing='none')
  • sm.tsa.VAR.fit(maxlags=None, method='ols', ic=None, trend='c', verbose=False)

and in SVAR is:

  • sm.tsa.SVAR(self, endog, svar_type, dates=None, freq=None, A=None, B=None, missing='none')
  • sm.tsa.SVAR.fit(A_guess=None, B_guess=None, maxlags=None, method='ols', ic=None, trend='c', verbose=False, s_method='mle', solver='bfgs', override=False, maxiter=500, maxfun=500)

I propose that we do the following:

  1. Add an optional order argument to the class constructor
  2. If the order argument is not set, issue a DeprecationWarning
  3. In the fit method, if maxlag is not None or if ic is not None, issue a DeprecationWarning.
  4. Otherwise maintain existing behavior in fit, except that if maxlag is None but order was set in the class constructor, maxlag is set to that order value.
  5. Change the docstring to note the deprecation.

Examples below. I don't know how deprecations are best performed - i.e. we can issue a DeprecationWarning but that is ignored by default in Python.

Also, I don't know if I should specify a version number? Maybe 0.10? Or is 0.9 okay?

Examples:

Start with

import warnings
import statsmodels.api as sm
warnings.simplefilter('always')
endog = [0] * 10

Construction

mod1 = sm.tsa.AR(endog)
ar_model.py:95: DeprecationWarning: Specifying the AR order in `fit` is deprecated.
Please specify it when constructing the model using the `order` argument
  " using the `order` argument", DeprecationWarning)

and no warning is issued if instead:

mod2 = sm.tsa.AR(endog, order=1)

Fitting

Now, if order was not specified in construction, we will have the following behavior for fit:

mod1.fit()
# Here no further warnings are issued, since this is a perfectly good `fit` call, even after the
# deprecation is complete, and they've been warned about needing to set `order` when they
# constructed the class
mod1.fit(maxlag=2)
ar_model.py:557: DeprecationWarning: Specifying the AR order in `fit` using the `maxlag`
argument is deprecated and will be unavailable in a future version. Please specify the exact
order when constructing the model using the `order` argument
  " `order` argument", DeprecationWarning)
mod1.fit(ic='aic')
ar_model.py:566: DeprecationWarning: Selecting the AR order by minimizing information criteria
in `fit` is deprecated and will be  unavailable in a future version. Please specify the exact order
when constructing the model using the `order` argument
  " the `order` argument", DeprecationWarning)
mod1.fit(maxlag=2, ic='aic')
ar_model.py:557: DeprecationWarning: Specifying the AR order in `fit` using the `maxlag`
argument is deprecated and will be unavailable in a future version. Please specify the exact
order when constructing the model using the `order` argument
  " `order` argument", DeprecationWarning)
ar_model.py:566: DeprecationWarning: Selecting the AR order by minimizing information criteria
in `fit` is deprecated and will be  unavailable in a future version. Please specify the exact order
when constructing the model using the `order` argument
  " the `order` argument", DeprecationWarning)

Activity

  1. ChadFulton commented on Feb 5, 2017

    @ChadFulton
    MemberAuthor

    Alternatively, if this is too much "touching the code", we can just add a deprecation warning to the constructor and notes to the documentation.

  2. ChadFulton commented on Feb 5, 2017

    @ChadFulton
    MemberAuthor

    @josef-pkt I can make whatever changes today, if this sounds okay to you?

  3. josef-pkt commented on Feb 5, 2017

    @josef-pkt
    Member

    It would be better not to do it for VAR until #3246 VECM is merged. It changes/adds to the signature of VAR and it might be messier to resolve merge conflicts.
    VECM specifies the order (diff_lags) in __init__ already, but VAR could be changed after the VECM merge (which should happen soonish)

    changing AR and SVAR should be fine. I don't remember the details, but we might have to find computationally efficient substitutes for the ic lag specification searches.

  4. ChadFulton commented on Feb 5, 2017

    @ChadFulton
    MemberAuthor

    It would be better not to do it for VAR until #3246 VECM is merged. It changes/adds to the signature of VAR and it might be messier to resolve merge conflicts.

    Since it doesn't sound like VECM will be in 0.8, is there some other deprecation notice I should put into the VAR class to alert users of future changes?

  5. josef-pkt commented on Feb 5, 2017

    @josef-pkt
    Member

    I misunderstood, I thought this was for 0.9.

    I think it's better not to add this to 0.8 until we know what the ic alternative will be.
    (for example, mainly guessing: Assuming there is a computational advantage e.g. creating the lag matrices only once. The order in the __init__ can specify a maxlag which is fixed for the model, but we add a new method fit_ic that slices the given matrices or whatever is used to create reduced models.)

  6. ChadFulton commented on Feb 5, 2017

    @ChadFulton
    MemberAuthor

    I think it's better not to add this to 0.8 until we know what the ic alternative will be.

    That sounds fine to me also. On the other hand, if we're sure that we're moving order into __init__, we may as well have some sort of deprecation notice?

  7. josef-pkt commented on Feb 5, 2017

    @josef-pkt
    Member

    In general I would agree, but I think it's a bit too late to look at it. e.g. we use AR fit with ic in ARMA for the start_params. The deprecation notice will be very noisy if we cannot avoid it.

  8. ChadFulton commented on Feb 5, 2017

    @ChadFulton
    MemberAuthor

    I see, in that case I'll rename this to 0.9.

  9. changed the title [-]DESIGN: AR, VAR, SVAR signature deprecations in 0.8[/-] [+]DESIGN: AR, VAR, SVAR signature deprecations in 0.9[/+] on Feb 5, 2017
  10. added this to the 0.9 milestone on Feb 5, 2017
  11. jbrockmendel commented on May 20, 2017

    @jbrockmendel
    Contributor

    +1 to bringing these models into alignment with the rest of the hierarchy. Dynamically setting nobs within fit is a pet peeve of mine.

    The use case of "I know only know roughly what I want to run" is pretty common. VAR with order selection is the case here. The other case that comes to mind is variable selection with many exog columns. This would largely be a convenience class to reuse endog/exog inputs and possibly cache intermediate results. Has this been discussed elsewhere?

  12. jbrockmendel commented on Sep 4, 2018

    @jbrockmendel
    Contributor

    16 months later... any thoughts on following through on this?

  13. ChadFulton commented on Sep 5, 2018

    @ChadFulton
    MemberAuthor

    It does seem like something that we should do.

  14. josef-pkt commented on Sep 5, 2018

    @josef-pkt
    Member

    to update on VECM: it has been merged and has all model definitions in __init__ and none in fit.

    I only looked at the VAR case.
    VAR will need a lot of refactoring to get rid of ic select_order in fit and to move the array construction to __init__. However, AFAICS, the current select_order uses (almost) no computational shortcuts, so I expect the timing will be almost the same if select order needs to create a new VAR instance for each order. (I have no guess how much performance we would gain by preconstructing an array for maxlag.)
    AFAICS searching the unit tests, there are only smoke tests for VAR.fit(ic='xxx') so we need verifying unit tests before refactoring this. (In general, VAR unit test have too much smoke-type test, AFAIR.)

  15. bashtage commented on Sep 21, 2018

    @bashtage
    Member

    A complete VAR class should have a way to omit lags, possibly another input in addition to order, like
    order=5, drop=[2,3] to get a VAR(5) that omits lags 2 and 3 (an unrestricted seasonal quarterly VAR).

    It is also important to eventually get a constrained estiamtor in. It should support both 0 constraints , which are practically very important, and linear equality constraints. 0 constraints should be efficiently implemented so that the variable is not actually included in the list of regressors. linearmodels has a SUR that supports arbitrary linear constraints. It uses memory efficient blocked matrix operations and so can handle very large models.

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