Skip to content

commented-out in results_arima and results_arima #4357

Open

Description

@jbrockmendel

Good news. We're almost done with the "what was the intention here?" issues. A little over half of whats left are in results_arma or results_arima.

results_arima: it looks like maybe older results came from a different package and were commented out (instead of deleted) for [some reason?]. I don't see any indication of why these are still useful, or why they one set of results is preferred over the other.

https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arima.py#L430
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arima.py#L332
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arima.py#L212
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arima.py#L91
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arima.py#L58
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arima.py#L46

results_arma: pretty much the same deal, but with less readable formatting.
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L731
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L721
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L687
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L678
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L670
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L659
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L610
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L596
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L548
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L478
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L410
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L358
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L315
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L257
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L202
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L138
https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arma.py#L75

Activity

  1. josef-pkt commented on Mar 18, 2018

    @josef-pkt
    Member

    I only spot checked a few.

    In general those comments or commented out results represent a large amount of work. I don't know about the specific case in here, but for other cases outside of tsa that I know better, it took some time to figure out how results and definitions differ across packages and which ones we replicate and which ones we don't.
    E.g. there are several possibilities for cov_params (one comment mentions OPG instead of hessian, which is now an option in SARIMAX) and many packages drop constant terms from llf/aic/...

    Those comments are in general helpful as documentation across packages and for debugging. They are not really necessary for the unit tests, but it's a good location for storing those (easy to find for debugging).

    There might be some obsolete comments or comparison numbers, but for a maintainer it's better to keep them than to throw out the good with the bad.
    (Two unrelated examples:
    GLM negative binomial follows R for dispersion which I didn't know and wouldn't have used if I had written that part.
    GLM aic/bic have inconsistent definitions that I don't like but those were written following the definitions in Stata. Comments in unit tests are very helpful for those kind of cases.)

  2. jbrockmendel commented on Mar 18, 2018

    @jbrockmendel
    ContributorAuthor

    I only spot checked a few.

    I'll see if these answers can help me fix any of them, follow up with remaining in smaller pieces.

    Those comments are in general helpful as documentation across packages and for debugging.

    The parts that are comments serve as documentation. The parts that are commented-out code are like anti-documentation. At best they are useful for one reader: you.

    For e.g https://github.com/statsmodels/statsmodels/blob/master/statsmodels/tsa/tests/results/results_arima.py#L430

                #self.tvalues = [11.97, -5.846, 7.631, 1.634]
                #self.pvalues = [5.21e-33, 5.03e-9, 2.32e-14, .1022]
                #cov_params = np.array([
                #         [0.0620096, -0.00172172, 0.00181301, 0.00103271],
                #         [0, 9.69682e-04, -9.70767e-04, -8.99814e-04],
                #         [0, 0, 0.00698068, -0.00443871],
                #         [0, 0, 0, 0.00713662]])
                #self.cov_params = cov_params + cov_params.T - \
                #                np.diag(np.diag(cov_params))
                #self.bse = np.diag(np.sqrt(self.cov_params))
    

    This could be made useful if proceeded by a comment to the effect of # The following results for tvalues, pvalues, cov_params, and bse are based on results from [...]. We do not use them because of [...], but they are retained for reference. Without something like that, this is worse-than-useless to a reader.

  3. josef-pkt commented on Mar 18, 2018

    @josef-pkt
    Member

    Note, the else starts with

    #NOTE: this looks like a "hard" problem
                #unable to replicate stata's results even with their starting
                #values
                # unable to replicate x12 results in stata using their starting
                # values. x-12 has better likelihood and we can replicate so
                # use their results
    
                # taken from R using X12-arima values as init params
    

    and the later part switches to Gretl

                # from x12arima via gretl
                # gretl did not converge for this model...
    

    This is not for "casual" readers who might find it useless.
    I am also an outsider for this code, but both comments and code comments with reference numbers would give me a huge head (*) start if I had or have to debug something in here, or have to answer a question about why statsmodels doesn't replicate xxx.
    (*) getting a head start doesn't mean that it provides a full answer, but unit test writers don't have the time to write an article about comparing packages.

    If I were the only debugger, then it still would be useful to keep those. But my guess is that it is useful for anyone who has to figure out what's going on.
    Commented out reference numbers are also useful to see the original numbers if they have been fixed in the mean time in the comparison package.

  4. jbrockmendel commented on Mar 19, 2018

    @jbrockmendel
    ContributorAuthor

    and the later part switches to Gretl

    It is not clear to me what parts of the code the gretl comment refers to. "Everything from here on down" is a reasonable guess, but so is "from here until the next line break"

    This is not for "casual" readers who might find it useless.

    Right. In this case I am the reader, and I'm asking you to take my word for it when I say that I find these unhelpful. But we're getting closer to fleshing them out into something useful.

    There's also a Bayesian aspect to this. There's a ton of code that is commented out without a clear reason, e.g. in nearly every summary method. Or even code that explicitly tells the reader to get rid of it (#4358, or sandbox.panel.sandwich_covariance). "This is here because someone refuses to hit delete" is a reasonable hypothesis.

  5. jbrockmendel commented on Mar 19, 2018

    @jbrockmendel
    ContributorAuthor

    So in results_arma, there are a bunch of comments "# Note bse, cov_params, and t are from R", and then there are commented-out versions of each of those three variables next to non-commented-out versions. Is the implication that a) everything other than those three variables is from some other package and b) the commented-out versions are from that same other package?

  6. josef-pkt commented on Mar 19, 2018

    @josef-pkt
    Member

    to the last comment:

    Yes, that's what I think it is. In some cases Skipper stitched together results from several packages that match our results, Other packages might not have the results available or use a different definition.
    If I have to debug in this, then one of the first things I would do is to try to replicate the results in Stata, R and Gretl. (I'm currently more familiar and faster with Stata, than R and Gretl.)
    If this information is not available, then I would have to try "blind", reading documentation, articles or books and figuring out what's going on from scratch.

    (It's partially an attitude question: I have been debugging python statistics code for almost 10 years, mostly code written by other developers and also my own code written years ago. I prefer to figure out what the intention and reasons of the original author were before making "arbitrary" changes. Some developers rewrite from scratch which in my experience requires more work, knowledge and decisions than fixing existing code even if writing a new version is more "fun".)

    (another aside: In the sandwiches I intentionally didn't follow Stata's small sample corrections. The only place where I can find the details for the differences between Stata and statsmodels is in the unit tests, mostly in the corr_fact.)

    "This is here because someone refuses to hit delete"

    That's partially my pattern. The main problem or issue is "When in doubt whether information will still be useful, then err on not deleting it".

    This is also a question on code stability:
    If the code is stable, i.e. we don't expect any changes anymore, then we only need minimal maintainer documentation and the rest can go into git history. If we expect that code will still need bug-fixes, refactorings and enhancements, then hints hiding in dirty comments are still useful.
    Furthermore, if we deprecate AR(I)MA in favor of SARIMAX, then these parts can go into the git history.

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