BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
emaneman
Pyrite | Level 9

(Very) Dear community,

 

I have a PROC GLM with one class variable that has two levels, and I would like to get plots for the means for each condition.

I attach an example of the type of plot that I'd like, below .

 

Screenshot 2021-07-03 at 00.42.22.png

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

It is generally recommended to use dot plots with error bars (rather than bar charts) to plot a mean and confidence limits. This is built into PROC GLM. You can use the LSMEANS and PLOTS=MEANPLOT options to get the plot, as follows:

 

proc glm data=sashelp.class plots(only)=(meanplot(cl ascending)); /* plot of means and CIs */
class sex;
model Weight = sex;
output out=GLMOut Predicted=Pred lclm=lclm uclm=uclm;
lsmeans Sex / cl;
run;
quit;

If you insist on using a bar chart, then use ODS OUTPUT to capture the  LSMeanCL table, then use the techniques in the article "Creating bar charts with confidence intervals" to create the plot. It will look something like this:

ods trace on;
proc glm data=sashelp.class plots(only)=(meanplot(cl ascending)); /* plot of means and CIs */
   class sex;
   model Weight = sex;
   output out=GLMOut Predicted=Pred lclm=lclm uclm=uclm;
   lsmeans Sex / cl;
   ods output LSMeanCL=LS;
run;
quit;

proc sgplot data=LS;
vbarparm category=Sex response=LSMean /
    limitlower=LowerCL limitupper=UpperCL;
run;

As Peter Flom wrote in the comments to my blog post:

Bar charts with confidence intervals are also known as "dynamite plots" and for two reasons: 1) They look like the old dynamite things on cartoons and 2) They are dangerous. See http://biostat.mc.vanderbilt.edu/twiki/pub/Main/TatsukiRcode/Poster3.pdf for a good explanation of why they are bad. 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You can get close to this plot using one of the plotting options in PROC GLM, specifically ANOMPLOT or MEANPLOT. These won't match exactly what you show, but are specifically designed to provide meaningful graphics in the case where you are comparing means, so in that sense, the plots will be better than the plots you show.

 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/statug/statug_glm_syntax01.htm#statug.glm.cgl...

--
Paige Miller
Rick_SAS
SAS Super FREQ

It is generally recommended to use dot plots with error bars (rather than bar charts) to plot a mean and confidence limits. This is built into PROC GLM. You can use the LSMEANS and PLOTS=MEANPLOT options to get the plot, as follows:

 

proc glm data=sashelp.class plots(only)=(meanplot(cl ascending)); /* plot of means and CIs */
class sex;
model Weight = sex;
output out=GLMOut Predicted=Pred lclm=lclm uclm=uclm;
lsmeans Sex / cl;
run;
quit;

If you insist on using a bar chart, then use ODS OUTPUT to capture the  LSMeanCL table, then use the techniques in the article "Creating bar charts with confidence intervals" to create the plot. It will look something like this:

ods trace on;
proc glm data=sashelp.class plots(only)=(meanplot(cl ascending)); /* plot of means and CIs */
   class sex;
   model Weight = sex;
   output out=GLMOut Predicted=Pred lclm=lclm uclm=uclm;
   lsmeans Sex / cl;
   ods output LSMeanCL=LS;
run;
quit;

proc sgplot data=LS;
vbarparm category=Sex response=LSMean /
    limitlower=LowerCL limitupper=UpperCL;
run;

As Peter Flom wrote in the comments to my blog post:

Bar charts with confidence intervals are also known as "dynamite plots" and for two reasons: 1) They look like the old dynamite things on cartoons and 2) They are dangerous. See http://biostat.mc.vanderbilt.edu/twiki/pub/Main/TatsukiRcode/Poster3.pdf for a good explanation of why they are bad. 

emaneman
Pyrite | Level 9

Thank you! both are good.

I may take advantage of your expertise for one more step. The design is in fact more complex, with a nested factor that is random.

This is the syntax:

 

 proc glm data=ebal_st plots=(meanplot(cl ascending));
class genre author;
model lessico = genre author(genre) /effectsize;
output out=GLMOut Predicted=Pred lclm=lclm uclm=uclm;
lsmeans genre / cl;
random author(genre);
ods output LSMeanCL=LS;
run;
quit;
run;
quit;

 

SAS automatically outputs an additional graph, to plot the random factor, AUTHOR, see below. I am not sure why for some of the levels of the random factor AUTHOR it puts what seem to be error bars. I cannot find the documentation where this graph is explained. Any idea?

The graph is below.

 

Screenshot 2021-07-03 at 13.53.04.png

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 1712 views
  • 3 likes
  • 3 in conversation