BookmarkSubscribeRSS Feed
katiexyz
Calcite | Level 5


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

2 REPLIES 2
ballardw
Super User

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

Ksharp
Super User

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

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
  • 2 replies
  • 987 views
  • 0 likes
  • 3 in conversation