Producing High Resolution Graphics using SAS Graph in Programming | STA 402, Study notes of Statistics

Material Type: Notes; Professor: Bailer; Class: Statistical Programming; Subject: Statistics; University: Miami University-Oxford; Term: Fall (First Sem) 2008;

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-o21
koofers-user-o21 🇺🇸

9 documents

1 / 36

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Week 06-07 [15+ Oct.] Class Activities
File: week-06-07-14oct08-SAS-GRAPH.doc
Directory: \\Muserver2\USERS\B\\baileraj\Classes\sta402\handouts
Producing High-Resolution Graphics using SAS/Graph
6. Higher-Resolution Graphics
6.1. G* parallels to line printer graphics
6.2 ODS stat graphics
6.3. Customizing graphics – selecting symbols, color control, axis alteration, etc.
6.4. Why you need to learn about annotate data sets
6.5. Case study: comparing distributions of responses
6.6. Statistical Graphics – entering the land of SG*
6.7 Multi-panel plots and other challenges
6.8 Summary
6.1. G* parallels to line printer graphics
Display 6.1: Histograms and scatterplots of the nitrofen young data produced using
CHART-GCHART and PLOT-GPLOT.
data nitrofen;
infile
'\\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\data\ch2-
dat.txt' firstobs=16 expandtabs missover pad ;
input @9 animal 2. @17 conc 3. @25 brood1 2.
@33 brood2 2. @41 brood3 2. @49 total 2.;
ods rtf bodytitle;
proc chart;
title "proc CHART";
hbar total / subgroup=conc;
run;
proc gchart;
title "proc GCHART";
hbar total / subgroup=conc;
run;
proc plot;
title "proc PLOT";
plot brood1*conc="1" brood2*conc="2" brood3*conc="3" /
overlay vaxis=0 to 20 by 2;
run;
proc gplot;
title "proc GPLOT";
plot brood1*conc="1" brood2*conc="2" brood3*conc="3" /
overlay vaxis=0 to 20 by 2;
run;
ods rtf close;
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download Producing High Resolution Graphics using SAS Graph in Programming | STA 402 and more Study notes Statistics in PDF only on Docsity!

Week 06-07 [15+ Oct.] Class Activities

File: week-06-07-14oct08-SAS-GRAPH.doc

Directory: \Muserver2\USERS\B\baileraj\Classes\sta402\handouts

Producing High-Resolution Graphics using SAS/Graph

6. 6.1. Higher-Resolution GraphicsG* parallels to line printer graphics

6.2 6.3. ODS stat graphicsCustomizing graphics – selecting symbols, color control, axis alteration, etc.

6.4. 6.5. Why you need to learn about annotate data setsCase study: comparing distributions of responses

6.6. 6.7 Statistical Graphics – entering the land of SG*Multi-panel plots and other challenges

6.8 Summary

6.1. G* parallels to line printer graphics

Display 6.1: Histograms and scatterplots of the nitrofen young data produced using CHART-GCHART and PLOT-GPLOT.

data nitrofen; infile '\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\data\ch2- dat.txt' firstobs=16 expandtabs missover pad ; input @9 animal 2. @33 brood2 2. @41 brood3 2. @49 total 2.; @17 conc 3. @25 brood1 2. ods rtf bodytitle; proc chart; title "proc CHART"; hbar total / subgroup=conc; run; proc gchart; title "proc GCHART"; hbar total / subgroup=conc; run; proc plot; title "proc PLOT"; plot brood1conc="1" brood2conc="2" brood3conc="3" / run;^ overlay vaxis=0 to 20 by 2; proc gplot; title "proc GPLOT"; plot brood1conc="1" brood2conc="2" brood3conc="3" / overlay vaxis=0 to 20 by 2; run; ods rtf close;

Display 6.2: Separate histograms for each concentration produced by PROC CHART for the

nitrofen young data total Cum. Cum.

