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
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.
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.
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.
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.
Activity
josef-pkt commentedon Apr 13, 2013
maybe your change to exog_names was a too soon, coef_names looks/was correct (?)
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.
jseabold commentedon May 4, 2013
IIRC
coef_nameswas 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
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_orderor 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.
REF: Deprecate lag selection. Add functions. Closes statsmodels#769
jseabold commentedon May 5, 2013
Refactored for these changes. The way it is now, we'd have to live with possibly stale
exog_namesuntil 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
REF: Deprecate lag selection. Add functions. Closes statsmodels#769
REF: Deprecate lag selection. Add functions. Closes statsmodels#769
REF: Deprecate lag selection. Add functions. Closes statsmodels#769