<?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: simulation with two normal distributions in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9143#M553</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the main purpose of this simulation is to generate two normal distributions with correlation of 0.5 using the random number generator rannor in SAS. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since two normal dist. are not independent I don't know how i can come up with the joint density function of f(x,y) in order to figure out E(XY). Any other ideas? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Sep 2011 22:59:48 GMT</pubDate>
    <dc:creator>kzepilos</dc:creator>
    <dc:date>2011-09-14T22:59:48Z</dc:date>
    <item>
      <title>simulation with two normal distributions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9140#M550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello. I am trying to simulate in sas about a case where two randomly generated normal distributions (say X and Y with 1000 observations) &lt;/P&gt;&lt;P&gt;have correlation of 0.5 (corr(X,Y)=0.5). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that corr(X,Y)= cov(X,Y)/(stdX*stdY) &lt;/P&gt;&lt;P&gt;where cov(X,Y)=E(XY)-E(X)E(Y).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now my question is how do you figure out E(XY)? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2011 22:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9140#M550</guid>
      <dc:creator>kzepilos</dc:creator>
      <dc:date>2011-09-14T22:06:56Z</dc:date>
    </item>
    <item>
      <title>simulation with two normal distributions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9141#M551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, you want to calculate the conditional mean?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2011 22:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9141#M551</guid>
      <dc:creator>FriedEgg</dc:creator>
      <dc:date>2011-09-14T22:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: simulation with two normal distributions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9142#M552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I might be missing something but from the simulation, multiply each x*y and take the average?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or do you need an explicit mathematical formula?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2011 22:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9142#M552</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-09-14T22:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: simulation with two normal distributions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9143#M553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the main purpose of this simulation is to generate two normal distributions with correlation of 0.5 using the random number generator rannor in SAS. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since two normal dist. are not independent I don't know how i can come up with the joint density function of f(x,y) in order to figure out E(XY). Any other ideas? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2011 22:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9143#M553</guid>
      <dc:creator>kzepilos</dc:creator>
      <dc:date>2011-09-14T22:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: simulation with two normal distributions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9144#M554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You do not need to figure out E(XY), there is a formula for calculating correlation coefficient.&lt;/P&gt;&lt;P&gt;You can hard code to get that .I used Standard Normal Distribution N(0,1), but It looks like hard to get cov=0.5.&lt;/P&gt;&lt;P&gt;So I set it cov=0.1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;%macro corr;
%do %until(&amp;amp;found eq Y);
data normal(drop=i);
do i=1 to 1000;
 x=rannor(0);
 y=rannor(0);
 output;
end;
run;
proc corr data=normal outp=corr(where=(_type_='CORR')) noprint ;
 var x;
 with y;
run;
%let found=N;
data _null_;
 set corr;
 if round(x,.1) eq .1 then call symputx('found','Y');
run;
%end;
%mend corr;

%corr

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Sep 2011 05:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9144#M554</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-09-15T05:01:18Z</dc:date>
    </item>
    <item>
      <title>simulation with two normal distributions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9145#M555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks alot for your help. It definitely helped!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Sep 2011 13:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9145#M555</guid>
      <dc:creator>kzepilos</dc:creator>
      <dc:date>2011-09-15T13:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: simulation with two normal distributions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9146#M556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's no need to hunt for the correlation.&amp;nbsp; It is generated through this process:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL start="1"&gt;&lt;LI&gt;Generate two separate random normal variables.&amp;nbsp; call them x1, x2. &lt;/LI&gt;&lt;LI&gt;If you want "drawn from a population with correlation R", skip this.&amp;nbsp; If you want the drawn sample to have correlation R, then do this step:&amp;nbsp; put the two columns through principle components (PROC PRINCOMP or PROC FACTOR) to generate two factors that are completely uncorrelated.&amp;nbsp; The reason is that x1, x2 from above might have non-zero correlation. &lt;/LI&gt;&lt;LI&gt;Use this formula:&amp;nbsp; Y = x1 * R + x2 * sqrt( 1 - R**2 ).&amp;nbsp; Y will be correlated with x1 with exactly correlation R.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For more variables, in general, take the components matrix and post multiply by Cholesky decomposition of R, the correlation matrix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let r=0.5;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call streaminit( 123 );&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i = 1 to 1000;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x1 = rand('normal');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x2 = rand('normal');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop i;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc princomp data=test out=pc;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var x1 x2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set pc;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; yr =&amp;nbsp;&amp;nbsp;&amp;nbsp; x1 * &amp;amp;r +&amp;nbsp;&amp;nbsp;&amp;nbsp; x2 * sqrt( 1 - (&amp;amp;r)**2 );&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; yp = prin1 * &amp;amp;r + prin2 * sqrt( 1 - (&amp;amp;r)**2 );&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc corr;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var x1 x2 yr prin1 prin2 yp;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Sep 2011 19:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9146#M556</guid>
      <dc:creator>DLing</dc:creator>
      <dc:date>2011-09-15T19:00:55Z</dc:date>
    </item>
    <item>
      <title>simulation with two normal distributions</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9147#M557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks DLing!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Sep 2011 20:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/simulation-with-two-normal-distributions/m-p/9147#M557</guid>
      <dc:creator>kzepilos</dc:creator>
      <dc:date>2011-09-15T20:04:54Z</dc:date>
    </item>
  </channel>
</rss>

