I am using proc sgplot to plot CDF (series statement) and PDF (density statement) for a dataset.
Does it always require to choose the distribution assumption? e.g., type= normal
Is it possible to plot CDF and PDF witout underline distribution assumption? and if, how to achieve that?
Many thanks!
For continuous distributions, the easiest way is to use PROC UNIVARIATE to create the CDF and PDF plots. The HISTOGRAM statement fits and optionally overlays a nonparamwetric kernel density estimate. The CDFPLOT statement displays the empirical CDF. Here is an example:
proc univariate data=sashelp.cars;
var mpg_highway;
histogram mpg_highway / kernel; /* nonparametric density estimate */
cdfplot mpg_highway;
ods select Histogram CDFPlot;
run;
You can also fit and overlay parametric distributions. PROC UNIVARIATE supports about 20 common distributions. Here is an example of fitting lognormal distribution (maximum likelihood estimation) to the same data:
proc univariate data=sashelp.cars;
var mpg_highway;
histogram mpg_highway / lognormal; /* overlay PDF */
cdfplot mpg_highway / lognormal; /* overlay CDF */
ods select Histogram CDFPlot;
run;
Not sure if this is what you're asking, but you can plot densities and distributions in PROC SGPLOT like this
data normal;
do x = -3 to 3 by 0.01;
y_pdf = pdf('normal',x);
y_cdf = cdf('normal',x);
output;
end;
run;
title 'Normal Distribution';
proc sgplot data = normal;
band x = x upper = y_pdf lower = 0 / legendlabel = 'Density';
series x = x y = y_cdf / legendlabel = 'CDF';
keylegend / location = inside position = topleft across = 1;
yaxis label = 'Density/Probability';
xaxis label = 'x';
run;
title;
For continuous distributions, the easiest way is to use PROC UNIVARIATE to create the CDF and PDF plots. The HISTOGRAM statement fits and optionally overlays a nonparamwetric kernel density estimate. The CDFPLOT statement displays the empirical CDF. Here is an example:
proc univariate data=sashelp.cars;
var mpg_highway;
histogram mpg_highway / kernel; /* nonparametric density estimate */
cdfplot mpg_highway;
ods select Histogram CDFPlot;
run;
You can also fit and overlay parametric distributions. PROC UNIVARIATE supports about 20 common distributions. Here is an example of fitting lognormal distribution (maximum likelihood estimation) to the same data:
proc univariate data=sashelp.cars;
var mpg_highway;
histogram mpg_highway / lognormal; /* overlay PDF */
cdfplot mpg_highway / lognormal; /* overlay CDF */
ods select Histogram CDFPlot;
run;
Thank you all!
by the way, how can I specify the distribution as t-distribution? without enough observations, I try to avoid normal distribution assumption.
Typically data are not distributed as t. The t distribution arises as the sampling distribution of statistics. See the article "Why doesn't PROC UNIVARIATE support certain common distributions?"
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.