<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Simulate Correlated Lognormal (Skewed) Data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367366#M275225</link>
    <description>&lt;P&gt;Hmm, I have a tendency to get a little too excited without fully exploring the code.&amp;nbsp; Ksharp's code works near as instructed, but is not completely what I had originally wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;allowed for negative values, since the standardiization occurred post hoc to data generation process, which would not be possible in my&amp;nbsp; particular context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jun 2017 13:53:14 GMT</pubDate>
    <dc:creator>H</dc:creator>
    <dc:date>2017-06-15T13:53:14Z</dc:date>
    <item>
      <title>Simulate Correlated Lognormal (Skewed) Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/366650#M275220</link>
      <description>&lt;P&gt;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&amp;nbsp;beyond the following, which were superficially provided from a colleague:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X: mean = 7.5; std = 6.5&lt;/P&gt;
&lt;P&gt;Y: mean = 1; std =&amp;nbsp; 1.5&lt;/P&gt;
&lt;P&gt;rho = 0.5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;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=&amp;amp;rho*x2+sqrt(1-&amp;amp;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;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;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 &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S., This seems to be easiily done in R or Laavan!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 15:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/366650#M275220</guid>
      <dc:creator>H</dc:creator>
      <dc:date>2017-06-13T15:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Simulate Correlated Lognormal (Skewed) Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/366971#M275221</link>
      <description>&lt;P&gt;You should take on SAS/IML .&lt;/P&gt;
&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2017 14:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/366971#M275221</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-14T14:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: Simulate Correlated Lognormal (Skewed) Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367198#M275222</link>
      <description>&lt;P&gt;I devote Chapter 9 of &lt;EM&gt;Simulating Data with &amp;nbsp;SAS &lt;/EM&gt;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&amp;nbsp;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are infinitely many bivariate distributions that have the required correlation and marginals. Some, like KSharp's solution, have a &amp;nbsp;strange bivariate distribution, as shown by a scatter plot of his variables.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 00:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367198#M275222</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-06-15T00:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Simulate Correlated Lognormal (Skewed) Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367344#M275223</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 13:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367344#M275223</guid>
      <dc:creator>H</dc:creator>
      <dc:date>2017-06-15T13:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: Simulate Correlated Lognormal (Skewed) Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367346#M275224</link>
      <description>&lt;P&gt;To be honest, I want&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;to say some more words to clarify this problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better give us an example of IML code .&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 13:11:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367346#M275224</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-15T13:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: Simulate Correlated Lognormal (Skewed) Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367366#M275225</link>
      <description>&lt;P&gt;Hmm, I have a tendency to get a little too excited without fully exploring the code.&amp;nbsp; Ksharp's code works near as instructed, but is not completely what I had originally wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;allowed for negative values, since the standardiization occurred post hoc to data generation process, which would not be possible in my&amp;nbsp; particular context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 13:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367366#M275225</guid>
      <dc:creator>H</dc:creator>
      <dc:date>2017-06-15T13:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Simulate Correlated Lognormal (Skewed) Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367385#M275226</link>
      <description>&lt;P&gt;H,&lt;/P&gt;
&lt;P&gt;I totally I agree with you. That is the reason I call Rick to clarify it more .&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 14:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulate-Correlated-Lognormal-Skewed-Data/m-p/367385#M275226</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-06-15T14:27:40Z</dc:date>
    </item>
  </channel>
</rss>

