Skip to content

Stale model with VAR #769

Open
Open

Description

@jseabold

Another ones of these.

def get_macrodata():
    data = sm.datasets.macrodata.load().data[['realgdp','realcons','realinv']]
    names = data.dtype.names
    nd = data.view((float,3))
    nd = np.diff(np.log(nd), axis=0)
    return nd.ravel().view(data.dtype)

import statsmodels.api as sm
from statsmodels.tsa.vector_ar import util
data = get_macrodata()
mod = sm.tsa.VAR(data)
res = mod.fit(2)

res2 = mod.fit(10, ic='fpe')

print res2.model.exog_names
# this is wrong
print res.model.exog_names
print res.exog_names

What to do? With ARIMA we moved the order to the model instantiation and we don't have lag-order selection for ARMA. My inclination would be to do the same for VAR and make the lag-order selection a function. The other thing I thought of is to make a Model.copy() and return a copy of the model attached to VARResults, but this might be too heavy.

Activity

  1. josef-pkt commented on Apr 13, 2013

    @josef-pkt
    Member

    maybe your change to exog_names was a too soon, coef_names looks/was correct (?)

    >>> res2.coef_names
    ['const', 'L1.realgdp', 'L1.realcons', 'L1.realinv']
    e:\josef\eclipsegworkspace\statsmodels-git\statsmodels-josef_new\statsmodels\tsa\vector_ar\var_model.py:864: FutureWarning: coef_names is deprecated and will be removed in 0.6.0.Use exog_names
      "Use exog_names", FutureWarning)
    

    VAR doesn't currently have any exog

    y_lagged, x and z are auxilliary variables, auxilliary models


    I don't see yet what the best structure for VAR would be,
    (my guess would be to use exog_ls (least squares) for the actual LHS)

    a basic question for/before refactoring VAR:
    What's the time difference in using the current lag order selection (internal to model) and just calling VAR fit with different lags, and checking the resulting ic?
    From the code, it looks like there are no (not much) savings in creating the y_lagged, so it's mostly the instantiation of the classes and supporting (data handling) code that is overhead in repeated calls.

  2. jseabold commented on May 4, 2013

    @jseabold
    MemberAuthor

    IIRC coef_names was created in the Results instance, so no it didn't have this problem. All of our code does (or should) rely on having the names in the model. Order selection / anything that changes the RHS / X / exog (except for trend selection) shouldn't be in the model functions I don't think. I leaning towards functions for these kinds of things, similar to the grid search API in scikit-learn. If we ever get variable selection / stepwise regression, etc. they should probably also be functions rather than model methods.

    My thinking now is to deprecate the lag order selection in fit and move the lag order selection to the model instantiation.

    I'll need to think a bit more about how the API should look through to be general, but something like

    # doesn't have to be a classmethod maybe just a function
    res = VAR.select_order(Y, maxlags=15, ic='aic', verbose=True)
    

    This would return a fitted model. I would say that it couldn't be called on an instantiated model already, but in that case it should probably just be a function var_select_order or something.

    The lag-order selection right now is about 3x faster than just instantiating the models and checking the IC, but the selection code doesn't have to be naive like this.

  3. added a commit that references this issue on May 5, 2013
    e3966d5
  4. jseabold commented on May 5, 2013

    @jseabold
    MemberAuthor

    Refactored for these changes. The way it is now, we'd have to live with possibly stale exog_names until 0.6.0 once the rest is deprecated. However, there are warnings for the deprecated and for when you reuse a model instance.

    https://github.com/jseabold/statsmodels/blob/3ebd7b0fd8bb76808241227d46b7ec3b571a5ac0/statsmodels/tsa/vector_ar/var_model.py#L390

  5. added a commit that references this issue on Jun 3, 2014
    9b4dfd7
  6. added a commit that references this issue on Sep 26, 2014
    da16c9d
  7. added this to the 0.9 milestone on Jun 16, 2016
  8. added a commit that references this issue on Jun 17, 2016
    2385d7e
  9. removed this from the 0.9 milestone on Apr 2, 2021
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions