Skip to content

Slowly port VAR rebased changes in - #5220

Closed
bashtage wants to merge 27 commits into
statsmodels:masterfrom
bashtage:refactor-vector-ar
Closed

bashtage wants to merge 27 commits into
statsmodels:masterfrom
bashtage:refactor-vector-ar

Conversation

@bashtage

Copy link
Copy Markdown
Member

Bring in the changes in vector_ar and dependent modules only. Manually ported in fixes from #3028 rather than trying to rebase the entire PR.

Lots of doc string changes.
A few external variables rename all with deprecation.
Structured commits that should each pass the test suite.

xref #5206 #3028

Plan is to get #3028 into VAR over a number of PRs to limit reviews work (which is already a lot).

Rename greek-named variable to standard notation
Rename detomega to det_cov_resid
Rename _cov_sigma to _cov_of_cov_resid
Use standard python names
Small internal renames for consistency
Use a more meaningful name in forecast methods
Fully memoize confidence band constructions
Replace missed kwarg
Deprecate verbose printing in favor of additional returns
Fix missed renames to avoid warnings
Rename interval estimator to be more meaningful
Prefer Bunch to allow . access
Simplify and clean
Use inspection to determine type
Use endog in place of y
Use pythonic variable nameing, e.g., replace Gd with g_d
Add many missing doctrings
Remove opaque private dictionary in facto of defined kwards
Fix some small doc issues
@coveralls

coveralls commented Sep 17, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.09%) to 84.288% when pulling 93d960f on bashtage:refactor-vector-ar into a764908 on statsmodels:master.

Comment thread statsmodels/tsa/vector_ar/irf.py Outdated
self.svar_irfs = model.svar_ma_rep(periods, P=P)
else:
self.orth_irfs = model.orth_ma_rep(periods, P=P)
self.orth_irfs = model.orth_ma_rep(periods, p=P)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be done in the svar_ma_rep above?

