BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
stats2554
Calcite | Level 5

I've been using PROC MIXED to perform repeated measures ANCOVA.  I receive the correct results with the following code:

proc mixed data=Result;
class subject period treatment time;
model result = baseline period subject treatment time treatment*time;
repeated time / type=CS subject=subject*period;
lsmeans treatment / pdiff=control;

 

I need to perform trend tests using contrasts.  When I evaluate the Treatment effect I receive the correct results:

  contrast 'linear' treatment -3 -1  1 3;

 

I need to look at the Treatment*time interaction with the contrast.  I have tried lsmestimate but I'm having difficulty finding the correct coefficients to use with the interaction.  Any advise is much appreciated!

 

1 ACCEPTED SOLUTION

Accepted Solutions
SteveDenham
Jade | Level 19

On a guess, the code you got was appropriate for looking at a linear trend at the first timepoint, much like a slicediff option for the lsmeans statement in PROC GLIMMIX. The periods serve as missing placeholders for the other timepoints.  Note that SLICE or SLICEDIFF do not fit an orthogonal linear trend (-3 -1 1 3)

 

One thing I would recommend is to remove the term 'subject' from your MODEL statement.  As it is now, I would expect that there would be either no degrees of freedom remaining for the residual variation, a zero estimate for the residual variation or both.

 

If your interaction is significant, then you would look at an LSMESTIMATE statement that had the -3 -1 1 3 coefficients separately for each time point.  Suppose you had 3 time points.  The statement would then look like:

 

lsmestimate Treatment*time 'Linear treatment at time 1' -3 0 0  -1 0 0  1 0 0  3 0 0, 
                           'Linear treatment at time 2' 0 -3 0  0 -1 0  0 1 0  0 3 0,
                           'Linear treatment at time 3' 0 0 -3  0 0 -1  0 0 1  0 0 3';

 With more time points, this gets longer and you might want to consider using non-positional syntax.

 

SteveDenham

 

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

Its not clear to me what contrast you want for an interaction, and its not clear what you linear contrast has to do with the interaction. Please explain in words. Please be specific.

--
Paige Miller
stats2554
Calcite | Level 5

I need to evaluate dose response relationship through linear trend tests.  I first ran the test for linear treatment for the overall treatment effect.  I also need to evaluate the linearTreatment*time.  If linear Treatment*time is significant I will run the tests at each individual timepoint.  But the p-value I'm receiving for the LinearTreatment*time interaction is not matching my reference data so am looking for help with the code.

PaigeMiller
Diamond | Level 26

On the one hand, you say you are having difficulty finding the right coefficients; but then you say your p-value is not what you expect it to be compared to reference material. Can you show us your code and show us your output and explain what the reference material shows?


Why does the reference material matter anyway? Did you try to do an exact duplicate of the experiment performed in the reference material?

--
Paige Miller
jiltao
SAS Super FREQ

One easier approach would be to treat your treatment variable as a continuous variable, then the test for treatment itself tells you whether the slope is significant -- that tells you the linear trend; and the interaction term treatment*time tests whether the slopes are different across different time points, all of which can be seen in the Type 3 Tests for Fixed Effects table.

If for some reason you must treat treatment as a categorical variable, then I would assume you wanted to test if the linear trend of the treatment is different across different time points with the proposed CONTRAST statement? Then the syntax would depend on your data. If you add the E option to your current CONTRAST statement  --

contrast 'linear' treatment -3 -1  1 3 / e;

and send us the output, maybe I can give it a try.

 

Thanks,

Jill

stats2554
Calcite | Level 5

Thanks I will try that.  I did receive some code however I don't understand what the periods mean in the lsmestimate statement ( 3 0 0 0.. -1 0 0 0.. 1 0 0 0.. 3 0 0 0) and how I adjust for my specific design?  

 

proc mixed data=Result;
class subject period treatment time;
model result = treatment time period subject treatment*time;
repeated time / type=CS subject=subject*period;
lsmeans treatment / pdiff=control;
lsmestimate Treatment*time 3 0 0 0.. -1 0 0 0.. 1 0 0 0.. 3 0 0 0;

SteveDenham
Jade | Level 19

On a guess, the code you got was appropriate for looking at a linear trend at the first timepoint, much like a slicediff option for the lsmeans statement in PROC GLIMMIX. The periods serve as missing placeholders for the other timepoints.  Note that SLICE or SLICEDIFF do not fit an orthogonal linear trend (-3 -1 1 3)

 

One thing I would recommend is to remove the term 'subject' from your MODEL statement.  As it is now, I would expect that there would be either no degrees of freedom remaining for the residual variation, a zero estimate for the residual variation or both.

 

If your interaction is significant, then you would look at an LSMESTIMATE statement that had the -3 -1 1 3 coefficients separately for each time point.  Suppose you had 3 time points.  The statement would then look like:

 

lsmestimate Treatment*time 'Linear treatment at time 1' -3 0 0  -1 0 0  1 0 0  3 0 0, 
                           'Linear treatment at time 2' 0 -3 0  0 -1 0  0 1 0  0 3 0,
                           'Linear treatment at time 3' 0 0 -3  0 0 -1  0 0 1  0 0 3';

 With more time points, this gets longer and you might want to consider using non-positional syntax.

 

SteveDenham

 

stats2554
Calcite | Level 5
I'm currently using the following code and am receiving the correct p-values for the overall treatment effect. can you provide any advice on the coefficients to use to get the correct overall linear treatment*time interaction p-value? I'm not interested in looking at individual timepoints unless the pooled overall Treatment*time effect is significant.
This is a crossover with 4 subjects/group, control + 3 treatment groups. 6 timepoints.

proc mixed data=Result;
class subject period treatment time;
model result = treatment time period subject treatment*time;
repeated time / type=CS subject=subject*period;
lsmeans treatment / pdiff=control;
lsmestimate Treatment 3 -1 1 3;
lsmestimate Treatment*time <need help with these coefficients>;
SteveDenham
Jade | Level 19

 

 

Here you go:

 

lsmestimate Treatment*time 'Linear treatment at time 1' -3 0 0 0 0 0  -1 0 0 0 0 0  1 0 0 0 0 0  3 0 0 0 0 0, 
                           'Linear treatment at time 2' 0 -3 0 0 0 0  0 -1 0 0 0 0  0 1 0 0 0 0  0 3 0 0 0 0,
                           'Linear treatment at time 3' 0 0 -3 0 0 0  0 0 -1 0 0 0  0 0 1 0 0 0  0 0 3 0 0 0,
                           'Linear treatment at time 4' 0 0 0 -3 0 0  0 0 0 -1 0 0  0 0 0 1 0 0  0 0 0 3 0 0,
                           'Linear treatment at time 5' 0 0 0 0 -3 0  0 0 0 0 -1 0  0 0 0 0 1 0  0 0 0 0 3 0,
                           'Linear treatment at time 6' 0 0 0 0 0 -3  0 0 0 0 0 -1  0 0 0 0 0 1  0 0 0 0 0 3/FTEST;

From the documentation: "The FTEST option produces an F test that joint test the rows of the LSMESTIMATE against zero." I assume that this is what you are looking for when you ask for the correct overall linear time by treatment interaction. Note that actually this is a time by linear treatment interaction F test. If you want a linear time by linear treatment overall test, it gets a bit more complicated.  We use a macro function to generate the string of coefficients.  In this case, the matrix is the cross product of the linear time vector, which for 6 timepoints is -5 -3 -1 3 5 and the linear treatment vector -3 -1 1 3; to get:

 

lsmestimate treatment*time 'linear treatment by linear time' 15 9 3 -3 -9 15  5 3 1 -1 -3 -5  -5 -3 -1 1 3 5  -15 -9 -3 3 9 15;

I hope you find this useful.

 

SteveDenham

stats2554
Calcite | Level 5

With the following code I'm receiving a LinTRT*time p-value of 0.1542 (should be 0.105 based on my reference).  Everything under the "Type 3 Tests of Fixed Effects" is accurate and so is the Linear treatment effect from the -3 -1 1 3 contrast.  Any ideas on what would be causing the p-value discrepancy?

 

