Hi,
I have upload my question. And I know how to sketch the normal distribution but just have no idea how to color the confident interval.
My code is
data Q4;
do mean=0;
do x=-5 to 5 by .01;
y=pdf('normal',x,mean,1);
output;
end;
end;
run;
proc sgplot data=Q4;
band x=x lower=0 upper=y / group=mean transparency=.5;
series x=x y=y / group=mean;
run;
I think I need to modify the "band" there but don't know how. Anyone could help me with that??
Thank you!
Do like this
data normalpdf;
lower_q = quantile('normal', .05/2);
upper_q = quantile('normal', (1 - .05/2));
do x=-4 to 4 by 0.01;
y=pdf('normal',x);
output;
end;
x = .; y = .;
do lower_x_band = -4 to lower_q by 0.01;
lower_band = pdf('normal',lower_x_band);
output;
end;
lower_x_band = .; lower_band = .;
do upper_x_band = upper_q to 4 by 0.01;
upper_band = pdf('normal',upper_x_band);
output;
end;
upper_x_band = .; upper_band = .;
run;
proc sgplot data=normalpdf noautolegend;
series x=x y=y;
band x = lower_x_band upper = lower_band lower = 0;
band x = upper_x_band upper = upper_band lower = 0;
yaxis offsetmin=0 min=0;
xaxis label = 'x' min=-4.5 max=4.5;
run;
title;
Result:
Do like this
data normalpdf;
lower_q = quantile('normal', .05/2);
upper_q = quantile('normal', (1 - .05/2));
do x=-4 to 4 by 0.01;
y=pdf('normal',x);
output;
end;
x = .; y = .;
do lower_x_band = -4 to lower_q by 0.01;
lower_band = pdf('normal',lower_x_band);
output;
end;
lower_x_band = .; lower_band = .;
do upper_x_band = upper_q to 4 by 0.01;
upper_band = pdf('normal',upper_x_band);
output;
end;
upper_x_band = .; upper_band = .;
run;
proc sgplot data=normalpdf noautolegend;
series x=x y=y;
band x = lower_x_band upper = lower_band lower = 0;
band x = upper_x_band upper = upper_band lower = 0;
yaxis offsetmin=0 min=0;
xaxis label = 'x' min=-4.5 max=4.5;
run;
title;
Result:
Anytime. You can read about the technique in the blog post How to overlay custom curves with PROC SGPLOT .
Have a nice day
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.