@@ -296,11 +296,11 @@ def errband_mc(self, orth=False, svar=False, repl=1000,
model = self.model
periods = self.periods
if svar == True:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if svar

Comment thread statsmodels/tsa/vector_ar/irf.py Outdated
irf_resim = model.irf_resim(orth=orth, repl=repl, T=periods, seed=seed,
burn=100)
irf_resim = model.irf_resim(orth=orth, repl=repl, horizon=periods, seed=seed,
burn=100)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the burn kwarg in the method be passed instead of hard-coding 100?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto below

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saved for irf.py cleanup

Comment thread statsmodels/tsa/vector_ar/irf.py Outdated
neqs = self.neqs
irf_resim = model.irf_resim(orth=orth, repl=repl, T=periods, seed=seed,
burn=100)
irf_resim = model.irf_resim(orth=orth, repl=repl, horizon=periods, seed=seed,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all uses of irf_resim are here. Should that just be an irf method instead of a VARResults method?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but saving for irf clean

T=periods, signif=signif, seed=seed, burn=burn, cum=True)
return model.irf_errband_mc(orth=orth, repl=repl, horizon=periods,
signif=signif, seed=seed, burn=burn,
cum=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't be opposed to changing cum to cumul

Comment thread statsmodels/tsa/vector_ar/svar_model.py Outdated
try:
from pandas.util._decorators import deprecate_kwarg
except ImportError:
from pandas.util.decorators import deprecate_kwarg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for using this

@@ -12,6 +12,10 @@
import numpy as np
import numpy.linalg as npl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting rid of this and other unique import as [...] names in this modules would be nice

Comment thread statsmodels/tsa/vector_ar/svar_model.py Outdated
self.names = names

def orth_ma_rep(self, maxn=10, P=None):
def orth_ma_rep(self, maxn=10, p=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

svar_ma_rep below also change P-->p?

Actually, why this change? P is a matrix right?

@bashtage bashtage Sep 17, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P is not an ideal python variable name, p is.


def test_forecast(self):
point = self.res.forecast(self.res.y[-5:], 5)
point = self.res.forecast(self.res.endog[-5:], 5)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very much +1 for getting rid of the multiple aliases with the # keep alias for nows

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this decorator with some extensions as part of this PR. Saved a lot of error prone copy-paste pain upgrading attributes to properties.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the edits you made, will incorporate them downstream. There's also a test ready to be copied.


def test_forecast_interval(self):
y = self.res.y[:-self.p:]
y = self.res.endog[:-self.p:]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I need more caffeine; what does this slice mean?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last colon is unnecessary

Comment thread statsmodels/tsa/vector_ar/var_model.py Outdated
try:
from pandas.util._decorators import deprecate_kwarg
except ImportError:
from pandas.util.decorators import deprecate_kwarg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be done in compat.pandas?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes


return phis


def is_stable(coefs, verbose=False):
@deprecate_kwarg('verbose', 'eigenvalues')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? verbose seems clearer to me.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see; verbose and eigenvalues are doing different things. In that case is deprecate_kwarg the right pattern?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, but I figured that it probably doesn't matter. It sort of does the same thing -- give the eigenvalues to the user.


return phis


def is_stable(coefs, verbose=False):
@deprecate_kwarg('verbose', 'eigenvalues')
def is_stable(coefs, eigenvalues=False):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several of the functions in this module are redundant with methods in the classes. is_stable is one that ideally I'd like to see in a VARParams-like class, which would be inherited by VARProcess. VARParams would basically just have coefs attribute.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class heirarchy in VAR/VARProcess doesn't make sense. VARPRocess needs to know about exog stuff which isn't actually in VARProcess. It could use a big refactor but this is more than I want to try in this PR. Ditto some of the functions (not in classes) that have self as the first argument so they can be used somewhere else. These should be rewritten as propper functions with lists of arguments rather than relying on a particular structure to self.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure exog belong in VARProcess, or at least being able to keep it out as option.
VARProcess should be the dynamic properties of the underlying VAR process, and not so much about exogenous changes in mean.

return LagOrderResults(ics, selected_orders)

@property
def exog_names(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you turn this into a property?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better docstring and to match endog_names

import warnings
warnings.warn("plotsim is deprecated and will be removed in 0.11.0. "
"Use plot_sim.", DeprecationWarning)
"Use plot_sim.", FutureWarning)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't DeprecationWarning in these cases more appropriate?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now guidance from python.org: Future for users, Deprecation for developers. So Future is almost always the right warning. Older posts seemed to indicate Future was for this is definitely going away and deprecation is for things that may go away but shouldn't be used because there is a better way now.

@josef-pkt

Copy link
Copy Markdown
Member

I went roughly through the main commits, comments are on commits not PR itself.
It's much easier to read the main commits separately than the entire PR changes, as intended.

@codecov

codecov Bot commented Sep 18, 2018

Copy link
Copy Markdown

Codecov Report

Merging #5220 into master will increase coverage by 0.05%.
The diff coverage is 92.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5220      +/-   ##
==========================================
+ Coverage   81.59%   81.65%   +0.05%     
==========================================
  Files         569      569              
  Lines       89766    89855      +89     
  Branches    10047    10054       +7     
==========================================
+ Hits        73247    73373     +126     
+ Misses      14249    14215      -34     
+ Partials     2270     2267       -3
Impacted Files Coverage Δ
statsmodels/tsa/vector_ar/var_model.py 91.79% <ø> (+3.26%) ⬆️
statsmodels/tools/decorators.py 90.52% <100%> (+1.5%) ⬆️
statsmodels/tsa/vector_ar/output.py 84.46% <100%> (ø) ⬆️
statsmodels/tsa/vector_ar/tests/test_var_jmulti.py 78.74% <100%> (ø) ⬆️
statsmodels/tools/tests/test_decorators.py 97.4% <100%> (+1.4%) ⬆️
statsmodels/tsa/vector_ar/util.py 82.35% <45.45%> (-1.86%) ⬇️
statsmodels/tsa/vector_ar/irf.py 56.85% <50%> (ø) ⬆️
statsmodels/tsa/statespace/dynamic_factor.py 92.9% <66.66%> (+0.01%) ⬆️
statsmodels/tsa/statespace/varmax.py 91.44% <75%> (ø) ⬆️
statsmodels/tsa/vector_ar/vecm.py 93% <90%> (ø) ⬆️
... and 47 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 074c8d2...bf5a8b0. Read the comment docs.

@codecov

codecov Bot commented Sep 18, 2018

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@1b01f16). Click here to learn what that means.
The diff coverage is 92.27%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #5220   +/-   ##
=========================================
  Coverage          ?   81.65%           
=========================================
  Files             ?      569           
  Lines             ?    89855           
  Branches          ?    10054           
=========================================
  Hits              ?    73373           
  Misses            ?    14215           
  Partials          ?     2267
Impacted Files Coverage Δ
statsmodels/tsa/vector_ar/var_model.py 91.79% <ø> (ø)
statsmodels/tools/decorators.py 90.52% <100%> (ø)
statsmodels/tsa/vector_ar/output.py 84.46% <100%> (ø)
statsmodels/tsa/vector_ar/tests/test_var_jmulti.py 78.74% <100%> (ø)
statsmodels/tools/tests/test_decorators.py 97.4% <100%> (ø)
statsmodels/tsa/vector_ar/util.py 82.35% <45.45%> (ø)
statsmodels/tsa/vector_ar/irf.py 56.85% <50%> (ø)
statsmodels/tsa/statespace/dynamic_factor.py 92.9% <66.66%> (ø)
statsmodels/tsa/statespace/varmax.py 91.44% <75%> (ø)
statsmodels/tsa/vector_ar/vecm.py 93% <90%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b01f16...826d6b1. Read the comment docs.

@codecov

codecov Bot commented Sep 18, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5220 into master will increase coverage by 0.09%.
The diff coverage is 91.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5220      +/-   ##
==========================================
+ Coverage   81.72%   81.81%   +0.09%     
==========================================
  Files         569      569              
  Lines       89700    89796      +96     
  Branches    10028    10035       +7     
==========================================
+ Hits        73305    73470     +165     
+ Misses      14126    14064      -62     
+ Partials     2269     2262       -7
Impacted Files Coverage Δ
statsmodels/tsa/vector_ar/var_model.py 91.81% <ø> (+3.28%) ⬆️
statsmodels/tools/decorators.py 90.42% <100%> (+1.53%) ⬆️
statsmodels/tsa/vector_ar/output.py 84.46% <100%> (ø) ⬆️
statsmodels/tsa/vector_ar/tests/test_var_jmulti.py 78.74% <100%> (ø) ⬆️
statsmodels/tools/tests/test_decorators.py 97.33% <100%> (+1.33%) ⬆️
statsmodels/tsa/vector_ar/util.py 82.35% <45.45%> (-1.86%) ⬇️
statsmodels/tsa/vector_ar/irf.py 56.85% <50%> (ø) ⬆️
statsmodels/tsa/statespace/dynamic_factor.py 92.9% <66.66%> (+0.01%) ⬆️
statsmodels/tsa/statespace/varmax.py 91.44% <75%> (ø) ⬆️
statsmodels/tsa/vector_ar/svar_model.py 64.68% <76.47%> (+0.24%) ⬆️
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4aa71bb...2f0e360. Read the comment docs.

@jbrockmendel

Copy link
Copy Markdown
Contributor

Possibly closes #815?

@bashtage

Copy link
Copy Markdown
Member Author

Possibly closes #815?

I don't think so, at least not yet.

Comment thread statsmodels/tsa/vector_ar/vecm.py Outdated
"""
r"""
Test assumption of normal-distributed errors using Jarque-Bera-style
omnibus :math:`\\chi^2` test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there still be double \?

Use cov_root consistently
Rename horizon to steps
@bashtage
bashtage force-pushed the refactor-vector-ar branch from 93d960f to 2f0e360 Compare October 1, 2018 16:30
@bashtage bashtage closed this Apr 30, 2019
@bashtage
bashtage deleted the refactor-vector-ar branch May 1, 2019 10:03
@jbrockmendel

Copy link
Copy Markdown
Contributor

@bashtage why did you close this? The only potential problem I see is that there are tests for deprecated_alias usages that don't seem to be in place.

@bashtage

Copy link
Copy Markdown
Member Author

There seemed to be real will to end up fix the API which seemed to be necessary to getting VAR to be coherent enough that it could be called correct. So I found other tings to do.

jbrockmendel added a commit to jbrockmendel/statsmodels that referenced this pull request May 24, 2019
jbrockmendel added a commit to jbrockmendel/statsmodels that referenced this pull request Jun 8, 2019
jbrockmendel added a commit to jbrockmendel/statsmodels that referenced this pull request Jul 8, 2019
bashtage added a commit that referenced this pull request Jul 12, 2019
MAINT: implement parts of #5220, deprecate ancient aliases
bashtage added a commit to bashtage/statsmodels that referenced this pull request Jul 12, 2019
MAINT: implement parts of statsmodels#5220, deprecate ancient aliases
jbrockmendel added a commit to jbrockmendel/statsmodels that referenced this pull request Jul 12, 2019
jbrockmendel added a commit to jbrockmendel/statsmodels that referenced this pull request Jul 14, 2019
bashtage added a commit that referenced this pull request Jul 15, 2019
bashtage added a commit to bashtage/statsmodels that referenced this pull request Jul 15, 2019
bashtage added a commit to bashtage/statsmodels that referenced this pull request Nov 22, 2019
@bashtage bashtage added the rejected Used for PRs with changes that are not acceptable label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rejected Used for PRs with changes that are not acceptable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants