BookmarkSubscribeRSS Feed
sliaousa
Fluorite | Level 6

Hi, 

 

I am running a "Constrained Longitudinal Data Analysis" using PROC MIXED model with repeated measurements and a list of covariates (including both class and continuous ones) and am having problem writing the LSMEANS statement to output the lsmeans with specific condition for the covariates. 

The objective is to obtain the LS means for trtpn=1 at week2, at week 4, at week 8,..  and just use the means for the other covariates. Also want to obtain the LS means for trtpn=2 at week2, week4...., etc.

 

Here is my data look like:

*** For cLDA, need to create dummy trt variables for each week, only when trtpn=1 then these trt variables will be assigned as 1; 

data A;
set A;
if (trtpn=1 and week=2) then trtwk2=1; else trtwk2=0;
if (trtpn=1 and week=4) then trtwk4=1; else trtwk4=0;
if (trtpn=1 and week=8) then trtwk8=1; else trtwk8=0;
if (trtpn=1 and week=12) then trtwk12=1;else trtwk12=0;
if (trtpn=1 and week=16) then trtwk16=1;else trtwk16=0;
if (trtpn=1 and week=20) then trtwk20=1;else trtwk20=0;
run;

 

sliaousa_1-1686761549613.png

 

I tried several codes in PROC MIXED and none worked yet. Below is one with no error message but the output is all missing:

PROC MIXED DATA=A;
        CLASS subjid WEEK(ref=first) trtwk2 trtwk4 trtwk8 trtwk12 trtwk16 trtwk20 SOO UOR;
by category2 category biomarker;
        MODEL LOG_VALUE_N = WEEK trtwk2 trtwk4 trtwk8 trtwk12 trtwk16 trtwk20 BALSFRS BASESLOPE TSS SOO UOR/SOLUTION DDFM=KENWARDROGER;
        REPEATED WEEK/SUBJECT=SUBJID TYPE=UN;
 
estimate 'trt1 for week=2' trtwk2 1 week 1 0 0 0 0 0 ;
estimate 'trt2 for week=2' trtwk2 0 week 1 0 0 0 0 0 ;
        ODS OUTPUT 
  estimates=estimates;
 run;
 
sliaousa_3-1686762371021.png

 

 
Here is another with error message: 
PROC MIXED DATA=adalsencals;
        CLASS subjid WEEK(ref=first) trtwk2 trtwk4 trtwk8 trtwk12 trtwk16 trtwk20 SOO UOR;
by category2 category biomarker;
        MODEL LOG_VALUE_N = WEEK trtwk2 trtwk4 trtwk8 trtwk12 trtwk16 trtwk20 BALSFRS BASESLOPE TSS SOO UOR/SOLUTION DDFM=KENWARDROGER;
        REPEATED WEEK/SUBJECT=SUBJID TYPE=UN;
LSMEANS WEEK*TRTWK2;
RUN;
 
sliaousa_2-1686762090737.png

 

        ODS OUTPUT 
  lsmeans=lsmeans;
 run;

 

Please let me know how to write the statements in PROC MIXED to get the desired lsmeans?

 

Thanks,

Aurora

5 REPLIES 5
PaigeMiller
Diamond | Level 26

The first problem can be avoided by not using the ESTIMATE statement here. The ESTIMATE statement is useful when the coefficients are not all 0 or 1. For example if you want to estimate the effect of 2*TRTWK2 - TRTWK4/3, then you have coefficients in the estimate logic that are not 0 or 1. If they are all 0 or 1, use the LSMEANS statement to obtain these values. SAS has done the hard work of getting the underlying math right in such a case, so you don't have to.

 

The error message is because the interaction WEEK*TRTWK2 does not appear in the model statement.

 

The objective is to obtain the LS means for trtpn=1 at week2, at week 4, at week 8,..  and just use the means for the other covariates.

 

If you are in a situation where you need to use LS Means for one variable, then you need to use it for all variables.

--
Paige Miller
StatDave
SAS Super FREQ

I don't think you need to create dummy variables - that is what the CLASS statement is for. So, it seems like your code could be simplified and might work if your CLASS is like

CLASS subjid week trtpn SOO UOR;

and your MODEL statement is like

MODEL LOG_VALUE_N = trtpn week trtpn*week BALSFRS ... ;

and then use your LSMEANS statement 

lsmeans trtpn*week;
sliaousa
Fluorite | Level 6

The trtp*week is the usual MMRM model we ran and we are trying this "constrained longitudinal data analysis (cLDA)" model as comparison and cLDA, we will need to use these dummy variables before running in PROC MIXED. Noticed in this PROC MIXED, trtpn is not included anymore.

 

Just to clarify the LSmeans we would like to obtain is for trtpn=1 at each of the weeks and the coefficients for the continuous variables will follow SAS LSMEANS defaul: 

sliaousa_0-1686767434360.png

 

I am struggling to write the statements (either using LSMEANS or ESTIMATE) to get the LSmeans we want...

StatsMan
SAS Super FREQ

Since you have created your own dummies, not sure you want those on the CLASS statement. 

I think you are pretty close with your ESTIMATE statement. A common mistake is to not include the intercept term in the estimate. I ran the following simulation

data test;
   call streaminit(9871534);
   do id = 1 to 50;
      x1=rand("normal");
      trt=ceil(rand("uniform")*2);
      do time=1 to 3;
         x2=rand("normal");
         if time=1 and trt=1 then trt1=1; else trt1=0;
         if time=2 and trt=1 then trt2=1; else trt2=0;
         if time=3 and trt=1 then trt3=1; else trt3=0;
         y=x1 + x2 + trt*time + rand("normal");
         output;
   end; end;
run;

proc mixed data=test;
   class time;
   model y=time trt1 trt2 trt3 x1 x2;
   estimate "trt1 and time1" int 1 time 1 trt1 1  / e;
   lsmeans time / at trt1=1 e;
run;

The ESTIMATE statement gives you estimate you suggest in your write-up. Notice, though, that the covariates for X1 and X2 are zero-ed out. If you want to evaluate the estimate at values other than 0 for your covariates, you would need to add those to your ESTIMATE statement. The LSMEANS statement is doing something similar, but evaluating all the covariates at their means. Including the covariates TRT2 and TRT3. 

xuyi
Fluorite | Level 6

StatDave codes work well. You don't need dummy variables. Especially dummy variable for treatment and time interaction term will not work.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 1739 views
  • 3 likes
  • 5 in conversation