Hello all, I need some help with marginal effects in proc mixed. I am comparing two treatments from a clinical trial. I have tried the following code:
PROC MIXED DATA=Data METHOD=ml;
CLASS trt_group patient_id;
MODEL y=visit_yrs|trt_group/solution residual;
Random int visit_yrs/subject=patient_id;
FORMAT trt_group trt_group.;
RUN;
What I'd like to do is get the marginal effects for the treatment group (ie mean of all readings for all participants across the study). I believe lsmeans only allows categorical variables. I did try putting visit_wks as a class variable to accommodate the lsmeans statement, however that seems to change all the parameters for the model. I hope I've got the terminology correct. Any help would be greatly appreciated!
Hello,
A nice blog about the terminology :
Marginalia: A guide to figuring out what the heck marginal effects, marginal slopes, average marginal effects, marginal effects at the mean, and all these other marginal things are
by Andrew Heiss
https://www.andrewheiss.com/blog/2022/05/20/marginalia/
For an answer, see here :
Usage Note 30333: FASTats: Frequently Asked-For Statistics
https://support.sas.com/kb/30/333.html
Search for "marginal effects".
Margins, predictive and marginal effects
The MARGINS statement can estimate and test predictive margins and marginal effects for CLASS (categorical) predictors and is available beginning in these releases in these SAS Viya procedures: GLIMMIX (2021.1.3), LOGISTIC, SURVEYLOGISTIC, SURVEYPHREG, SURVEYREG, LMIXED (2022.12). For both categorical and continuous predictors, the Margins macro (SAS Note 63038) is available in SAS/STAT beginning in SAS 9.4M8 or can be downloaded. The Margins macro can estimate and test predictive margins and average marginal effects in generalized linear and GEE models fit using SAS/STAT PROC GENMOD. Predictive margins and average marginal effects can be estimated by the macro at specified values of other model variables or at computed values such as means or medians. For binary or ordinal logit or probit models, point estimates of marginal effects for predictors not involved in interactions can be obtained from the MARGINAL option in the OUTPUT statement of SAS/ETS PROC QLIM. SAS Note 22604 discusses and illustrates the estimation of marginal effects in logit and probit models.
Usage Note 22604: Marginal effect estimation for predictors in logistic and probit models
https://support.sas.com/kb/22/604.html
Koen
Many thanks Koen, that information was interesting. Unfortunately, I still couldn't figure out a way to calculate the mean across the whole study. Is the only way to calculate the lsmeans at specific time points, save to an output, and take a mean of those means? Or is there a simpler way?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.