Midpoint (^) ‚ Freq Freq Percent Percent 0 ‚33 ‚ 1 1 2.00 2. 6 ‚223333333333333333 ‚ 9 10 18.00 20. 12 ‚2222 ‚ 2 12 4.00 24. 18 ‚22222233 ‚ 4 16 8.00 32. 24 ‚00881111222222 ‚ 7 23 14.00 46. 30 ‚0000000088888888111111111111111122 ‚ 17 40 34.00 80. 36 ‚00000000008888888888 ‚ 10 50 20.00 100. Šƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒƒˆƒƒ 2 4 6 8 10 12 14 16 Frequency Symbol conc Symbol conc Symbol conc 02 2350 83 31080 1 160

Display 6.3: Separate histograms for each concentration produced by nitrofen young data PROC GCHART for the

proc GCHART

conc 0 80 160 235 310

FREQ. FREQ.CUM. PCT. CUM.PCT. 1 1 2 2 9 10 18 20 2 12 4 24 4 16 8 32 7 23 14 46 17 40 34 80 10 50 20 100

total MIDPOINT

36

30

24

18

12

6

0

FREQUENCY

0 2 4 6 8 10 12 14 16 18

Display 6.5: Separate scatterplots for each brood size vs. concentration produced by PROC

GPLOT for the nitrofen young data

brood

0

2

4

6

8

10

12

14

16

18

20

conc

0 100 200 300 400

proc GPLOT

1

1111111 1

(^1 )

1

1

1

1 1 1

11 1

1111111 1

1 1

1111 1

11 111

1

111111

2 222

(^22) 22 22 2

2222 22

222 22 2

22

(^22) 2

22 2 2

2

2

2

22

2

2

2 2222

2

22222

3

3

3 3333 (^33)

3

33

3 (^33) (^33) 3

33 33

3 3

(^333) 333

(^33)

3

3

3

3 3

3 3

3

3333333333

5.2. ODS stat graphics

Display 6.6: (Example 5.2 revisited) ODS graphics with simple linear regression: Manatee deaths over years 77-

data manatee_deaths; input year nboats manatees @@; 77 447 13^ datalines; 78 460 21 79 481 24 80 498 16 81 513 24 85 585 33 82 512 2086 614 33 83 526 1587 645 39 84 559 3488 675 43 89 711 50 ; 90 719 47 ODS RTF bodytitle; ODS graphics on; proc reg data=manatee_deaths; title ‘Number of Manatees killed regressed on the number of boats registered in Florida’; model manatees = nboats; run; ODS graphics off; ODS RTF CLOSE;

Display 6.7: ODS Stat Graphics with PROC REG Fit Diagnostics

Display 6.10: Multiple regression for examining big brains and big bodies (revisited)

data mrexample; * Lunneborg (1994) - body weight brain example; input species $ bodywt brainwt @@; logbody = log10(bodywt); logbrain = log10(brainwt); * transform the weights; idino = 0; if (species="diplodoc" or species="tricerat" or species="brachios") then * define the indicator of dinosaurs; idino=1;

beaver 1.35 8.10 cow 465.00 423.00 wolf 36.33 119.50 goat 27.66 115.00^ datalines; guipig 1.04 5.50 diplodocus 11700.00 50.00 asielephant 2547.00 4603.00 donkey 187.10 419.00 horse 521.00 655.00 potarmonkey 10.00 115. cat 3.30 25.60 giraffe 529.000 680.00 gorilla 207.00 406.00 human 62.00 1320.00 afrelephant 6654.00 5712.00 triceratops 9400.00 70. rhemonkey 6.80 179.00 kangaroo 35.00 56.00 hamster 0.12 1.00 mouse 0.023 0.40 rabbit 2.50 12.10 sheep 55.50 175. jaguar 100.00 157.00 chimp 52.16 440.00 brachiosaurus 87000.00 154.50 rat 0.28 1.90 mole 0.122 3.00 pig 192.00 180 ;

ODS RTF bodytitle; ODS graphics on;

proc reg; title2 ‘Dinosaurs fitted with potentially different INTERCEPTS’; * different intercepts;

run;^ model logbrain=logbody idino; ODS graphics off; ODS RTF CLOSE;

Display 6.11: ODS Stat Graphics for Proc REG residual plot –predicting log10(brain weight) from log10(body weight) and dinosaur indicator

Display 6.13: ODS Stat Graphics for one-way anova – boxplot with mean comparison

Display 6.14 ODS Stat Graphics for one-way anova – mean comparisons

Display 6.16: Toss a digital coin – long-term relative frequency of “heads” (Prettier) data cointoss;

retain num_heads 0; call streaminit(1234567); do itoss = 1 to 1200; outcome = RAND('Bernoulli', 0.50); num_heads = num_heads + (outcome=1); probability_heads = num_heads / itoss ; end;^ output; goptions reset=global; symbol interpol=join; axis1 order=0.35 to 0.65 by 0.05 label=(angle=90 "Estimated Pr(HEADS)"); axis2 order=0 to 500 by 50 label=("Number of simulated data points"); ods rtf bodytitle; proc gplot; plot probability_heads*itoss / vaxis=axis1 haxis=axis2; run; ods rtf close;

Display 6.17: (Prettier) Plot of relative frequency of heads as a function of number of tosses of a fair coin

Estimated Pr(HEADS)

Number of simulated data points

0 50 100 150 200 250 300 350 400 450 500

Display 6.18: (More publication ready) Plot of relative frequency of heads as a function of number of tosses of a fair coin

Estimated Pr(HEADS)

Number of simulated data points

0 50 100 150 200 250 300 350 400 450 500

Display 6.20: Contents of the annotate data set for enhancing the long-term relative frequencyfigure

Obs function Text xsys ysys x y

1 move 2 2 0 0.

2 draw 2 2 500 0.

3 label Long-term relative frequency of HEADS=0.50 2 2 350 0.

Display 6.21: Plot of relative frequency of heads as a function of number of tosses of a fair coin with annotation

Estimated Pr(HEADS)

Number of simulated data points

0 50 100 150 200 250 300 350 400 450 500

Long-term relative frequency of HEADS=0.

Display 6.22: Illustrating the construction of a CI for an odds ratio based on exponentiating the CI for log[OR]

/* generate a profile of [OR, log(OR)] values */ data or_stuff; do or=0.01 to 5 by .01; logor = log(or); end;^ output; goptions reset=global; * often a good idea, especially if doing lot of graphs;

/* interpolate btwn [OR, log(OR)] values and set up axes */ symbol interpol=join; axis1 label=("Odds Ratio"); axis2 label=(angle=90 "Log(Odds Ratio)" );

/* set up annotate data set with arrows and text to illustrate the CI idea / data myanno; length function $ 5 text $ 7; retain xsys "2" ysys "2" function SE; SE = .2; function="move"; x=2; y=-5; output; function="arrow"; x=2; y=log(2); line=2; output; from OR to logOR; function="arrow"; x=.01; y=log(2); output; * back to y-axis; function="draw"; function="arrow"; x=exp(log(2)+ 1.96SE); y=log(2)+ 1.96SE; output; x=.01; y=log(2)+ 1.96SE; output; * upper CI; function="arrow"; x=exp(log(2)+ 1.96SE); y=-4.5; output; function="move"; function="draw"; x=.01; y=log(2); output;x=.01; y=log(2)- 1.96SE; output; * lower CI; function="arrow"; x=exp(log(2)- 1.96SE); y=log(2)- 1.96SE; output; function="arrow"; x=exp(log(2)- 1.96SE); y=-4.5; output; function="label"; x=exp(log(2)- 1.96SE); y=-4.75; text="LCL OR"; output; x=exp(log(2)+ 1.96SE); y=-4.75; text="UCL OR"; output; x=2.2; y=-2; text="Step 1 "; output; x=1; y=log(2) + .25; text=" Step 2 "; output; x=0.5; y= log(2)- 1.96SE - .25; text="Step 3a"; output; x=0.5; y= log(2)+ 1.96SE + .25; text="Step 3b"; output; x=3.2; y=-2; text="Step 4a"; output;

text;^ x=1.2; y=-2; text="Step 4b";^ position="<"; output; * right justify /* render the figure with annotation */ ods rtf bodytitle; proc gplot data=or_stuff; plot logor * or / annotate=myanno haxis=axis1 vaxis=axis2;

