turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Get pdf from proc fmm (truncated normal distributi...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-20-2014 11:33 AM

Hello,

I'm fitting a mixture of one truncated normal distribution and 1 normal distribution to my data. The code is:

proc fmm data=observations plot=density(bins=56);

model x = / dist=normal kmax=1 parms(8 1);

model +/ dist=truncnormal(3,.);

I want to export the resulting pdf for both distributions and added together. I've read through FMM manual, but I couldn't find the easy way of doing it, so I used another approach:

data pdf;

set example;

do x = 0 to 13 by 0.01;

f1 = Prior_1 * (1/ ((Var_1)**(1/2) * 2.506628)) * exp(-((x - Pred_1)**2) / (2 * (Var_1)**(1/2) * (Var_1)**(1/2)));

f2 = Prior_2 * (1/(cunormal(3-Pred_2)/(Var_2)**(1/2))(1/ ((Var_2)**(1/2) * 2.506628)) * exp(-((x - Pred_2)**2) / (2 * (Var_2)**(1/2) * (Var_2)**(1/2)));

f = f1 + f2;

output pdf;

keep f1 f2 f x;

end;

run;

It works fine with normal distribution, but how can I get the term (1/(cunormal(1.38-Pred_2)/(Var_2)**(1/2)) to work? Since there is no such function is SAS. Could someone please advise me how I can get the actual pdf for truncated normal and export it?

Thank you.

Accepted Solutions

Solution

11-21-2014
10:21 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-21-2014 10:21 AM

Yes, you can implement the function in the DATA step. The CDF and PDF functions are both available in the DATA step. In place of the CHOOSE function, you can use an IF-THEN/ELSE statement.

You can inline the computation, so no need to define the pdfTN function.

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-20-2014 01:11 PM

You should use the PDF function to produce the PDF for the normal distribution. For details on the PDF function (and the related CDF, QUANTILE, and RAND functions) see Four essential functions for statistical programmers - The DO Loop

You can also use the PDF of the normal distribution to compute the PDF for the truncated normal distribution. See http://blogs.sas.com/content/iml/2013/07/24/the-truncated-normal-in-sas/

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-21-2014 08:49 AM

Thank you for your reply. Is there a way to write the following code without using proc iml?

start pdfTN(x, mu, sigma, a, b);

/* Support one-sided truncation. Define Phi(.M)=0 and Phi(.P)=1 */

cdf_a = choose(a=., 0, cdf("Normal", a, mu, sigma)); /* Phi(a) */

cdf_b = choose(b=., 1, cdf("Normal", b, mu, sigma)); /* Phi(b) */

return( pdf("Normal", x, mu, sigma) / (cdf_b - cdf_a) );

finish;

Or how can I access the function pdfTN in my code?

data pdf;

set example;

do x = 0 to 13 by 0.01;

f1=Prior_1*pdf("Normal",x,Pred_1,Var_1);

f2=Prior_2*pdfTN(x,Pred_2,Var_2,3,8);

output pdf;

keep f1 f2;

end;

run;

When I run the code, the error message is "The function PDFTN is unknown, or cannot be accessed."

Solution

11-21-2014
10:21 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-21-2014 10:21 AM

Yes, you can implement the function in the DATA step. The CDF and PDF functions are both available in the DATA step. In place of the CHOOSE function, you can use an IF-THEN/ELSE statement.

You can inline the computation, so no need to define the pdfTN function.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-22-2014 09:26 AM

Thank you for your help. It was very useful and my code works now.