You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add methods to get the margins and maginal plot for RegressionResults #6479
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.
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 .
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.)
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.
Activity
josef-pkt commentedon Jan 28, 2020
some preliminary thought:
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
dxthat 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
x.stevenlis commentedon Jan 28, 2020
https://cran.r-project.org/web/packages/margins/vignettes/Introduction.html
https://www.rdocumentation.org/packages/margins/versions/0.3.23
josef-pkt commentedon Jan 28, 2020
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
evalfor 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.)
stevenlis commentedon Jan 28, 2020
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.
josef-pkt commentedon Jan 28, 2020
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
stevenlis commentedon Jan 29, 2020
@josef-pkt I'm actually talking about the dependent variable or the function
C1