ods rtf close;^ run;

6.5. Case study: comparing distributions of responses

Display 6.24: SAS code to generate scatterplots of total number of young versus nitrofen concentration with either superimposed means or superimposed boxplots

/* load the nitrofen data until a SAS data set / data nitrofen; infile '\Muserver2\USERS\B\BAILERAJ\public.www\classes\sta402\data\ch2- dat.txt' firstobs=16 expandtabs missover pad ; input @9 animal 2. @17 conc 3. @25 brood1 2. @33 brood2 2. @41 brood3 2. @49 total 2.; jconc = conc + 15ranuni(0) - 7.5; * adding a little jitter to see points; proc print data=nitrofen; run; proc means data=nitrofen; var total; * obtain means that are hard coded below; class conc; run;

/* FIGURE 1: Scatterplot with superimposed segments at group means / / set up axes and suppress the x-axis tick marks and labels / goptions reset=global; axis1 label=(angle=90 'Total number of young (3 broods)'); axis2 label=('Nitrofen Concentration') order=(-20 to 340 by 20) minor=none major=none v=none; / define annotate data set to draw mean segments and nitrofen conc. / data myanno; length function $ 5 text $ 3; retain xsys '2' ysys '2'; function="label"; x=0; y=2; text="0"; output; function="label"; x=80; y=2; text="80"; output; function="label"; x=160; y=2; text="160"; output; function="label"; x=235; y=2; text="235"; output; function="label"; x=310; y=2; text="310"; output; function='move'; x= 0 - 15; y=31.4; output; * conc=0; function='draw'; x= 0 + 15; function='move'; x= 80 - 15; y=31.4; size=2; output;y=31.5; output; * conc=80; function='draw'; x= 80 + 15; function='move'; x= 160 - 15; y=31.5; size=2; output;y=28.3; output; * conc=160; function='draw'; x= 160 + 15; function='move'; x= 235 - 15; y=28.3; size=2; output;y=17.2; output; * conc=235; function='draw'; x= 235 + 15; function='move'; x= 310 - 15; y=17.2; size=2; output;y=6.0; output; * conc=310; function='draw'; x= 310 + 15; y=6.0; size=2; output; ods rtf bodytitle; / generate figure 1 / proc gplot data=nitrofen; plot totaljconc / vaxis=axis1 haxis=axis2 annotate=myanno; run; /* FIGURE 2: Scatterplot with superimposed boxplots */

/* set up axes and suppress the x-axis tick marks and labels / / and request boxplot interpolations */ goptions reset=global; axis1 label=(angle=90 'Total number of young (3 broods)'); axis2 (^) minor=none major=none v=none;label=('Nitrofen Concentration') order=(-20 to 340 by 20) symbol1 i=none v=dot color=black; symbol2 interpol=box v=none color=black bwidth=8;

/* annotate data set for the concentration labels / data myanno2; length function $ 5 text $ 3; retain xsys '2' ysys '2'; function="label"; x=0; y=2; text="0"; output; function="label"; x=80; y=2; text="80"; output; function="label"; x=160; y=2; text="160"; output; function="label"; x=235; y=2; text="235"; output; function="label"; x=310; y=2; text="310"; output; / generate figure 2 proc gplot data=nitrofen; */

;^ plot totaljconc totalconc / overlay anno=myanno2 vaxis=axis1 haxis=axis ods rtf close;^ run;