Hi, guys
I expand my research of PDF graph to two variables. Here is my code.
data Have; set Sample2(keep=weight inf_weight); run;
proc kde data=Have;
bivar weight inf_weight / bwm=2 ngrid=250 plots=contour;
score data=Have out=Out(rename=(value1=weight value2=inf_weight));
run;
proc sort data=Out; by density; run;
proc sgplot data=Out;
styleattrs wallcolor=white;
scatter x=weight y=inf_weight / colorresponse=density colormodel=ThreeColorRamp
markerattrs=(symbol=CircleFilled) transparency=0.5;
xaxis grid values=(30 to 150);
yaxis grid values=(500 to 6000);
run;
This will produce a scatter plot and the value of PDFs is represented by the color.
If I intend to know the area that corresponds to a probability mass of 95%, how do I get it and mark the area on the graph? I know there is another type of graph called surface plot which uses the volume to represent the probability mass but that's not my consideration. Thanks.
Check @Rick_SAS blogs:
https://blogs.sas.com/content/iml/2014/07/21/add-prediction-ellipse.html
https://blogs.sas.com/content/iml/2014/07/23/prediction-ellipses-from-covariance.html
data Have; set sashelp.heart(keep=weight height); run;
proc kde data=Have ;
bivar weight height /out=out(rename=(value1=weight value2=height)) bwm=2 ngrid=250 plots=contour;
run;
proc sort data=Out; by density; run;
data out2;
set out have(keep=weight height rename=(weight=weight2 height=height2));
run;
proc sgplot data=Out2;
styleattrs wallcolor=white;
scatter x=weight y=height / colorresponse=density colormodel=ThreeColorRamp
markerattrs=(symbol=CircleFilled) transparency=0.5;
ellipse x=weight2 y=height2; /* default is ALPHA=0.05 */
run;
Check @Rick_SAS blogs:
https://blogs.sas.com/content/iml/2014/07/21/add-prediction-ellipse.html
https://blogs.sas.com/content/iml/2014/07/23/prediction-ellipses-from-covariance.html
data Have; set sashelp.heart(keep=weight height); run;
proc kde data=Have ;
bivar weight height /out=out(rename=(value1=weight value2=height)) bwm=2 ngrid=250 plots=contour;
run;
proc sort data=Out; by density; run;
data out2;
set out have(keep=weight height rename=(weight=weight2 height=height2));
run;
proc sgplot data=Out2;
styleattrs wallcolor=white;
scatter x=weight y=height / colorresponse=density colormodel=ThreeColorRamp
markerattrs=(symbol=CircleFilled) transparency=0.5;
ellipse x=weight2 y=height2; /* default is ALPHA=0.05 */
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.