BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jonate_H
Quartz | Level 8

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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;

 

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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;
Rick_SAS
SAS Super FREQ

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;

 

Jonate_H
Quartz | Level 8

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.

Rick_SAS
SAS Super FREQ

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?"

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 2040 views
  • 2 likes
  • 3 in conversation