Programming the statistical procedures from SAS

Trend Analysis in proc mixed

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Trend Analysis in proc mixed

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 . 


Accepted Solutions
Solution
‎07-14-2015 12:29 PM
Respected Advisor
Posts: 2,655

Re: Trend Analysis in proc mixed

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


All Replies
Respected Advisor
Posts: 2,655

Re: Trend Analysis in proc mixed

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

Contributor
Posts: 42

Re: Trend Analysis in proc mixed

Thanks so much!

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

Respected Advisor
Posts: 2,655

Re: Trend Analysis in proc mixed

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

Contributor
Posts: 42

Re: Trend Analysis in proc mixed

Thanks so much!

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

Contributor
Posts: 42

Re: Trend Analysis in proc mixed

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!

Solution
‎07-14-2015 12:29 PM
Respected Advisor
Posts: 2,655

Re: Trend Analysis in proc mixed

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

Contributor
Posts: 42

Re: Trend Analysis in proc mixed

Thanks so much! I really appreciate your great help!

Contributor
Posts: 42

Re: Trend Analysis in proc mixed

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;

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

Respected Advisor
Posts: 2,655

Re: Trend Analysis in proc mixed

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

Contributor
Posts: 42

Re: Trend Analysis in proc mixed

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.

Respected Advisor
Posts: 2,655

Re: Trend Analysis in proc mixed

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

Contributor
Posts: 42

Re: Trend Analysis in proc mixed

Thanks so much!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 938 views
  • 6 likes
  • 2 in conversation