Skip to content

add methods to get the margins and maginal plot for RegressionResults #6479

Open

Description

@stevenlis

We have .get_margeff for LogitResults. Please consider adding the same method for RegressionResults so that the users can explore the margins for continuous variables (such as their interactions) in an ols model.

https://www.statalist.org/forums/forum/general-stata-discussion/general/1324886-continuous-interaction-variables-and-margins

https://stats.idre.ucla.edu/stata/faq/how-can-i-explain-a-continuous-by-continuous-interaction-stata-12/

Currently I wonder if there could be a workaround.

Activity

  1. josef-pkt commented on Jan 28, 2020

    @josef-pkt
    Member

    some preliminary thought:

    • The marginal effect dydix in linear models is just the parameter and not a nonlinear function of exog. The t_test method is a flexible method for arbitrary linear combination of parameters.
    • In linear models the values of other variables not in the parameters of interest don't affect the results, i.e. we don't need to specify them in margins_at predict_at, similar to partial prediction that only includes some terms.
    • The current margeff does not handle multi-column effects like main + interaction, nor polynomials or similar.
    • For polynomials or arbitrary user functions it would also be difficult to get the relevant information about the mean function, dxdy for a specific exog that spans multiple columns.

    What can we provide for linear models that is not just a simple call to t_test?

    If we want to compute some average prediction, then a piecewise linear function is still non-linear overall, and we need to compute the piecewise linear sum for margins_at or predict_at with averaging.

    The dx that we need to add params for linear models is an indicator function (exog_i != 0) if the corresponding param has a linear effect. However, even if x_i == 0 if x_i is a continuous variable, we could have a slope (dx !=0) at that point.

    Correction: It's not so easy for continuous-continuous interactions because we have to take the other continuous variable into account. I was thinking only of continuous-dummy interactions.

    so there are two ENH

    • extend current margins to linear models, which is mainly creating the indicator function for t_test.
    • extend current margins to handle interaction effects or multicolumn effects in general. That will not be easy for continuous-continuous interactions or arbitrary transformation of an x .
  2. josef-pkt commented on Jan 28, 2020

    @josef-pkt
    Member

    Thanks for the links. I knew that it was released a while ago but never looked at what they support.

    The main work for implementing margins for interaction effects is in getting the information out of the formula information.
    For nonlinear functions like log(x) it is essentially impossible, AFAIK, because patsy just uses eval for everything that is not predefined.
    Categorical variables have now a pretty good design_info, but I never looked at interactions with discrete variables.

    I'm not planning to look at how to get information out of formulas any time soon.

    (When I added the pairwise t_test, I avoided looking at and supporting interaction effects.
    In GAM we also don't support patsy's splines directly, because we needed additional first and second derivatives that patsy doesn't provide.)

  3. stevenlis commented on Jan 28, 2020

    @stevenlis
    Author

    In fact, I never used another package other than SM that uses formula or patsy. I really wish we could have our own formula support since it seems like patsy is no longer being maintained. Something like this pydata/patsy#146 should really be supported.

  4. josef-pkt commented on Jan 28, 2020

    @josef-pkt
    Member

    I may wanna code Yes as 0 and No as 1, or Yes as 1 and No as 0

    patsy supports choosing the reference category in dummy coding

    "C(a, Treatment('a2'))"
    https://patsy.readthedocs.io/en/latest/API-reference.html#handling-categorical-data

  5. stevenlis commented on Jan 29, 2020

    @stevenlis
    Author

    @josef-pkt I'm actually talking about the dependent variable or the function C1

  6. added
    topic-post_estim
    on Jun 9, 2023
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

    comp-discretecomp-regressioncomp-statstopic-post_estimtype-enh

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions