BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Porscha
Calcite | Level 5

Hi, I have a this program to calculate the hospital use according to the number of disease and the age. The number of disease has been coded into 5 categories (0 to 4) and the age also has 5 categories (1 (youngest) to 5(oldest)). We also added an interaction term between age and number of disease. I'm trying to calculate the difference between the oldest and the youngest group for each category of disease. I know we van use the lsmestimate procedure but I'm having a hard time to figure out where to place the zeros and ones, etc. This is my code :

 

Thank you 

 

PROC LOGISTIC desc DATA=exemple;
Class disease (ref='0') age (ref='1')/ param=glm;
Model hospital = disease age disease*age;
lsmeans disease age disease*age/ diff ilink cl e exp;
lsmestimate 'diff age 5 - age 1 for disease = 0' 0 0 0 0 0  1 0 0 0 -1/ ilink cl e exp;

lsmestimate 'diff age 5 - age 1 for disease = 1' 0 1 0 0 0  1 0 0 0 -1/ ilink cl e exp;

lsmestimate 'diff age 5 - age 1 for disease = 2' 0 0 1 0 0  1 0 0 0 -1/ilink cl e exp;

lsmestimate 'diff age 5 - age 1 for disease = 3' 0 0 0 1 0  1 0 0 0 -1/ilink cl e exp;

lsmestimate 'diff age 5 - age 1 for disease = 4' 0 0 0 0 1  1 0 0 0 -1/ilink cl e exp;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
StatDave
SAS Super FREQ

First, if there are five levels of both variables then there will be 25 mean estimates from the LSMEANS statement. If you want to compare two particular means, look at the table presented by the LSMEANS statement and specify 25 coefficients matching the order of means in that table in your LSMESTIMATE statement. For instance, if you want to compare the first two means (first - second), then specify coefficients 1 -1 followed by 23 zeros (though the trailing zeros can be omitted).

 

However, if you want an estimate of the difference in means, that cannot be provided by the LSMESTIMATE statement. You can see that in the results of the statements you showed by noting that the difference in two means from the LSMEANS statement (the values in the "Mean" column) is not the same as the value (either in the "Estimate" or "Mean" column) from the LSMESTIMATE statement. The Estimate value is the difference in log odds (not means) and the Mean value is nothing useful (the inverse logit of the difference in log odds). To estimate the difference in means, use the Margins macro to both fit the model and provide the estimate. 

 

%Margins(data = exemple,
         response = hospital,
         class = disease age,
         model = disease age disease*age,
         dist = binomial,
         margins = age,
         margwhere= age in (1 5),
         at = disease,
         options = diff cl)

 

 

 

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

This is exactly what the SLICE command in PROC LOGISTIC does.

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_introcom_sect064.htm&docsetVersio...

 

An example of using SLICE is given here (scroll down)

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=statug&docsetTarget=statu...

 

Additionally, you wouldn't normally use LSMESTIMATE or ESTIMATE if all you are doing is comparing one level to another level. Usually, the only time you need LSMESTIMATE or ESTIMATE is if you, for some reason, want to create estimates where the comparisons are not one level to another, for example, if you wanted –1*(level 1)+2*(level 2)–1*(level 3).

--
Paige Miller
sld
Rhodochrosite | Level 12 sld
Rhodochrosite | Level 12

Check the syntax for the LSMESTIMATE statement

 

LSMESTIMATE fixed-effect <'label'> values <divisor=> <, <'label'> values <divisor=>> <, ...>< / options> ;

 

You will see that your statement fails to include a fixed-effect.

 

This paper by Kiernan et al. contains a lot of information that you will probably find useful

 

CONTRAST and ESTIMATE Statements Made Easy: The LSMESTIMATE Statement 

 

In particular, for a contrast involving a 5x5 interaction I would use "non-positional syntax" (p 5 in the paper); it's a lot easier than trying to figure out where to put a "1" and a "-1" and 23 zeros in a set of 25 coefficients.

 

I hope this helps.

 

StatDave
SAS Super FREQ

First, if there are five levels of both variables then there will be 25 mean estimates from the LSMEANS statement. If you want to compare two particular means, look at the table presented by the LSMEANS statement and specify 25 coefficients matching the order of means in that table in your LSMESTIMATE statement. For instance, if you want to compare the first two means (first - second), then specify coefficients 1 -1 followed by 23 zeros (though the trailing zeros can be omitted).

 

However, if you want an estimate of the difference in means, that cannot be provided by the LSMESTIMATE statement. You can see that in the results of the statements you showed by noting that the difference in two means from the LSMEANS statement (the values in the "Mean" column) is not the same as the value (either in the "Estimate" or "Mean" column) from the LSMESTIMATE statement. The Estimate value is the difference in log odds (not means) and the Mean value is nothing useful (the inverse logit of the difference in log odds). To estimate the difference in means, use the Margins macro to both fit the model and provide the estimate. 

 

%Margins(data = exemple,
         response = hospital,
         class = disease age,
         model = disease age disease*age,
         dist = binomial,
         margins = age,
         margwhere= age in (1 5),
         at = disease,
         options = diff cl)

 

 

 

sld
Rhodochrosite | Level 12 sld
Rhodochrosite | Level 12

As @StatDave notes, Margins (and NLMeans and NLEstimate) are useful macros when the statistical model is a generalized linear model, and not a generalized linear mixed model. (Unfortunately, most of those I work with are mixed.)

 

Porscha
Calcite | Level 5

Thank you  @StatDave, and everyone else for the answers. This solution is what i was looking for. However, I am trying to use the Margins macro in sas and it is not working. I entered the code provided and added other covariables that i wanted to adujst for and I got this warning message for both of my main variables. I downloaded the macro from SAS, so i don't know if it ever happened to someone and what they've done to fix it. 

WARNING: No variables found beginning with 'disease_' in data set WORK._MODDAT.
WARNING: No variables found beginning with 'age_' in data set WORK._MODDAT.

 

Thank you 

 

 

StatDave
SAS Super FREQ

Please show the exact Margins macro call that caused those errors.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 1614 views
  • 1 like
  • 4 in conversation