Skip to content

WIP: abstraction/namespace correction for IRF - #5206

Closed
jbrockmendel wants to merge 1 commit into
statsmodels:masterfrom
jbrockmendel:irf
Closed

jbrockmendel wants to merge 1 commit into
statsmodels:masterfrom
jbrockmendel:irf

Conversation

@jbrockmendel

Copy link
Copy Markdown
Contributor

IRF needs some TLC. This PR is intended to discuss what order things should be done in.

var_model

The VARProcess class represents a known VAR process, takes coefs and sigma_u. This is a very good abstraction, is mathematically/statistically meaningful. To make it more directly usable, methods/properties of VARResults that correspond to to this abstraction should be moved up to this class. Demonstrated in this PR by roots, _cov_sigma, cov_ybar.

Also for demonstration purposes this collected all the coefs-but-not-sigma_u properties/methods first, as those also form a meaningful abstraction.

vector_ar.irf

irf has a BaseIRAnalysis and IRAnalysis(BaseIRAnalysis). BaseIRAnalysis uses some methods that are only defined in IRAnalysis (NameError, not just NotImplementedError). If those methods were moved to IRAnalysis, there would be basically nothing left in the base class. I think we're better off just having the one class. Is there either a) a meaningful abstraction the base class represents or b) something else we anticipate subclassing it?

The signature is incorrect as is. both __init__ methods take model, but what they really need is results or process.

The T attribute is easy to confuse with transpose when reading. Better to keep it consistent with the parent object's nobs. Using lags instead of k_ar doesn't have the same confusion issue, but we might as well keep it internally consisnent.

@josef-pkt

Copy link
Copy Markdown
Member

needs careful review
There is a lot of code reshuffling. and I'm not sure whether unit test coverage is good enough.
basic idea sounds good

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

and I'm not sure whether unit test coverage is good enough.

Definitely not. The initial motivation was in trying to shore up the unit tests. I think there's just a couple of smoke tests in test_var.

needs careful review [...] There is a lot of code reshuffling [...] basic idea sounds good

Thoughts on how to proceed? My inclination would be to split this into bite-size logically-independent steps. That approach isn't everyone's cup of tea.

@josef-pkt

Copy link
Copy Markdown
Member

The first step for this kind of refactoring is adding unit tests to ensure we don't have refactoring bugs in uncovered code.
Even bite-sized PRs require a lot of review work if unit test coverage is not good enough, i.e. just guessing whether code is correct based on reading it is fragile or takes a lot of time.
see test driven development in developer notes.

It's better to keep structural changes, e.g. moving several methods across classes, together. The first step is to decide whether the basic idea for the restructuring makes sense and is worth the effort, taking eg. deprecation cost into account.

In general, i.e. without having looked at the details of the changes here:
Anything that uses inference needs to be in a results class or delegated from the results class (or take the results class as argument and keep it as attribute).
e.g. when I wrote ArmaProcess the assumption was that we have a stochastic process with fixed parameters and no inference.
However, when we want inference like confidence intervals for process properties like impulse response function, then we need the estimation results. So, the most appropriate structure is not obvious to me when we mix things.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

see test driven development in developer notes.

uh, maybe software-development-process is not the best topic for the two of us

e.g. when I wrote ArmaProcess the assumption was that we have a stochastic process with fixed parameters and no inference.

Yah, total tangent but ARMAResults should ideally subclass ARMAProcess, analogous to VARResults/VARProcess. IIRC some of the naming conventions don't line up quite right.

Closing until after #5220.

@jbrockmendel
jbrockmendel deleted the irf branch September 18, 2018 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants