BookmarkSubscribeRSS Feed
emaneman
Pyrite | Level 9

hello all.

I could use some help with plotting interactions and a main effect with proc plm, from a store produced with proc mixed.

The syntax is included.

The effectplot in the PLM gives me the three way interaction plotted as i want, but only for males (sesso=m)  -- see attached image. 

It seems that since categorical variable sesso is in the model, proc plm chooses to plot the requested interaction at one of the two levels of it. 

Can I get PLM to plot the three way interaction between the three other variables (two continuous and one categorical) for the whole sample, that is, for men and women together?  I attach a figure of the current output, and the SAS syntax.

 

 

proc mixed ic data=mls2;
class id gruppo2 scuola classe luogo sesso;
model cas2= 	gruppo2|cas1|sesso|ageyears;
Random intercept  /subject=classe;
Random intercept  /subject=scuola;
Random intercept  /subject=luogo;
lsmeans gruppo2 /pdiff;
store sunday2;
run;quit;


proc plm source=sunday2;
	   effectplot slicefit (x=cas1 sliceby=gruppo2 plotby=ageyears=-1 1)/ clm;
   
run;

 

 

Screenshot 2021-12-12 at 15.46.34.png

 

21 REPLIES 21
StatDave
SAS Super FREQ

Either use an interaction in PLOTBY or use the AT option:

effectplot slicefit(x=cas1 sliceby=gruppo2 plotby=ageyears) / at(sesso=all);
effectplot slicefit(x=cas2 sliceby=gruppo2 plotby=ageyears*sesso);
emaneman
Pyrite | Level 9

using the / AT option gives me the plots by sex, not a single plot including both males and females.

the second suggestion does not work either, because ageyears is a continuous variable. But even if it worked, the problem would be the same, namely that it would give me different plots for males and females. 

Since I have no interaction effects involving sex, i would like the plots NOT to be divided by sex.

StatDave
SAS Super FREQ
The vertical bars between all of the variables means you have several interactions involving sex. You have a choice of either separate plots or separate lines involving sex - the latter if you specify sliceby=gruppo*sesso.
emaneman
Pyrite | Level 9

What I mean is that no interaction involving sex is statistically significant. So I do not want separate plots for the two sex levels.

Is there a way to do that?

StatDave
SAS Super FREQ
As long as sex is in the model it obviously must affect the predicted values. So, the only way an effect plot will not involve sex at all is to remove it from the model.
emaneman
Pyrite | Level 9

That is not the case. Even if sex were to have significant interaction effects, one may want to plot interaction effects between other variables for men and women together, not separately. This is easily achievable when the "third" variable is  continuous variable, either by default or by specifying the average level of the continuous variable.  

StatDave
SAS Super FREQ

Since it's true that different predicted values are produced depending on the sex value, what you want amounts to averaging the two values from the two sexes at any given setting of the other variables. This isn't possible with the EFFECTPLOT statement. If all of the predictors were CLASS variables, then this could be relatively easy by specifying the 3-way interaction that omits sex in the LSMEANS statement, saving the predicted values with an ODS OUTPUT statement, and then creating the plot as desired using PROC SGPLOT. Since some of the variables are continuous, it would require some programming to generate a data set of settings to score, averaging the scores within each 3-way setting, and then plotting.

emaneman
Pyrite | Level 9

Thank you Dave. I will indeed have to find a way around it. 

emaneman
Pyrite | Level 9

@Rick_SAS do you have any advice?

Rick_SAS
SAS Super FREQ

Yes, I suggest you post sample data.

 

emaneman
Pyrite | Level 9

Wonderful! Here you go, syntax and attached dataset in sas format.

 

proc mixed ic data=giunti.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;
lsmeans Condition sex/cl  ;
lsmeans sex/cl;
   effectplot slicefit (x=cas1 sliceby=Condition plotby=ageyears=-1 1)/ clm ;
Rick_SAS
SAS Super FREQ

It sounds like you just want to overlay the graphs that you get with @(sex='Male') and @(sex='Female')@@

 

If that is the case, you can do either of the following:

1. Score the model on a uniform grid of CAS1 values. Use the OUTPREDM= option on the MODEL statement in PROC MIXED to output the predicted values. Use PROC SGPANEL to graph the results. The details are provided in the article "Visualize a mixed model that has repeated measures or random coefficients."

2. Use ODS OUTPUT to save the data model the underlies the graphs that are produced by the EFFECTPLOT statements. Merge the data. Use PROC SGPANEL to graph the results.

 

The following implements the second approach. Hope this helps. 

 

/* save the prediction for males */
proc plm source=storecas;
ods output SliceFitPanel=Males;
effectplot slicefit (x=cas1 sliceby=Condition plotby=ageyears=-1 1)/ clm at(sex="Male");
run;
/* save the predictions for females */
proc plm source=storecas;
ods output SliceFitPanel=Females;
effectplot slicefit (x=cas1 sliceby=Condition plotby=ageyears=-1 1)/ clm at(sex="Female");
run;

/* merge the males and females; create a new Group variable that has four levels
   and combines the levels of the 'Condition' and 'Sex' groups */   
data AllSex;
length Sex $6 Group $21;  /* length(group)=length(Condition)+length(sex)+2 */
set Males(in=M) Females;
if M then Sex="Male  ";
else Sex = "Female";
Group = catx("; ", _Group, Sex); /* example: 'Control; Male' */
run;

title "Fit for CAS2";
proc sgpanel data=AllSex;
   panelby _PlotBY;
   band x=_XCont1 lower=_LCLM upper=_UCLM / group=Group transparency=0.5;
   series x=_XCont1 y=_Predicted / group=Group;
   rowaxis grid;
   colaxis grid;
run;
emaneman
Pyrite | Level 9

Hello Rick, and thanks. 

The second approach still gives me the slopes separately for males and females, and that is what I am trying to avoid. In other words, I want to plot a 3-way, not a 4-way interaction. 

 

I tried with first approach (OUTPRED), but THEN I need to specify the two panels as low and high age (ageyears -1 and 1, since it is standardized).

When I use the LSMEANS output it can be done, since i output LSmeans at  ageyears = -1 and 1. But when I used the OUTPRED, of course ageyears is still continous, and I do not think there is a way to use a continuous variable in PANELBY and have the two panels be specific values of the continuous variables.   In the article "Visualize a mixed model that has repeated measures or random coefficients."   there is no SGPANEL example. I can use SGPLOT (see syntax below), and it gives me the two way interaction between CONDITION  and CAS1 (see attached graph), but I cannot see how I could obtain the same two-way plotted separately for high (1) and low (-1) levels of the variable ageyears - which is what I need. 

 

proc SGPLOT data=pred;
 reg x=cas1 y=Pred / group=condition  clm ;
 /*how to specify i want the above separately for ageyears= -1 and ageyears = 1* ??/

 

Rick_SAS
SAS Super FREQ

 @StatDave already answered this question. Please reread his responses. If you want to plot the predicted values when sex is ignored, use the following:


ods exclude all;
proc mixed ic data=giunti.mls2;
class id Condition scuola classe luogo sex;
model cas2= 	Condition|cas1|ageyears;
Random intercept  /subject=classe;
Random intercept  /subject=scuola;
Random intercept  /subject=luogo;
lsmeans Condition /pdiff cl;
store storecasNOSEX;
run;quit;
ods exclude none;

/* save the prediction for males */
proc plm source=storecasNOSEX;
ods select SliceFitPanel;
effectplot slicefit (x=cas1 sliceby=Condition plotby=ageyears=-1 1)/ clm;
run;

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
  • 3143 views
  • 3 likes
  • 3 in conversation