Turn on suggestions

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

Showing results for

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 01-18-2016 06:58 PM
(2120 views)

Hello:

Expert does any one now what is wrong with the following code:

I am simulating a truncated distribution that is multivariate in nature with the follow code from Rick's blog, but it not working well:

data TruncNormal(keep=x fa fb);

Fa = cdf('Normal', 30); /* for a = 30 */

Fb = cdf('Normal', 50); /* for b = 50 */

call streaminit(1234);

do i = 1 to 1000; /* sample size = 1000 */

v = Fa + (Fb-Fa)*rand('Uniform'); /* V ~ U(F(a), F(b)) */

x = quantile('Normal', v); /* truncated normal on [a,b] */

output;

end;

run;

ods select histogram;

proc univariate data=TruncNormal;

histogram x / endpoints=30 to 50 by 5;

run;

The aim is to simulate a truncated [a=30,b=50] distribution that is normally distribution. Minimum value is 30 maximum value is 50. The orginal normal distribution has a mean of 38 and standard of 5. Following generation,I like to check to see that the generated distribution is in fact a PDF.

The above case is aimed to generate on one instance of such a truncated distribution, but I want to genereate three of such variable so that I have a multivariate distrunction with column=3 and a with specified covariance. The plan is to generate the truncated distribution thrice and then merge but that can't build the covariance.

I see that one can still use acceptance-rejection, but building covariance/correlation may be challenging.

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You must specify the parameters of the simulated truncated distribution:

```
data TruncNormal(keep=x fa fb);
Fa = cdf('Normal', 30, 38, 5); /* for a = 30 */
Fb = cdf('Normal', 50, 38, 5); /* for b = 50 */
call streaminit(1234);
do i = 1 to 1000; /* sample size = 1000 */
v = Fa + (Fb-Fa)*rand('Uniform'); /* V ~ U(F(a), F(b)) */
x = quantile('Normal', v, 38, 5); /* truncated normal on [a,b] */
output;
end;
run;
ods select histogram;
proc univariate data=TruncNormal;
histogram x / endpoints=28 to 52 by 2;
run;
```

PG

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You must specify the parameters of the simulated truncated distribution:

```
data TruncNormal(keep=x fa fb);
Fa = cdf('Normal', 30, 38, 5); /* for a = 30 */
Fb = cdf('Normal', 50, 38, 5); /* for b = 50 */
call streaminit(1234);
do i = 1 to 1000; /* sample size = 1000 */
v = Fa + (Fb-Fa)*rand('Uniform'); /* V ~ U(F(a), F(b)) */
x = quantile('Normal', v, 38, 5); /* truncated normal on [a,b] */
output;
end;
run;
ods select histogram;
proc univariate data=TruncNormal;
histogram x / endpoints=28 to 52 by 2;
run;
```

PG

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Apparently the reference is "The inverse CDF method for simulating from a distribution," which is based on Chapter 7 of *Simulating Data with SAS *(Wicklin 2013)..

See also "Implement the truncated normal distribution in SAS."

If your eventual goal is multivariate correlated, I recommend reading Chapter 9, "Advanced Simulation of Multivariate Data" as well as searching the literature. This looks like a challenging problem!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks. Yes, multivariate correlated is the goal. And yes, it is a challenging problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks PGstat. The code works for univariate case

SAS is headed **back** to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

**Interested in speaking?** Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.