BookmarkSubscribeRSS Feed
emaneman
Pyrite | Level 9

That is not the same model.  I need to include SEX in the model; of course the pred values change if I do not. 

I need the model with the four predictors, but then plot the 3-way interaction.

Rick_SAS
SAS Super FREQ

To answer your most recent question: When you set up the data set that you use to score the model, first output the scoring data for ageyears=-1. Then repeat the output for ageyears=+1.

 

You can use PROC SGPANEL or a BY statement to get separate graphs for each level. 

proc SGPLOT data=pred;
reg x=cas1 y=Pred / group=condition  clm ;
by ageyears;  /*how to specify i want the above separately */
run;

 

You might want to read the following articles:

Visualize multivariate regression models by slicing continuous variables

How to create a sliced fit plot in SAS

I think the second article might be most similar to your situation. 

emaneman
Pyrite | Level 9

I am taking too much of your time... 

I do not see how I could "output the scoring data for ageyears=-1. Then repeat the output for ageyears=+1." using outpred. I can of course do this using LSMEANS, but then I run into the problem of not being able to "merge" men and women. I feel like I am in a catch 22!

Rick_SAS
SAS Super FREQ

Show the code you are using the create the scoring data set and to evaluate the model on the scoring data.

StatDave
SAS Super FREQ

As I summarized in my Monday post, if you want the plot to not involve sex then you will need to average over the two predicted values from the two sexes within each combination of the other three predictors in the model. I laid out the general approach in that post. This code implements and produces the plot.

proc mixed ic data=mls2;
class id Condition scuola classe luogo sex;
model cas2= 	Condition|cas1|sex|ageyears;
Random intercept  /subject=classe;
Random intercept  /subject=scuola;
Random intercept  /subject=luogo;
store storecas;
run;quit;
data new; 
do condition='Reading Aloud','Control'; 
do sex='Female','Male'; 
do cas1=-3.5,0,3.5; 
do ageyears=-1,1; 
 output;
end; end; end; end; 
run;
proc plm restore=storecas;
score data=new out=out;
run;
proc means nway data=out; 
class condition cas1 ageyears; 
var predicted; 
output out=out2 mean=; 
run;
proc sgpanel; 
panelby ageyears;
series y=predicted x=cas1 / group=condition;
run;

SGPanel11.png

StatDave
SAS Super FREQ

The general solution to this sort of problem is to use predictive margins. Margins are averages of predicted values and are what the code in my last post computed. Unlike LS-means, margins are not computed as linear combinations of model parameters. As such, an LS-mean fixes all of the predictors in the model to specific values. A predictive margin uses the actual values of the predictors and the resulting predicted values they generate for each observation. LS-means are a special case of margins. However, as I noted earlier, the LSMEANS statement only allows CLASS variables to be specified.

 

Margins can more easily be estimated using the Margins macro. The macro both fits the model of interest and computes the desired margins. It also computes appropriate standard errors and confidence limits which could not be easily added to my previous code. The macro uses PROC GENMOD to fit the model, and while it does not fit mixed models, it can fit Generalized Estimating Equations (GEE) models which can handle clustered data. It appears that a GEE model with clusters defined by the CLASSE levels gives very similar results to your mixed model. Unlike the LSMEANS statement, the macro allows the margin variables to be either CLASS or continuous variables. However, if a margin variable is continuous and has many levels, you generally will want to specify the specific levels to use when computing margins.

 

The following code creates a data set that defines the combinations of the three-way interaction for which margins will be computed. The Margins macro then fits the GEE model and provides margin estimates and confidence limits. The margins are then plotted and confidence bands are added.

data md; 
   do condition='Reading Aloud','Control'; 
   do ageyears=-1,1; 
   do cas1=-3.5,0,3.5; 
    output;
   end; end; end;  
   run;
%Margins(data=mls2, 
         class=Condition sex classe,
         response=cas2, 
         model=Condition|cas1|sex|ageyears,
         geesubject=classe, geecorr=exch,
         margins=Condition*cas1*ageyears, 
         margindata=md, 
         options=cl)
proc sort data=_margins out=mplot; 
   by condition cas1;
   run;
proc sgpanel data=mplot; 
   panelby ageyears;
   band x=cas1 upper=upper lower=lower / group=condition transparency=.8;
   series y=estimate x=cas1 / group=condition;
   run;

SGPanel5.png

emaneman
Pyrite | Level 9

Dear @StatDave  @Rick_SAS 

many, many thanks for all the suggestions. 

In the end, I found this solution with PROC PLM/EFFECTPLOT, which seems the simplest to implement. It consists in adding a coding for the class variable sex, based on the proportion of the its two values in the dataset. See code here and attached the output, which is identical to what I Dave posted.

Eman

 

proc mixed ic data=MLS2;
class id Condition scuola classe luogo sex;
model cas2= Condition|cas1|sex|ageyears /;
Random intercept /subject=classe;
Random intercept /subject=scuola;
Random intercept /subject=luogo;
lsmeans Condition /pdiff cl;
store storecas;
run;quit;


proc plm source=storecas;
effectplot slicefit (x=cas1 sliceby=Condition )/ clm smooth AT(sex(coded)=0.4475 0.5525, ageyears=-1 1);

 

 

 

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
  • 21 replies
  • 3140 views
  • 3 likes
  • 3 in conversation