data Result;
input treatment time subject period result baseline;
datalines;
1 1 1 1 112 109
1 2 1 1 113 109
1 3 1 1 105 109
1 4 1 1 111 109
1 5 1 1 102 109
1 6 1 1 111 109
1 1 2 8 102 105
1 2 2 8 103 105
1 3 2 8 106 105
1 4 2 8 104 105
1 5 2 8 107 105
1 6 2 8 101 105
1 1 3 15 98 99
1 2 3 15 95 99
1 3 3 15 94 99
1 4 3 15 96 99
1 5 3 15 92 99
1 6 3 15 94 99
1 1 4 22 102 106
1 2 4 22 109 106
1 3 4 22 105 106
1 4 4 22 113 106
1 5 4 22 113 106
1 6 4 22 111 106
2 1 1 22 112 112
2 2 1 22 112 112
2 3 1 22 109 112
2 4 1 22 113 112
2 5 1 22 109 112
2 6 1 22 113 112
2 1 2 1 105 101
2 2 2 1 108 101
2 3 2 1 99 101
2 4 2 1 103 101
2 5 2 1 98 101
2 6 2 1 104 101
2 1 3 8 96 96
2 2 3 8 96 96
2 3 3 8 96 96
2 4 3 8 99 96
2 5 3 8 99 96
2 6 3 8 94 96
2 1 4 15 101 106
2 2 4 15 108 106
2 3 4 15 111 106
2 4 4 15 114 106
2 5 4 15 105 106
2 6 4 15 110 106
3 1 1 15 118 114
3 2 1 15 111 114
3 3 1 15 113 114
3 4 1 15 111 114
3 5 1 15 110 114
3 6 1 15 113 114
3 1 2 22 105 112
3 2 2 22 115 112
3 3 2 22 110 112
3 4 2 22 117 112
3 5 2 22 112 112
3 6 2 22 108 112
3 1 3 1 95 92
3 2 3 1 93 92
3 3 3 1 95 92
3 4 3 1 100 92
3 5 3 1 93 92
3 6 3 1 93 92
3 1 4 8 107 109
3 2 4 8 115 109
3 3 4 8 113 109
3 4 4 8 112 109
3 5 4 8 113 109
3 6 4 8 105 109
4 1 1 8 117 112
4 2 1 8 106 112
4 3 1 8 111 112
4 4 1 8 109 112
4 5 1 8 108 112
4 6 1 8 106 112
4 1 2 15 112 113
4 2 2 15 110 113
4 3 2 15 112 113
4 4 2 15 109 113
4 5 2 15 108 113
4 6 2 15 109 113
4 1 3 22 104 96
4 2 3 22 92 96
4 3 3 22 95 96
4 4 3 22 92 96
4 5 3 22 98 96
4 6 3 22 92 96
4 1 4 1 109 107
4 2 4 1 110 107
4 3 4 1 107 107
4 4 4 1 109 107
4 5 4 1 106 107
4 6 4 1 108 107
;
Run;
proc mixed data=Result;
class subject period treatment time;
model result = baseline period subject treatment time treatment*time;
repeated time / type=CS subject=subject*period;
lsmeans treatment / pdiff=control;
contrast 'linear' treatment -3 -1 1 3;
lsmestimate Treatment*time 'Linear treatment at time 1' -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0 0 0,
'Linear treatment at time 2' 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0 0,
'Linear treatment at time 3' 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0,
'Linear treatment at time 4' 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0,
'Linear treatment at time 5' 0 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0,
'Linear treatment at time 6' 0 0 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3/FTEST;
run; quit;

SteveDenham
Jade | Level 19

I am not really sure what is causing the difference. It could be a difference in algorithm, such as a difference in whether Period is handled as another repeated measure, with time nested in period.  To check you might try the following:

 

proc mixed data=Result maxfunc=5000 convf=1e-6;
class subject period treatment time;
model result = baseline period subject treatment time treatment*time/ddfm=kr2;
repeated period time / type=UN@CS subject=subject;
lsmeans treatment / pdiff=control;
contrast 'linear' treatment -3 -1 1 3;
lsmestimate Treatment*time 'Linear treatment at time 1' -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0 0 0,
'Linear treatment at time 2' 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0 0,
'Linear treatment at time 3' 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0,
'Linear treatment at time 4' 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0,
'Linear treatment at time 5' 0 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0,
'Linear treatment at time 6' 0 0 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3/FTEST;
run; quit;

On my machine, the linear treatment at time 1 comes in with a P value of 0.0019, so I applied a multiplicity adjustment:

 

proc mixed data=Result maxfunc=5000 convf=1e-6;
class subject period treatment time;
model result = baseline period subject treatment time treatment*time/ddfm=kr2;
repeated period time / type=UN@CS subject=subject;
lsmeans treatment / pdiff=control;
contrast 'linear' treatment -3 -1 1 3;
lsmestimate Treatment*time 'Linear treatment at time 1' -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0 0 0,
'Linear treatment at time 2' 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0 0,
'Linear treatment at time 3' 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0 0,
'Linear treatment at time 4' 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0 0,
'Linear treatment at time 5' 0 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3 0,
'Linear treatment at time 6' 0 0 0 0 0 -3 0 0 0 0 0 -1 0 0 0 0 0 1 0 0 0 0 0 3/FTEST adjust=simulate(seed=1) stepdown adjdfe=row;
run; quit;

This gives an adjusted P value of 0.0109, which is within striking distance of the 0.0105 you are looking for, so it may have a different adjustment method

 

SteveDenham

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 10 replies
  • 3322 views
  • 1 like
  • 4 in conversation