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

proc mixed data= dataset ;

class id group;

model y= group time group*time / solution;

random int time/subject=id ;

estimate "trend test"  group*time 3 1 -1 -3/e cl divisor  = 3;

run;

Question:

variable group = 1,2,3,4, time is continuous time variable in years.

1. how to do the trend test in proc mixed for "group"?

2. how to calculate the contrast coefficients and value of divisor for this trend analysis?


Thank you . 

1 ACCEPTED SOLUTION

Accepted Solutions
SteveDenham
Jade | Level 19

Here's a link to orthogonal contrasts up through 7 equally spaced levels:

http://www.stat.ufl.edu/~winner/tables/orthpol.pdf

The actual process involves:

Sum the values of the levels (1 + 2 + 3 + 4) =10

Calculate the mean  10/4 = 2.5

Subtract the mean from each level's value ( 1-2.5  2-2.5  3-2.5  4-2.5) = (-1.5 -.5 .5 1.5)

'Integerize' by multiplying by a constant (here it is 2) = -3 -1 1 3, for an ascending linear contrast.

To get the quadratic, multiply each term by itself to get (9 1 1 9)

Calculate the mean  20/4 = 5

Subtract the mean from each level's value (9-5 1-5 1-5 9-5) = (4 -4 -4 4)

Integerize by dividing by a constant (here it is 4) = 1 -1 -1 1

To get the cubic, find a vector whose inner product with both the linear and quadratic is zero ( I haven't done this since first year linear algebra, so I don't have the steps).

It turns out to be -1 3 -3 1.

There is a great program written in IML to carry this out for any number of levels, and there is no need for equal spacing of the levels, either.

Steve Denham

View solution in original post

12 REPLIES 12
SteveDenham
Jade | Level 19

Several things here.  Do you want the trend test as a marginal test over all times included?  If so, consider using an LSMESTIMATE statement:

lsmestimate group 'trend test' 3 1 -1 3/cl divisor=3;

Use of continuous covariates in estimate statements would require something like:

estimate "trend test" group 3 1 -1 3 group*time 3 1 -1 3/cl divisor=3;

Now about the variable 'time'--is there any reason to suspect that measures on an individual id are correlated over time?  If so, some sort of covariance structure may be much more powerful than the random intercept-random slope model being fit.  This may be an excellent chance to examine a spline fit for the covariance structure.

Steve Denham

peppapig
Calcite | Level 5

Thanks so much!

How to understand the "3 1 -1 3" in the estimate statement?

SteveDenham
Jade | Level 19

Those are the coefficients that the lsmeans, or solution vector needs to be multiplied by.  You'll see that they are equally spaced and sum to zero.  And I apologize--in my previous post they should read '3 1 -1 -3", note well that the last term is -3.

Steve Denham

peppapig
Calcite | Level 5

Thanks so much!

For the "3 1 -1 -3", is there any formula or rule to calculate it?

peppapig
Calcite | Level 5

Can you recommend any documents (paper, book chapter...) about how to calculate the coefficients in this estimate statement for the trend test? Thank you so much!

SteveDenham
Jade | Level 19

Here's a link to orthogonal contrasts up through 7 equally spaced levels:

http://www.stat.ufl.edu/~winner/tables/orthpol.pdf

The actual process involves:

Sum the values of the levels (1 + 2 + 3 + 4) =10

Calculate the mean  10/4 = 2.5

Subtract the mean from each level's value ( 1-2.5  2-2.5  3-2.5  4-2.5) = (-1.5 -.5 .5 1.5)

'Integerize' by multiplying by a constant (here it is 2) = -3 -1 1 3, for an ascending linear contrast.

To get the quadratic, multiply each term by itself to get (9 1 1 9)

Calculate the mean  20/4 = 5

Subtract the mean from each level's value (9-5 1-5 1-5 9-5) = (4 -4 -4 4)

Integerize by dividing by a constant (here it is 4) = 1 -1 -1 1

To get the cubic, find a vector whose inner product with both the linear and quadratic is zero ( I haven't done this since first year linear algebra, so I don't have the steps).

It turns out to be -1 3 -3 1.

There is a great program written in IML to carry this out for any number of levels, and there is no need for equal spacing of the levels, either.

Steve Denham

peppapig
Calcite | Level 5

Thanks so much! I really appreciate your great help!

peppapig
Calcite | Level 5

Hi Steve,

Thanks for all your help. I really appreciate it.

For the trend test, I still have some questions.

For the three estimate statements below,they gave me different p values for the trend test.

How to interpret these three types of estimates statements? group values = 1,2,3,4.

group 3 1 -1 -3 group*time 3 1 -1 -3 in the 1st model

or group*time 3 1 -1 -3

or group 3 1 -1 -3 ?

Thank you so much.

****************************************************************

proc sort  data= data1 ;

by descending group;

run;

proc mixed data = data1 COVTEST NOITPRINT;

class haltid group(ref = "1");

model y =  time group time* group/solution cl;

random int /subject = id type = un;

estimate "trend test"  group 3 1 -1 -3 group*time 3 1 -1 -3/e cl divisor=2;

run;

proc mixed data = data1 COVTEST NOITPRINT;

class haltid group(ref = "1");

model y =  time group time* group /solution cl;

random int /subject = id type = un;

estimate "trend test" group*time 3 1 -1 -3/e cl divisor=2;

run;

proc mixed data = data1 COVTEST NOITPRINT;

class haltid group(ref = "1");

model y =  time group time* group /solution cl;

random int /subject = id type = un;

estimate "trend test"  group 3 1 -1 -3/e cl divisor=2;

run;

****************************************************************

SteveDenham
Jade | Level 19

You can see the differences in each of the estimate statements by looking at the L matrix that the /e option provides.  The last provides an estimate averaged over all time points.  The next to last provides an estimate of the trend in group at the first time point.  The first, well, it is a mixture of things that really don't make sense to me.

This truly looks to me like a case where you might benefit from the use of the LSMESTIMATE statement, which provides estimates of linear combinations of the marginal means (lsmeans).  The syntax is much clearer, in the sense that you can easily construct the linear combination that you are really interested in, and that it relies solely on a combination of the lsmeans, thus eliminating a lot of the confusion necessary to construct correct ESTIMATE statements.

Steve Denham

peppapig
Calcite | Level 5

Thanks so much!

how to understand that:


estimate "trend test" group*time 3  1 -1 -3/e cl divisor=2;  group * time is for" estimate of the trend in group at the first time point."?

and

estimate "trend test"  group 3  1 -1 -3/e cl divisor=2; is for " provides an estimate averaged over all time points" ?

Thank you.

SteveDenham
Jade | Level 19

Again, examine the coefficients that are in the output for each of these estimates to see what is happening.

To put this on a more intuitive level, you really should consider changing from ESTIMATE statements to LSMESTIMATE statements.  The latter are for trends in the marginal means, which is what your analysis should be trying to discover.

Steve Denham

peppapig
Calcite | Level 5

Thanks so much!

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 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
  • 12 replies
  • 5657 views
  • 7 likes
  • 2 in conversation