BookmarkSubscribeRSS Feed
atorchio
Calcite | Level 5

Hello! I need to perform a one-way ANOVA once using effect coding and once using reference coding for a categorical variable with four categories.

However, I noticed that PROC GLM only allows reference coding...

Additionally, after running the ANOVA, I need to perform orthogonal contrasts and verify that the contrasts produce an additive decomposition of the explained deviance.

  1. Which SAS procedure allows me to specify the coding scheme for categorical variables (effect coding vs. reference coding) in ANOVA?
  2. How can I define orthogonal contrasts and ensure they lead to an additive decomposition of the explained variance in the same procedure above?

Any advice or example code would be greatly appreciated!

3 REPLIES 3
StatDave
SAS Super FREQ

You could use PROC GENMOD to fit the model with either parameterization of CLASS variables. Note that GENMOD fits the model via maximum likelihood estimation rather than least squares as is used by the ANOVA, REG, or GLM procedures. This example fits a simple one-way model using both parameterizations and tests a set of contrasts which match the parameter tests. Note that with reference parameterization, the tests compare each strain to the reference strain. With effect coding they compare each strain to the average of the strains. GENMOD's CONTRAST statement produces likelihood ratio tests by default but uses Wald tests for the parameters, so the WALD option is used to make the contrasts also use Wald tests.

data Clover;
   input Strain $ Nitrogen @@;
   datalines;
3DOK1  19.4 3DOK1  32.6 3DOK1  27.0 3DOK1  32.1 3DOK1  33.0
3DOK5  17.7 3DOK5  24.8 3DOK5  27.9 3DOK5  25.2 3DOK5  24.3
3DOK4  17.0 3DOK4  19.4 3DOK4   9.1 3DOK4  11.9 3DOK4  15.8
3DOK7  20.7 3DOK7  21.0 3DOK7  20.5 3DOK7  18.8 3DOK7  18.6
3DOK13 14.3 3DOK13 14.4 3DOK13 11.8 3DOK13 11.6 3DOK13 14.2
COMPOS 17.3 COMPOS 19.4 COMPOS 19.1 COMPOS 16.9 COMPOS 20.8
;
proc genmod data=clover;
   class Strain / param=ref;
   model Nitrogen = Strain;
   contrast '3dok1 v compost'  strain 1 0 0 0 0 / wald;
   contrast '3dok13 v compost' strain 0 1 0 0 0 / wald;
   contrast '3dok4 v compost'  strain 0 0 1 0 0 / wald;
   contrast '3dok5 v compost'  strain 0 0 0 1 0 / wald;
   contrast '3dok7 v compost'  strain 0 0 0 0 1 / wald;
   run;
proc genmod data=clover;
   class Strain / param=effect;
   model Nitrogen = Strain;
   contrast '3dok1 v compost'  strain 1 0 0 0 0 / wald;
   contrast '3dok13 v compost' strain 0 1 0 0 0 / wald;
   contrast '3dok4 v compost'  strain 0 0 1 0 0 / wald;
   contrast '3dok5 v compost'  strain 0 0 0 1 0 / wald;
   contrast '3dok7 v compost'  strain 0 0 0 0 1 / wald;
   run;

 

PaigeMiller
Diamond | Level 26

@atorchio wrote:

Hello! I need to perform a one-way ANOVA once using effect coding and once using reference coding for a categorical variable with four categories.


I suppose you can do this in PROC GLM, but the two models are identical — the predicted values are the same, the fit is the same.

 


@atorchio wrote:


However, I noticed that PROC GLM only allows reference coding...

 


You could create your own effect coding dummy variables in a DATA step and then use these dummy variables in PROC GLM, but the end result is the same. In fact, this is one of the major benefits of PROC GLM (and other SAS modeling PROCs) is that you don't have to spend the time to create your own dummy variables for categorical effects (and potentially make mistakes), SAS does this for you behind the scenes.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 829 views
  • 2 likes
  • 4 in conversation