Skip to content

ENH/Design: statsmodels equivalent of design_info #5342

Open

Description

@josef-pkt

(I didn't find an issue, but I commented on this already)

We need some design_info when we are not directly using patsy's formulas.

current case: GAM creates multi-column terms that need special treatment. Currently this is handled directly in the model and results classes.
To make this more generic we need some additional information for terms that are created by statsmodels, or by the user, in which case the user needs to provide the information.

A generic idea was to allow for exog_extra in models that are user specified terms, similar to using terms like splines or categoricals in the formulas, but under the control of statsmodels without formula parsing.
Current example is polynomial trend in tsa models, and seasonal dummies in VECM.

Another usecase would be if we use patsy for individual terms but then want to combine this term into a full exog used in the models.
Related would be a drop methods for formula terms.
One problem with formula terms is that those are not independent of each other, e.g. dropping a reference category for categoricals depends on the presence of a constant, and it's more complicated with interaction terms.

This is mainly a convenience feature for users, e.g. we can provide additional post-estimation results without the user having to provide the extra information.
Similar to what we can do now with the additional information in patsy's design_info, for example wald_test_terms.
GAM will allow partial prediction, i.e. the contribution of a "term" to the linear predictor.
Another application is margins with respect to a non-linear function in an explanatory variable that is a linear combination of basis functions like polynomials or splines, which we don't have yet.

First part of design_info would be just named terms with index to the relevant columns of exog and of params, plus maybe a reference to the underlying instance that handles that term, e.g. a penalized spline instance.

Activity

  1. josef-pkt commented on Oct 31, 2018

    @josef-pkt
    MemberAuthor

    link to an old patsy PR for partial predict
    pydata/patsy#98

  2. josef-pkt commented on Jan 16, 2019

    @josef-pkt
    MemberAuthor

    a related ENH issue #5370 (comment)

    If we have exog_extra, then we need to combine the given exog with the exog_extra, which requires that we have the data handling (exog_names, and similar) and design_info for the full, concatenated exog.
    One problem in GAM is how to combine the given linear component exog with the created spline basis functions. It's not a problem with numpy arrays, but we don't have the extra info that we get from pandas, i.e. column names and index, and from patsy's design_info.

    GAM is the first case for this, AFAIK, but there will be more if we follow the exog_extra idea. Then we need a more generic and reusable solution to this.

  3. added this to the 0.11 milestone on Feb 1, 2019
  4. jbrockmendel commented on May 8, 2019

    @jbrockmendel
    Contributor

    Does this relate in any way to sandbox/formula.py?

  5. modified the milestones: 0.11, josef on Oct 5, 2019
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions