BookmarkSubscribeRSS Feed
darrylovia
Quartz | Level 8
All
I am running a simple z-test and instead of displaying the data in a table, i.e. z-score=.67 and z-statistic at 95% = 1.96. I would like to display the test statistics graphically.

-1) Draw a normal distribution plot.
-2) on the graph put a marker for the threshold value 95% z (1.96) and fill with color values above the threshold
-3) Put a marker for the calculated z-score so the customer can visually see if the statistics is in the rejection zone. (above 1.96 or below -1.96).

Also, I am using Enterprise Guide 4.1 and SAS 9.1 is the SAS server.
Any ideas?

Thanks
4 REPLIES 4
GraphGuy
Meteorite | Level 14
I don't have an example of exactly what you're looking for, but I think this one might be close:

http://robslink.com/SAS/democd12/normal.htm

http://robslink.com/SAS/democd12/normal_info.htm
darrylovia
Quartz | Level 8
Robert Thanks
I filled in the tails by drawing a bunch of vertical lines using the annotate facility. I pasted the code below.



** Sources: SAS System for Statistical Graphs, Michael Friendly, 1st Edition **;
** Also see normal distribution, wiki;
** http://robslink.com/SAS/democd24/multdist_info.htm;
%let z_cutoff=1.96;
%let z_score=.8;

data normal;
a=1 / sqrt(2 * constant('PI'));

do x=-3.5 to 3.5 by .01;
y= a * exp(-(x**2)/2);
if x>= &z_cutoff then z=y;
else if x<=-&z_cutoff then z=y;
else call missing(z95);
output;
end;
run;


data anno_data;
length function color $8 text $32;
retain color 'red'
xsys ysys '2'
size 1;
a=1 / sqrt(2 * constant('PI'));

do x=1.96 to 3.5 by .01;
function='move';
y=0;
output;
y=a * exp(-(x**2)/2);
function='draw';
output;
end;

do x=-3.5 to -1.96 by .01;
function='move';
y=0;
output;
y=a * exp(-(x**2)/2);
function='draw';
output;
end;

function='label';
text="Z-Score= "||strip(put(&z_score,z4.2));
x=2;
y=.35;
style='swiss';
color='black';
size=3;
when='A';
output;

function='label';
text="Z-Cut Off= &z_cutoff";
x=2;
y=.33;
style='swiss';
color='black';
size=3;
when='A';
output;

run;



proc gplot data=normal;
plot y * x/ href=0 &z_score chref=(black green) lhref=20 anno=anno_data
vaxis=axis1 haxis=axis2 ;
symbol1 i=join v=none c=black;
axis1 order=0 to .4 by .1
label=(f=titalic h=2 a=90 r=0 'Probability')
value=(f=duplex h=1.8) minor=none;
axis2 label=(f=titalic h=2 'Standard Deviations')
value=(f=duplex h=1.8) minor=none;
format y 3.1;
run;
Jay54
Meteorite | Level 14
This is a good use case where you can get the benefit of the SGPlot procedure that supports band plots. Here is the code. Note the small change in the data step to compute z1 and z2 (used to draw the bands).

%let z_cutoff=1.96;
%let z_score=.8;

data normal2;
a=1 / sqrt(2 * constant('PI'));

do x=-3.5 to 3.5 by .01;
z1=.; z2=.;
y= a * exp(-(x**2)/2);
if x>= &z_cutoff then z1=y;
if x<=-&z_cutoff then z2=y;
output;
end;
run;

ods html file='Normal.htm';
ods graphics / reset imagename='normal';
proc sgplot data=normal2;
label x='Standard Deviations';
label y='Probability';
band x=x upper=z1 lower=0;
band x=x upper=z2 lower=0;
series x=x y=y;
xaxis values=(-4 to 4 by 1);
inset ("Z-Score =" = "&z_score" "Z-Cutoff =" = "&z_cutoff") / border osition=topright;
run;
ods html close;
darrylovia
Quartz | Level 8
Unfortunately SGPLOT is a 9.2 proc and we have 9.1

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1255 views
  • 0 likes
  • 3 in conversation