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
- /
- General Programming
- /
- Simulate Correlated Lognormal (Skewed) 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-13-2017 11:41 AM - edited 06-13-2017 11:42 AM

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!

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

06-14-2017 10:13 AM - edited 06-14-2017 10:22 AM

You should take on SAS/IML .

Calling @Rick_SAS

```
data have;
call streaminit(123456789);
do i=1 to 10000;
y=exp(rand('normal'));
z=exp(rand('normal'));
x=0.5*y+sqrt(1-0.5**2)*z;output;
end;
run;
proc standard data=have mean=7.5 std=6.5 out=have1;
var x;
run;
proc standard data=have1 mean=1 std=1.5 out=have2;
var y;
run;
proc means data=have2 mean std;
var x y;
run;
proc corr data=have2 ;
var x y;
run;
proc univariate data=have2;
histogram x/kernel;
histogram y/kernel;
run;
```

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

06-14-2017 08:59 PM

I devote Chapter 9 of *Simulating Data with SAS *to this kind of problem, which is simulating multivariate data that has a specified correlation and specified marginal distributions. In SAS, the easiest way to do this is to use PROC COPULA in SAS/ETS software and fit a normal copula, as shown in the example on p. 169-172 of my book. The same chapter also shows how to fit copulas with SAS/IML.

There are infinitely many bivariate distributions that have the required correlation and marginals. Some, like KSharp's solution, have a strange bivariate distribution, as shown by a scatter plot of his variables.

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

06-15-2017 09:04 AM

Sharp K's response seemed to be exactly what I was looking for in regards to the parameters. The use of the STANDARDIZED approach appears to be what I was missing. Clever. Thanks.

Rick, thank you for the feedback. Yes, I had seen that section in your book, but due to my initiial lack of knowledge with COPULA, I strayed away from that option. I will have to go back and examine it in more depth when I have time. Though, I was using these data in a sample size calculation, so I did tap into that portion of your book. Thanks.

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

06-15-2017 09:11 AM

To be honest, I want @Rick_SAS to say some more words to clarify this problem.

Better give us an example of IML code .

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

06-15-2017 09:53 AM

Hmm, I have a tendency to get a little too excited without fully exploring the code. Ksharp's code works near as instructed, but is not completely what I had originally wanted.

Problem with the code in regards to using it with sample size calculation is that it constrains all of the means and std to the a priori parameters with no variability in those parameters only in the values in the sample distribution. Though, I needed the variabiliity which would have been seen in the sampling distribution in parameters. The above code also allowed for negative values, since the standardiization occurred post hoc to data generation process, which would not be possible in my particular context.

It ended up turning out that I don't have to corelate variables since the study design will be a little different than orginally expected. Which is easy enough to simulate two independent lognormal variables.

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

06-15-2017 10:27 AM

H,

I totally I agree with you. That is the reason I call Rick to clarify it more .