/**********************************************/ /**********************************************/ /* MACRO quartplot: A scatterplot for assessing the relationship between a continuous variable and a dichotomous variable. Includes jitter for dichotomous variable OPTIONS: data = name of input data set y = name of dichotomus variable (default 'x') x = name of continous variable (default 'y') jitterwidth = amount of jitter around 0 and 1 (default 0.05) smooth = degree of smoothing: values 1 ... 99, high is smoother, (default 50) quartiles = 0 or 1: If 1, shows vertical lines at the 25, 50, and 75th percentiles (default 0) NOTES: 1. Smoothed line uses real values, not jittered values. 2. Only y values of 0 and 1 are plotted. Other values ignored. 3. Quartiles among observations have y= 0 or 1. CREATED by Ken Kleinman, 6/8/2009 */ /**********************************************/ /**********************************************/ %macro quartplot(x = x, y = y, data=, jitterwidth = .05, smooth = 50, quartiles=0); data lp1; set &data; if &y eq 0 or &y eq 1; jitter = uniform(0) * &jitterwidth; if &y eq 1 then yplot = &y - jitter; else if &y eq 0 then yplot = &y + jitter; run; %if &quartiles = 1 %then %do; proc summary data = lp1; var &x; output out = lp2 q1=q1 median=q2 q3=q3; run; data _null_; set lp2; call symput("quart1",q1); call symput("quart2",q2); call symput("quart3",q3); run; %end; axis1 minor=none label = ("&x"); axis2 minor=none label = (angle = 270 rotate = 90 "&y"); symbol1 i = sm&smooth.s v = none c = blue; symbol2 i = none v = dot h = .2 c = blue; title1 "Smooth = &smooth"; proc gplot data = lp1; plot (&y yplot) * &x / overlay haxis = axis1 vaxis = axis2 %if &quartiles = 1 %then href = &quart1 &quart2 &quart3; ; run; quit; %mend quartplot; /* * demonstration of use; data test; beta = .5; do i = 1 to 1000; xtest = normal(12345); linpred = xtest * beta; prob = exp(linpred)/ (1 + exp(linpred)); ytest = uniform(0) lt prob; output; end; run; * plain plot: hard to see the y values. Hard to get sense of relationship; symbol1 i = none v = dot h = .2 c = blue; proc gplot data = test; plot ytest *xtest; run; quit; * Better with logiplot. ; %quartplot(data=test, x=xtest, y=ytest, jitterwidth = 0.075, smooth = 55, quartiles=1); */