<?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: Generate binary values after fitting logistic model in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44953#M245</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Santanu,&lt;/P&gt;&lt;P&gt;You can generate a random uniform for each observation (U), then set OUTCOME = 1 if prob &amp;gt; U, 0 otherwise.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Susan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Sep 2011 18:19:02 GMT</pubDate>
    <dc:creator>sgruber</dc:creator>
    <dc:date>2011-09-14T18:19:02Z</dc:date>
    <item>
      <title>Generate binary values after fitting logistic model</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44950#M242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a large dataset, having 8 million observations. I have fitted a logistic model and obtained the predicted probabilities using PROC LOGISTIC. Now using the predicted probabilities, I would like to generate the 0-1 values corresponding to each observation. I was trying to do that in PROC IML using the RANDGEN function within a loop. Rick Wicklin's blog (April 4, 2011) suggest similar solution for independent normal distribution. But it's taking for ever. When I do the same thing for a subset (2 million) of the dataset, it works reasonable fast (overnight). Is there a better way to this? Note that the predicted probabilities are different for each observation. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Similar problem occurs when I try to generate from normal with different mean in PROC IML. Any guidance would be highly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Santanu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 18:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44950#M242</guid>
      <dc:creator>spramanik</dc:creator>
      <dc:date>2011-08-08T18:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Generate binary values after fitting logistic model</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44951#M243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe I'm confused. I think all you have to do to get the groups is to assign group=1 when the predicted value is greater than 0.5 and group=0 when the predicted value is less than 0.5.&amp;nbsp; I don't see why RANDGEN comes into play or why there would be a loop.&amp;nbsp; Here is some code that generates some fake data and calls logistic to output predicted probabilities. The PROC IML code just assigns 1 or 0 depending on the predicted probabilities. You can use the DATA step to do the same thing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a(drop = i prob);&lt;BR /&gt;call streaminit(321);&lt;BR /&gt;do i = 1 to 1000;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; x = rand("normal");&lt;BR /&gt;&amp;nbsp;&amp;nbsp; prob = exp(x) / (1 + exp(x));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; y = rand("Bernoulli", 1-prob);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;end;&lt;BR /&gt;proc logistic data=a;&lt;BR /&gt;model y(event='1') = x;&lt;BR /&gt;output out=out pred=pred;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc iml;&lt;BR /&gt;use out; read all var {pred y}; close out;&lt;BR /&gt;class = (pred&amp;gt;= 0.5);&lt;BR /&gt;print (sum(class=y));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 18:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44951#M243</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2011-08-08T18:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: Generate binary values after fitting logistic model</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44952#M244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rick,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your reply. What if all the predicted probabilities are greater than 0.5 or less than 0.5? Still there is a chance of of an observation getting assigned to a different group, right? I would like to incorporate that uncertainty by generating from Bernoulli. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is similar to that of fitting a model using PROC MIXED. I can get the predicted (EBLUP) values from PROC MIXED, but those are unrealistically smooth values. I would like to obtain the predicted values in two steps: first generate a value (say, mu) from normal with mean=synthetic (Xbeta_hat) and common variance=random effect variance component estimate, then generate from normal with mean=mu and common variane=residual variance estimate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Santanu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 18:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44952#M244</guid>
      <dc:creator>spramanik</dc:creator>
      <dc:date>2011-08-08T18:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Generate binary values after fitting logistic model</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44953#M245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Santanu,&lt;/P&gt;&lt;P&gt;You can generate a random uniform for each observation (U), then set OUTCOME = 1 if prob &amp;gt; U, 0 otherwise.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Susan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Sep 2011 18:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Generate-binary-values-after-fitting-logistic-model/m-p/44953#M245</guid>
      <dc:creator>sgruber</dc:creator>
      <dc:date>2011-09-14T18:19:02Z</dc:date>
    </item>
  </channel>
</rss>

