I am trying to simulate two correlated lognormal variables. The variables should be right skewed somewhat and are are left bound by zero. I don't have any moment information beyond the following, which were superficially provided from a colleague:
X: mean = 7.5; std = 6.5
Y: mean = 1; std = 1.5
rho = 0.5
Ideally the code will allow me to play around with the above parameters, and I will desire to eventually simulate 1,000s of samples given the parameters. My fruitless attempt is below:
data have;
call streaminit(4321);
sigma1 = 0.78; /* shape or log-scale parameter */
zeta1 = 1.72; /* scale or log-location parameter */
do id=1 to 10000;
X1 = rand("Normal", zeta1, sigma1); /* Y ~ N(zeta, sigma) */
X2 = exp(X1);
output;
end;
run;
%let rho=0.45;
data want;
set have;
call streaminit(1234);
sigma2 = 0.00000000000000000000000000000000001; /* shape or log-scale parameter */
zeta2 = 0.000000000000000000000000000000000001; /* scale or log-location parameter */
y1=&rho*x2+sqrt(1-&rho**2)*rand("Normal", zeta2, sigma2);
Y2=exp(y1);
run;
proc corr data=want;
var x2;
with y2;
run;
proc univariate data=want; /* visualize simulated data and check fit */
histogram x2 y2/ lognormal;
run;
Obviously my issue is with the second variable. I was getting deserate and thinking of just sorting each variable independently and pseudo sorting them and merging them together get a semblance of my target sample. That or the X variable is not that skewed appearing, so I could simulate Y (log normal) and correlate X (normal). There could be an easy work around, say simulate normal variable and then transform them after the simulation process. Not sure 😞
P.S., This seems to be easiily done in R or Laavan!
... View more