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

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.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

4 REPLIES 4
Rick_SAS
SAS Super FREQ

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.

mostater
Obsidian | Level 7

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.

Rick_SAS
SAS Super FREQ

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;
mingyuqi
Calcite | Level 5

I encountered the same issue a few days ago when I tried to run a cross-classified model using HPMIXED procedure. It seems that HPMIXED would pick up the reference level based on the fastest way of processing. So it is totally random each time you run the model. I suspect if there is really a way to set up the reference level by ourselves.  

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2034 views
  • 0 likes
  • 3 in conversation