Repository navigation
Open
Labels
Milestone
Description
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:
- Add an optional
orderargument to the class constructor - If the
orderargument is not set, issue aDeprecationWarning - In the
fitmethod, ifmaxlag is not Noneor ific is not None, issue aDeprecationWarning. - Otherwise maintain existing behavior in
fit, except that ifmaxlag is Nonebutorderwas set in the class constructor,maxlagis set to thatordervalue. - 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] * 10Construction
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 classmod1.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
ChadFulton commentedon Feb 5, 2017
Alternatively, if this is too much "touching the code", we can just add a deprecation warning to the constructor and notes to the documentation.
ChadFulton commentedon Feb 5, 2017
@josef-pkt I can make whatever changes today, if this sounds okay to you?
josef-pkt commentedon Feb 5, 2017
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
iclag specification searches.ChadFulton commentedon Feb 5, 2017
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?
josef-pkt commentedon Feb 5, 2017
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 methodfit_icthat slices the given matrices or whatever is used to create reduced models.)ChadFulton commentedon Feb 5, 2017
That sounds fine to me also. On the other hand, if we're sure that we're moving
orderinto__init__, we may as well have some sort of deprecation notice?josef-pkt commentedon Feb 5, 2017
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.
ChadFulton commentedon Feb 5, 2017
I see, in that case I'll rename this to 0.9.
[-]DESIGN: AR, VAR, SVAR signature deprecations in 0.8[/-][+]DESIGN: AR, VAR, SVAR signature deprecations in 0.9[/+]jbrockmendel commentedon May 20, 2017
+1 to bringing these models into alignment with the rest of the hierarchy. Dynamically setting
nobswithinfitis 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?
jbrockmendel commentedon Sep 4, 2018
16 months later... any thoughts on following through on this?
ChadFulton commentedon Sep 5, 2018
It does seem like something that we should do.
josef-pkt commentedon Sep 5, 2018
to update on VECM: it has been merged and has all model definitions in
__init__and none infit.I only looked at the VAR case.
VAR will need a lot of refactoring to get rid of
icselect_order infitand 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.)bashtage commentedon Sep 21, 2018
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.