BookmarkSubscribeRSS Feed
emaguin
Quartz | Level 8

I am unable to write valid contrasts for 2-way interactions and higher. Everything i write is not estimable, the assessment of which is unknown to me. 

Let factor A be (0,1),  factor B be (0,1), factor C be (1,2,3,4)  

1) I want to contrast factor B at factor A=1.

 I write: contrast 'factor B at A=1' what do i write next and  WHY? 

2) I want to contrast factor C levels 1,2 vs 3  vs 4 at factor B levels B=0

Again, what do i write and why? 

I want to emphasize that i don't want a reply of what Contrast does. I've read the  help statement several times and it's not  usefully helpful to me. 

Thanks, Gene Maguin

 

 

 

 

3 REPLIES 3
StatDave
SAS Super FREQ

You should avoid the use of CONTRAST or ESTIMATE statements for simple comparisons of means by using alternative statements like LSMEANS, SLICE, or LSMESTIMATE. These statements simplify or remove the necessity of correctly providing estimable functions of model parameters. All of these statements are illustrated and compared in multiple examples in this note. As shown there, the SLICE statement can be used to compare levels of one variable at each level of another variable. For example, when the model contains the A*B interaction, this statement compares the levels of A at each level of B, where both A and B are CLASS variables:

    slice a*b / sliceby=b; 

Or you could use LSMEANS:

    lsmeans a*b / slice=b; 

If you add the E option in either statement, you will get a table showing the coefficients on the model parameters that you could use in a CONTRAST or ESTIMATE statement to produce the same results.

jiltao
SAS Super FREQ

Like what @StatDave says, there are better ways to do the contrasts you listed, like the LSMEANS, SLICE, LSMESTIMATE statements. But if you still want the syntax for the CONTRAST statement, here are some examples.

Suppose your model is

class A B C;

model y=A B C A*B A*C B*C;  

where factor A (0,1),  factor B (0,1), factor C (1,2,3,4)  

Then here is the contrast statement:

contrast "b 0 vs 1 at A=1'  B 1 -1 A*B 0 0 1 -1;

Note that

1. The order of the coefficients depends on the order of the levels of your CLASS variables, as well as the CLASS statement. For example, CLASS A B C; determines that the coefficients for the interaction term, whether you use A*B or B*A, would be A0B0, A0B1, A1B0, A1B1 (hold the first effect's level, loop through the second effect's levels, then move on).

3. you could start with two simple estimates first: estimate "b0 at A=1" intercept 1 A 0 1 B 1 0 A*B 0 0 1 0; and

estimate "b1 at A=1" intercept 1 A 0 1 B 0 1 A*B 0 0 0 1;

then take the difference of the corresponding coefficients, to get the CONTRAST statement above.

Similarly, you might specify:

contrast "C 1 vs 3 at B=0" C 1 0 -1 0 B*C  1 0 -1 0 0 0 0 0;

contrast "C1 vs 4 at B=0" C 1 0 0 -1 B*C 1 0 0 -1 0 0 0 0;

 

I trust you understand that when I specify C 1 0 0 -1, that is because C has 4 levels, and the coefficients for these four levels are 1 (for level 1), 0 (for level 2), 0 (for level 3), and -1 (for level 4). So essentially it is comparing level 1 and level 4. I hope it make sense.

Like @StatDave pointed out, if you add the E option in in the LSMEANS or LSMESTIMATE statements, that would help you come up with the CONTRAST/ESTIMATE statement. Similarly, you can always add the E option in the CONTRAST and ESTIMATE statement to help you understand the coefficients in these statements.

Hope this helps,

Jill

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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