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
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Generating bivariate lognormal data

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

06-24-2013 12:12 PM

Hi,

I have to generate 30 lines of data from the bivariate lognormal distribution.

I have this information

"The log10 transformed responses follow the normal distribution as follows: X~N(-0.4, 0.3**2) and Y~N(-1.4, 0.3**2). Their correlation rho=0.5"

I have been generating the data with this code so far, which I believe is incorrect.

data simulate;

keep logy1 logy2;

do i=1 to 30;

mu1=-0.4 ;mu2=-1.4;sd1=0.3;sd2=0.3;rho=0.5;

r1 = rannor(1245);

r2 = rannor(2923);

logy1=10**(mu1 + sd1*r1);

logy2= 10**(mu2 + rho*sd2*r1+sqrt(sd2**2-sd2**2*rho**2)*r2);

output;

end;

proc corr data=simulate;

var logy1 logy2;

run;

Proc corr gives me estimates that i do not expect. I suppose I expected to see the mean, sd and rho values that I wrote in the datastep: I don't know how they'd change by being logtransformed.

Please can anyone help me? I am very stuck.

Katie

XX

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

Posted in reply to katiexyz

06-24-2013 06:19 PM

The Rand function with 'LOGNORMAL' might generate the type of number you need better than the attempted transforms.

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

Posted in reply to katiexyz

06-24-2013 09:27 PM

Not sure if it what you need. You should run code several times to get almost 0.5 correlation rho.

data simulate; do i=1 to 300; r1 = rand('NORMAL',-0.4,0.3); r2 = rand('NORMAL',-1.4,0.3); r3 = rand('NORMAL',-1.4,0.3); r1=0.5*r2+sqrt(1-0.5**2)*r3; output; end; proc corr data=simulate; var r1 r2; run;

Ksharp