BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
wateas
Fluorite | Level 6

I'm conducting ANOVA for a multinomial, ordinal response variable in proc glimmix.  I would like to alter the order of factor levels to make interpretation of odd ratios easier, but short of renaming the factor levels, I'm not sure how to do it.  The variable is "Trt_CC" and the levels are "CC" and "no_CC".  The default ordering is alphabetical, but I would like "no_CC" ordered first as to help me interpret the procedure output.  So far, I've only been successful at renaming the factor levels

/* Change order of factor levels in factor2 such that no_CC is first. */
proc format;
value $trtfmt 
    'no_CC' = 1
    'CC'    = 2;
run;

/* Reponse_Var is an ordered, categorical variable with 5 levels.*/
proc glimmix data=df;
	class Site Block factor1 factor2;
	format factor2 $trtfmt.;
	model Response_Var = factor1 | factor2 | Site / dist=multinomial link=cumlogit oddsratio(diff=all) solution;
	random Block(Site) / solution;
run;


The above code successfully renames the levels of "factor2" as numbers and provides to desired ordering, but that has obvious drawbacks with respect to interpretability.  Any advice as to how to change the ordering of "factor2" so that "no_CC" is before "CC" would be appreciated.  Thanks for reading. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You did not convert the factors into numbers.  You merely attached a format that displayed them as digit strings that your mind interpreted as numbers.  Remember that formats convert values into text.

Why not use some other display values that make the outputs more sensible? 

proc format;
value $trtfmt 
    'no_CC' = '1 - No CC'
    'CC'    = '2 - CC'
;
run;

If you want to convert the variable into numeric use an INFORMAT instead.

proc format;
invalue trtinfmt 
    'no_CC' = 1
    'CC'    = 2
;
value trtfmt 
    1='1 - no_CC'
    2='2 - CC'
;
run;
data for_analysis;
  set df;
  nfactor2 = input(factor2,trtinfmt.);
  format nfactor2 trtfmt.;
run;
proc glimmix data=for_analysis ....

Or in this case just convert them to boolean 0/1 values.  Those should be clear without any need for additional display formats, especially as you can just name the boolean variable after the thing it is testing, which seems to be CC in this case (what ever that means to you.)

data for_analysis;
  set df;
  cc = factor2='CC' ;
run;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

There is the ORDER= option of the PROC GLIMMIX statement, but I believe that affects the order of all CLASS variables.

 

How about this example

 

proc glimmix data=sashelp.class;
    class sex(ref=first);
    model height=sex/solution;
run;

 

Of course the problem of interpreting coefficients for CLASS variables from the SOLUTION option, generally can be replaced by the easier-to-interpret (in my opinion) LSMEANS output;

 

                  Sex Least Squares Means

                   Standard
Sex    Estimate       Error       DF    t Value    Pr > |t|

M       63.9100      1.5735       17      40.62      <.0001
F       60.5889      1.6586       17      36.53      <.0001

 

--
Paige Miller
wateas
Fluorite | Level 6

I can't use LSMEANS for a multinomial distribution.  The issue is not interpreting the content of the solution table, but rather the odd ratios table.  The multinomial model is modeling the probabilities of a lower value of the response variable "weed_rating" (screenshot below).

 

wateas_0-1734979802228.png


The odds ratio table is easier to interpret when the first level has a lower response score than the second level, as the odds ratio estimate is a measure of the odds that the first level will have a LOWER score than the second level.  So if the estimate is 10, then the odds are 10x more likely that the first level will have a lower score than the second.   When the odds ratio is less than 1, the interpretation is not as intuitive to me, so it would be advantageous if I can rearrange factor level orders to accommodate that and make my life easier.  Here is a good link for reference and further detail.

wateas_1-1734980110413.png

 

Of course, I can simply manually rename my factor levels so they will have the desired ordering, but I thought I would try for a more sophisticated approach at first.  It is easy to reorder factor levels in R, so I thought there might be similarly easy solution in SAS.  Thanks for your help.

Tom
Super User Tom
Super User

You did not convert the factors into numbers.  You merely attached a format that displayed them as digit strings that your mind interpreted as numbers.  Remember that formats convert values into text.

Why not use some other display values that make the outputs more sensible? 

proc format;
value $trtfmt 
    'no_CC' = '1 - No CC'
    'CC'    = '2 - CC'
;
run;

If you want to convert the variable into numeric use an INFORMAT instead.

proc format;
invalue trtinfmt 
    'no_CC' = 1
    'CC'    = 2
;
value trtfmt 
    1='1 - no_CC'
    2='2 - CC'
;
run;
data for_analysis;
  set df;
  nfactor2 = input(factor2,trtinfmt.);
  format nfactor2 trtfmt.;
run;
proc glimmix data=for_analysis ....

Or in this case just convert them to boolean 0/1 values.  Those should be clear without any need for additional display formats, especially as you can just name the boolean variable after the thing it is testing, which seems to be CC in this case (what ever that means to you.)

data for_analysis;
  set df;
  cc = factor2='CC' ;
run;

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 3 replies
  • 353 views
  • 2 likes
  • 3 in conversation