Help using Base SAS procedures

Getting the correct reference level for categorical variable in HPMIXED

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Getting the correct reference level for categorical variable in HPMIXED

I am running a mixed model using PROC HPMIXED.  I have a coded, classification variable called PAY with the following categories: 1='Private', 2='Medicare', 3='Medicaid', 4='Other'.  The codes have been formatted.  I would like to make Medicare the reference level so that the model solution forces Medicare to have beta = 0.  

 

Using the CLASS statement "CLASS PAY(ref='Medicare');" actually makes Medicare the last level and provides a non-zero beta for it.  The level receiving the zero beta is Medicaid, since it sorts alphabetically first.  It seems the REF option does not work the same in HPMIXED like it does in other SAS procedures.  Other than changing the format to force Medicare to be alphabetically first or changing the coding scheme, is there a way to get the desired reference level Medicare?

 

And the ORDER option (=DATA or =INTERNAL or =FREQ) in the PROC HPMIXED statement does not necessarily guarantee the correct reference level either.

 

 

 


Accepted Solutions
Solution
‎07-01-2016 12:55 PM
SAS Super FREQ
Posts: 3,310

Re: Getting the correct reference level for categorical variable in HPMIXED

Although many people like to recode, you can also use a user-defined format to change the order of categories. By default, SAS procedures use the FORMATTED values to determine order.  See the article "How to order categories..."

 

For example, the following statements change the order of the Geneder and Family variables. The example data/model is from the PROC MIXED documentation:

 

proc format;
value $ SexFmt 'F' = '2Female'
               'M' = '1Male';
value FamilyFmt 1 = 'Jones'
                2 = 'Johnson'
                3 = 'Smith'
                4 = 'Albertson';
run;

data heights;
   input Family Gender $ Height @@;
   datalines;
1 F 67   1 F 66   1 F 64   1 M 71   1 M 72   2 F 63
2 F 63   2 F 67   2 M 69   2 M 68   2 M 70   3 F 63
3 M 64   4 F 67   4 F 66   4 M 67   4 M 67   4 M 69
;

ods graphics off;
title "Without formats";
proc hpmixed data=heights;
   class Family Gender;
   model Height = Gender / s;
   random Family Family*Gender / s;
   ods select ParameterEstimates SolutionR;
run;

title "With formats";
proc hpmixed data=heights;
format Family FamilyFmt. Gender $SexFmt.; 
   class Family Gender;
   model Height = Gender / s;
   random Family Family*Gender / s;
   ods select ParameterEstimates SolutionR;
run;

View solution in original post


All Replies
SAS Super FREQ
Posts: 3,310

Re: Getting the correct reference level for categorical variable in HPMIXED

That's a good question. I think you are correct that "the REF option does not work the same in HPMIXED."  The doc for the CLASS statement in HPMIXED says the following (boldface added):

 

REF=’level’ | FIRST | LAST

specifies a level of the classification variable to be put at the end of the list of levels. (In procedures that solve mixed model equations by sequentially sweeping rows and columns, this level thus corresponds to the reference level in the usual interpretation of the estimates of a singular parameterization. However, since PROC HPMIXED does not necessarily solve mixed model equations in the original order, this interpretation of the specified REF= level does not apply for this procedure.)

 

I interpret the statement to mean that the REF= option changes the order in which parameters appear in the “Solution for Fixed Effects” table, but doesn’t change the parameter estimates. I don't know the technical reason, but apparently the order on the CLASS statement does not affect the linear algebra operations that PROC HPMIXED uses.

Contributor
Posts: 26

Re: Getting the correct reference level for categorical variable in HPMIXED

Thank you for the response.  Yes, I saw that in SAS help.  What I still can't determine, though, is a nice way to specify which level of the categorical variable is set to "zero".  The options basically allow you to sort the levels but I have not been able to use them correctly to obtain the desired order.  PROC HPMIXED sets the first sorted level to "zero", but if the desired level cannot be sorted that way using the REF='level'|FIRST|LAST, then I don't see an easy solution.  One solution is to recode the categorical variable or change the format, but that seems a little bit clunky.  I was hoping there would be a procedure option or something else that I was overlooking.

Solution
‎07-01-2016 12:55 PM
SAS Super FREQ
Posts: 3,310

Re: Getting the correct reference level for categorical variable in HPMIXED

Although many people like to recode, you can also use a user-defined format to change the order of categories. By default, SAS procedures use the FORMATTED values to determine order.  See the article "How to order categories..."

 

For example, the following statements change the order of the Geneder and Family variables. The example data/model is from the PROC MIXED documentation:

 

proc format;
value $ SexFmt 'F' = '2Female'
               'M' = '1Male';
value FamilyFmt 1 = 'Jones'
                2 = 'Johnson'
                3 = 'Smith'
                4 = 'Albertson';
run;

data heights;
   input Family Gender $ Height @@;
   datalines;
1 F 67   1 F 66   1 F 64   1 M 71   1 M 72   2 F 63
2 F 63   2 F 67   2 M 69   2 M 68   2 M 70   3 F 63
3 M 64   4 F 67   4 F 66   4 M 67   4 M 67   4 M 69
;

ods graphics off;
title "Without formats";
proc hpmixed data=heights;
   class Family Gender;
   model Height = Gender / s;
   random Family Family*Gender / s;
   ods select ParameterEstimates SolutionR;
run;

title "With formats";
proc hpmixed data=heights;
format Family FamilyFmt. Gender $SexFmt.; 
   class Family Gender;
   model Height = Gender / s;
   random Family Family*Gender / s;
   ods select ParameterEstimates SolutionR;
run;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 206 views
  • 0 likes
  • 2 in conversation