BookmarkSubscribeRSS Feed
MattMaill
Calcite | Level 5

Hi,

I run a mixed model for a repeated mesures analysis. I have 2 factors : group factor with 4 levels and week factor with 5 levels. I want to test the time effect in each group and the group effect in each week.

 

I used the following code to test time effect in group 1 and group effect in week 2 : 

 
proc mixed data=rawdata;
class mice group week;
model col1 =  group week week*groupe ;
repeated / subject=mice type=cs;
 
contrast "Time effect in group 1" 
week -1 0 0 0 1 groupe*week -1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,
week 0 -1 0 0 1 groupe*week 0 -1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,
week 0 0 -1 0 1 groupe*week 0 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,
week 0 0 0 -1 1 groupe*week 0 0 0 -1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;

 

contrast "Group effect at time 2" 
    group -1 0 0  1 week*group 0 0 0 0 -1 0  0 1 0 0 0 0 0 0 0 0 0 0 0 0,
    group 0 -1 0  1 week*group 0 0 0 0 0 -1  0 1 0 0 0 0 0 0 0 0 0 0 0 0,
    group 0  0 -1 1 week*group 0 0 0 0 0  0 -1 1 0 0 0 0 0 0 0 0 0 0 0 0;

run;

It is working for "Time effect in group 1" but it does not work for "Group effect at time 2".

In the log, I can see " the contrast is not estimable".

 

Please, can you let me know if my first contrast is correct and if so, why the second one does not work?

Many thanks

Matthieu

 

9 REPLIES 9
PaigeMiller
Diamond | Level 26

Contrast statements are difficult for me (and others) to write, and there is a much simpler tool. Please look at the SLICE statement, it will estimate the values you want in this case. SAS has done the hard job of coming up with the right Contrasts (behind the scenes) so you don't have to do it yourself.

--
Paige Miller
jiltao
SAS Super FREQ

I agree with @PaigeMiller -- the SLICE statement is much easier to use. For example --

proc mixed data=rawdata;
class mice group week;
model col1 =  group week week*group ;
repeated / subject=mice type=cs;
slice week*group / sliceby=group sliceby=week;
run;
For your CONTAST statement, see if the following statement works for you --
contrast "Group effect at time 2" 
    group -1 0 0  1 week*group 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0,
    group 0 -1 0  1 week*group 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 1 0 0 0,
    group 0  0 -1 1 week*group 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 1 0 0 0;

 

Hope this helps,
Jill
MattMaill
Calcite | Level 5

Thank you very much,

I tried both, slice statement  and revised contrast statement as you suggested.

It is working perfectly.

Thanks again

Regards,Matthieu

MattMaill
Calcite | Level 5

Thank you,

Slice statement is much simpler !

 

Ksharp
Super User

From your CONTRAST statement,
You want "Time effect5 - Time effect1
in group 1" , NOT "Time effect in group 1" .
If you want Time5 v.s. Time1 effect, I think the best way is using LSMESTIMATE:

lsmestimate group*week 'time5- time1 at group1' -1 0 0 0 1 ;

Ksharp
Super User
slice week*group / sliceby(group='1') diff;
slice week*group / sliceby(week='2') diff;
MattMaill
Calcite | Level 5

Hi,

Thanks for your the suggested statements. It helps me too to compare groups two by two.

Matthieu

 

PaigeMiller
Diamond | Level 26

@MattMaill 

Advice: only use CONTRAST statements when the coefficients in the contrast statement are not some combination of -1 or  0 or 1. For example, if you want coefficients 2 -5 3, then CONTRAST is probably the way to go. Otherwise use SLICE or LSMEANS.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 9 replies
  • 219 views
  • 0 likes
  • 4 in conversation