<?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: Simulating random variables to determine whether the expected value converges or diverges in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510058#M137216</link>
    <description>Your log has a note that indicates where part of your issue is, did you fix that already? &lt;BR /&gt;&lt;BR /&gt;I *think* that you're being asked to determine if the expected value converges. So as you simulate the data and keep adding values and recalculating the mean, does the value become a constant or does it go all over the place. You can check this by creating a running mean and seeing if the running means are diverging/converging. Graphing helps to show this (SGPLOT). &lt;BR /&gt;&lt;BR /&gt;So once you fix the simulation portion, you can add the running total part and then graph the results.&lt;BR /&gt;&lt;BR /&gt;This is my interpretation based on ONLY the information you've included in the post.</description>
    <pubDate>Fri, 02 Nov 2018 20:39:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-11-02T20:39:10Z</dc:date>
    <item>
      <title>Simulating random variables to determine whether the expected value converges or diverges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510055#M137214</link>
      <description>&lt;P&gt;d&lt;/P&gt;</description>
      <pubDate>Sat, 22 Dec 2018 07:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510055#M137214</guid>
      <dc:creator>JamesHawthorne</dc:creator>
      <dc:date>2018-12-22T07:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating random variables to determine whether the expected value converges or diverges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510058#M137216</link>
      <description>Your log has a note that indicates where part of your issue is, did you fix that already? &lt;BR /&gt;&lt;BR /&gt;I *think* that you're being asked to determine if the expected value converges. So as you simulate the data and keep adding values and recalculating the mean, does the value become a constant or does it go all over the place. You can check this by creating a running mean and seeing if the running means are diverging/converging. Graphing helps to show this (SGPLOT). &lt;BR /&gt;&lt;BR /&gt;So once you fix the simulation portion, you can add the running total part and then graph the results.&lt;BR /&gt;&lt;BR /&gt;This is my interpretation based on ONLY the information you've included in the post.</description>
      <pubDate>Fri, 02 Nov 2018 20:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510058#M137216</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-02T20:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating random variables to determine whether the expected value converges or diverges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510066#M137221</link>
      <description>&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I changed the r variable right before inserting it. The randnum variable should be r.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;How would I create a running mean?&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;data pieces;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;call streaminit(12345);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;do i = 1 to 50000;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;r = rand('uniform');&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;short = min(r, 1-r);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;long = max(r, 1-r);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;short_long = short / long;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;long_short = long / short;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;proc means data=pieces;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;var short_long long_short;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510066#M137221</guid>
      <dc:creator>JamesHawthorne</dc:creator>
      <dc:date>2018-11-02T21:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating random variables to determine whether the expected value converges or diverges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510072#M137226</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/244201"&gt;@JamesHawthorne&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;I changed the r variable right before inserting it. The randnum variable should be r.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;How would I create a running mean?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p2"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;data pieces;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;call streaminit(12345);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;do i = 1 to 50000;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;r = rand('uniform');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;short = min(r, 1-r);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;long = max(r, 1-r);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;short_long = short / long;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;long_short = long / short;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;proc means data=pieces;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;var short_long long_short;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class="p3"&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data status;
	set pieces;
	row = _n_;
	SL_Running + short_long;
	LS_Running + long_short;

	SL_Mean = SL_Running / _n_;
	LS_Mean = LS_Running / _n_;


run;

proc sgplot data=status;
series x=row y=SL_mean;
series x=row y=LS_Mean;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510072#M137226</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-02T21:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating random variables to determine whether the expected value converges or diverges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510111#M137251</link>
      <description>&lt;P&gt;Long/short is the tough one... Look at this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
call streaminit(12345);
do e = 2 to 7;
    n = 10**e;
    do m = 1 to 9-e;
        do i = 1 to n;
            x = rand("uniform");
            y = max(x, 1-x) / min(x, 1-x);
            output;
            end;
        end;
    end;
keep n m y;
run;

proc sql;
create table outtest as
select 
    n, m, 
    mean(y) as _mean_ "Mean(long/short)"
from test
group by n, m;
quit;

proc sgplot data=outtest;
scatter x=n y=_mean_ / jitter;
xaxis type=log logbase=10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot8.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24611i0B746C88C1712921/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot8.png" alt="SGPlot8.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 03:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510111#M137251</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-11-03T03:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating random variables to determine whether the expected value converges or diverges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510201#M137295</link>
      <description>&lt;P&gt;So&amp;nbsp;by looking at the graphs, the expected value of short divided by long converges because the values converge towards a single value. While the expected value of long divide by short diverges because it doesn't converge towards a single value?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Expected Value of Long Divide by Short" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24631i98A4328546E3C1B7/image-size/large?v=v2&amp;amp;px=999" role="button" title="L_S.png" alt="Expected Value of Long Divide by Short" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Expected Value of Long Divide by Short&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Expected Value of Short Divide by Long" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/24632i070BA818C1C7FB8B/image-size/large?v=v2&amp;amp;px=999" role="button" title="S_L.png" alt="Expected Value of Short Divide by Long" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Expected Value of Short Divide by Long&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 19:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510201#M137295</guid>
      <dc:creator>JamesHawthorne</dc:creator>
      <dc:date>2018-11-03T19:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating random variables to determine whether the expected value converges or diverges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510203#M137297</link>
      <description>&lt;P&gt;I'm relatively new to SAS programming so I'm having trouble understanding some of your code.&amp;nbsp;I'm having trouble understanding the purpose of the first 2 do loops. Why is the variable 'n' 10^e? Also, why does the second do loop go from 1 to 9-e. Does the code below do the same thing but in a simpler way?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pieces;
call streaminit(23456);
   do i= 1 to 100000;
      r= rand('uniform');
      short = min(r,1-r);
      long  = max(r,1-r);
      output;
	short_long = short/long; 
	long_short = long/short;
	end;
run;

data status;
set pieces;
row = _n_;
SL_Running + short_long;
LS_Running + long_short;

SL_Mean = SL_Running / _n_;
LS_Mean = LS_Running / _n_;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Nov 2018 19:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510203#M137297</guid>
      <dc:creator>JamesHawthorne</dc:creator>
      <dc:date>2018-11-03T19:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Simulating random variables to determine whether the expected value converges or diverges</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510220#M137312</link>
      <description>&lt;P&gt;The two loops generate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;7 independent samples of 100 values,&lt;/P&gt;
&lt;P&gt;6 independent samples of 1000 values,&lt;/P&gt;
&lt;P&gt;...&lt;BR /&gt;and 2 independent samples of 10000000 values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to explore the variability of estimates as a function of sample size while keeping the total size of the simulation within reasonable bounds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is not quite equivalent to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s proposition as those consecutive estimates are not independent. But both approaches are instructive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for the original question. In numerical analysis, we say that an iterative procedure diverges when the results start moving &lt;EM&gt;farther&lt;/EM&gt; &lt;EM&gt;away&lt;/EM&gt; from the objective, at some point. So, technically, &amp;nbsp;the long/short mean simulation is NOT diverging, as it&amp;nbsp;keeps (very slowly) moving &lt;EM&gt;closer&lt;/EM&gt; to the true value, which is infinity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What this exercise demonstrates imho is that random simulation&amp;nbsp;can be a very poor estimator sometimes.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Nov 2018 04:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simulating-random-variables-to-determine-whether-the-expected/m-p/510220#M137312</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-11-04T04:22:51Z</dc:date>
    </item>
  </channel>
</rss>

