BookmarkSubscribeRSS Feed
BruceBrad
Lapis Lazuli | Level 10

I have a logistic regression model with a large number of binary RHS variables (some entered as class variables). I want to calculate average marginal effects of each predictor.

 

If these were continuous variables, I would calculate this as p(1-p)B[i] where p is the predicted probability for each case, and B[i] is the i'th parameter. Following http://support.sas.com/kb/22/604.html I could use proc qlim to do this for me. I would then calculate the average of these estimates across cases to get an average marginal effect for each parameter.

 

My understanding, however, is that for binary variables a different approach is conventionally used. For each case, two predicted values are calculated. First, the value when X[i] is set = 0 and other X values at their original value, and second, when X[i] = 1 and other X values are set equal to their predicted values. The difference between these is the marginal effect for parameter i for each case - this can then be averaged across cases.

 

This binary case seems very messy to calculate, particularly with class variables. Does anyone have any example calculations? Indeed, is this really necessary? I would presume that the marginal effect should be very close to the binary comparison particularly when the B[i] are small.

2 REPLIES 2
StatDave
SAS Super FREQ

EDITED:

For binary response models, marginal effects for each observation can be obtained using the MARGINAL option in the OUTPUT statement of PROC QLIM in SAS/ETS. Note that these values are only correct for predictors that are not involved in higher-order effects in the model, like interactions. To get the average marginal effect of a predictor not involved in interactions, simply use PROC MEANS to compute the average of it's marginal effect for the desired response level. However, standard errors are not available from QLIM for the marginal effects, and not for the average marginal effect.

 

Alternatively, you can use the Margins macro. It can provide estimates of predictive margins, average marginal effects, and marginal effects at the means. Appropriate computations for marginal effects are done even for predictors involved in higher-order effects in the model. Standard errors for the margins and effects are provided and tests and confidence intervals are available as are pairwise comparisons and the ability to estimate and test contrasts. Several examples are provided in the Results tab at the above link. 

BruceBrad
Lapis Lazuli | Level 10

Looks interesting, though not quite what I want (I think). Essentially I'm after an equivalent of Stata's margins dydx command treatment of factor variables. That is, an average marginal effect for every parameter in the model where parameters that are members of class variables are calculated as follows: (assuming one category of the class variable is reference).

- For each observation,

     - predicted values are calculated for the case where all dummies of the class variable = 0, and other variables are at their observed value.

     - predicted values are calculated for the case where the dummy for the category of interest = 1 other categories = 0 and other variables at their observed value.

     - the difference between these predicted probabilities is calculated

- This difference is averaged across observations.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 4763 views
  • 0 likes
  • 2 in conversation