Skip to content

df_resid in ar/arima/var_model #3568

Open

Description

@jbrockmendel

I'm trying to merge some redundant and confusing-to-me bits of ar_model, arima_model, and var_model. First a question that should be easy:

AR.fit and ARIMA.fit each take a method argument. method is used to determine self.nobs dynamically, which in turn affects self.df_resid and so on down the line. The options they recognize are slightly different, and I want to confirm that these are synonyms.

ARIMA.fit recognizes "css-mle", "mle", and "css". It sets nobs = n_totobs - k_ar if the method is "css", otherwise nobs = n_totobs. AR.fit recognizes "cmle" and "mle", and subtracts k_ar in the "cmle" case. (VAR subtracts k_ar regardless). So it looks very much like "cmle" is a synonym for "css". Is this correct?

That was the easy part. One more for now. AR, ARIMA, and VAR each define df_model, df_resid, and the information criteria slightly differently. My guess/hope is that the definition in AR contains a typo, in which case all of these can be merged into properties in a base class.

VAR and ARIMA both define df_resid as self.nobs - self.df_model. But AR defines it as self.n_totobs - self.df_model. Should the AR version also be nobs - df_model?

Some suggestive evidence:

a) df_resid is defined but then never used in ar_model.py
b) AR defines fpe as ((nobs+df_model)/(nobs-df_model))*self.sigma2. Having df_resid in the denominator here would line up with the definition in VAR.
c) AR divides by nobs-df_model in defining old_scale in the bse method.

Activity

  1. josef-pkt commented on Mar 22, 2017

    @josef-pkt
    Member

    (You are jumping around even more than I do :)

    I'm not sure about the details, but most sounds about right.
    first: I think AR might be "unreviewed", IIRC it is missing the summary method and other features.
    second: I'm skeptical about combining things much between VAR and the AR/ARMA/ARIMA, since VAR is multivariate and there are some special ways of counting degrees of freedom, e.g. by equation or by system.

    One guess, cmle and css might produce the same result in AR case, but are conceptually different, i.e. solve for MLE or for least-squares estimator. VAR is only least squares. statespace models includes VARMAX which has VARX estimated by MLE as a special case.

    Should the AR version also be nobs - df_model?

    My guess is yes, but you need to check whether df_resid shows up in the unit tests.
    Also, as a consistency check AR(p) and ARMA(p, 0) with css should produce identical results, unless there is a difference in definitions somewhere, i.e. differences are ok if they can be justified, but I would think those should be equivalent.

    df_resid is required by results.t_test, so if it is not used, then there is a missing feature or maybe missing test coverage.
    (Note, t_test doesn't actually use df_resid if use_t=True, but df_resid is required for every model as part of common attributes, an t_test is the method that checks for it.)

  2. ChadFulton commented on Mar 22, 2017

    @ChadFulton
    Member

    I'm trying to merge some redundant and confusing-to-me bits of ar_model, arima_model, and var_model.

    My opinion (maybe not shared by anyone else :) is that these models should all eventually extend from state space models (SARIMAX and VARMAX), except with additional fit methods (e.g. MLE using conditional loglikelihood, least squares) and perhaps some specific results (e.g. FPE). Then we get consistency for free.

    There are certain things that would be more difficult in that set up, but I think that it would be more than made up for by not having to maintain three separate sets of what should be essentially identical code (a good example of this is prediction / forecasting).

  3. josef-pkt commented on Mar 22, 2017

    @josef-pkt
    Member

    @ChadFulton My guess is that ARMA will become obsolete in favor of SARIMAX and we will be able to eventually deprecate it.
    However, VAR is to me pretty different from statespace models, and for example I don't think I would have been able to mentor a statespace.VECM GSOC project. A similar expansion will be to sparse VAR, which to me looks easier as a least squares/MLE VAR than as a statespace model. Much of the post-estimation extras could be shared or delegated to the more convenient representation.
    (VAR in Stata delegates to SUR or similar system of equation models. VECM with parameter restriction estimates by iterating between 2 or 3 conditional linear equations, or something like that.)

  4. jbrockmendel commented on Mar 22, 2017

    @jbrockmendel
    ContributorAuthor

    but I think that it would be more than made up for by not having to maintain three separate sets of what should be essentially identical code (a good example of this is prediction / forecasting).

    @ChadFulton That's pretty much the M.O. I've been pursuing in the branch I'm currently working on -- getting rid of duplication by putting things in base classes. Also making derived attributes (df_resid, aic, ...) into properties to avoid this kind of thing.

    these models should all eventually extend from state space models (SARIMAX and VARMAX)

    I understand (and share) the impulse to go more general --> less general, but as someone who has spent a lot of the last couple weeks getting familiar with the code-base, I'd suggest keeping some simpler versions around and in-use to keep it accessible to newcomers. The SARIMAX namespace is pretty overwhelming.

    @ChadFulton ... and since I've already been called out for jumping around, I might as well ask about this. Should there be a **0.5 in there somewhere? The corresponding point in transform_params squares the parameter, and this looks like the only place where transform_params and untransform_params aren't inverses of each other. Note this question is based solely on aesthetics and no attempt to understand what is actually happening.

  5. bashtage commented on Jul 22, 2019

    @bashtage
    Member

    xref #5985

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions