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;
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);
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.
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?
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.
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.
Thank you Dave. I will indeed have to find a way around it.
@Rick_SAS do you have any advice?
Yes, I suggest you post sample data.
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 ;
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;
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* ??/
@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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.