<?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: writing formula in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186869#M1909</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know what "the results are weird" means.&amp;nbsp; What are you seeing that is different than you expect?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your loop appears to reconstruct the formula in the paper.&amp;nbsp; I don't see anything obviously wrong, other than the code being slightly inefficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suggest that you debug and check the code on a smaller example, like 5x3 instead of 5000x30.&amp;nbsp; That will enable you to check the computations by hand to make sure they are correct.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Jun 2014 15:43:12 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2014-06-06T15:43:12Z</dc:date>
    <item>
      <title>writing formula</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186868#M1908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I wrote a formula in SAS IML. In that formula there are two type of parameters. One of them is from a existing file and the other one is created by SAS. When I run the program it works but the results are weird. I want to be sure that my code is correct. Could you check my code please. The formula which I work is attached. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;data parms;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;INFILE "C:\mirt\parms.txt";&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;INPUT a1 a2 a3 d1;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call randseed(0);&lt;/P&gt;&lt;P&gt;&amp;nbsp; use parms;&lt;/P&gt;&lt;P&gt;&amp;nbsp; read&amp;nbsp; all var {a1 a2 a3} into a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; read all var {d1} into d;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; mean = {0,0,0};&amp;nbsp; *change these values to transfrom theta1 and theta2 to a different mean; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; cov = {1 0.45 0.45,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.45 1 0.45,&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.45 0.45 1};&amp;nbsp; *change the covariance to modify the correlation between dimensions;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp; theta = RANDNORMAL(5000,mean,cov);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;T=theta`; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;z=j(5000,30);&lt;/P&gt;&lt;P&gt; p=j(5000,30);&lt;/P&gt;&lt;P&gt; u=j(5000,30);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do j=1 to 5000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to 30;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;p[j,i]= exp((a[i,]*T[,j])+d[i,])/(1+(exp((a[i,]*T[,j])+d[i,])));&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;u[j,i]=ranuni(0);&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if p[j,i]&amp;lt;u[j,i] then z[j,i]=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if p[j,i]&amp;gt;=u[j,i]then z[j,i]=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;create response from z;&lt;/P&gt;&lt;P&gt;append from z;&lt;/P&gt;&lt;P&gt;names1={theta1 theta2 theta3};&lt;/P&gt;&lt;P&gt;create theta from theta [colname=names1];&lt;/P&gt;&lt;P&gt;append from theta;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;data keep2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set response;&lt;/P&gt;&lt;P&gt;&amp;nbsp; file "C:\mirt\mirt_data.txt";&lt;/P&gt;&lt;P&gt;&amp;nbsp; put (col1-col30)(1.0);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc corr data=keep2 alpha;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var col1-col30;&lt;/P&gt;&lt;P&gt;&amp;nbsp; ods output cronbachalpha=alpha;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;data alpha_need;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set alpha;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; keep alpha;&lt;/P&gt;&lt;P&gt;&amp;nbsp; file "c:\mirt\alpha\alpha.txt" mod;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put alpha;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data theta;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set theta;&lt;/P&gt;&lt;P&gt;&amp;nbsp; file "C:\mirt\theta.txt";&lt;/P&gt;&lt;P&gt;&amp;nbsp; put theta1 theta2 theta3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jun 2014 16:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186868#M1908</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2014-06-05T16:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: writing formula</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186869#M1909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know what "the results are weird" means.&amp;nbsp; What are you seeing that is different than you expect?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your loop appears to reconstruct the formula in the paper.&amp;nbsp; I don't see anything obviously wrong, other than the code being slightly inefficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suggest that you debug and check the code on a smaller example, like 5x3 instead of 5000x30.&amp;nbsp; That will enable you to check the computations by hand to make sure they are correct.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jun 2014 15:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186869#M1909</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-06-06T15:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: writing formula</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186870#M1910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The program is much easier to understand (and more efficient) if you vectorize the computations instead of using two DO loops.&amp;nbsp; In vector form, the main computation requires two calls:&lt;/P&gt;&lt;P&gt;p = logistic( theta*A` + d` );&lt;/P&gt;&lt;P&gt;call randgen(z,"Bernoulli", p);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The computation of P is equivalent to the longer computation that you have:&lt;/P&gt;&lt;P&gt;do j=1 to 5000;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do i=1 to 30;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p[j,i]= exp((a[i,]*T[,j])+d[i,])/(1+(exp((a[i,]*T[,j])+d[i,])));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 11:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186870#M1910</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-06-09T11:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: writing formula</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186871#M1911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dr. Wicklin,&lt;/P&gt;&lt;P&gt;Thank you SO much for your answer. I really appreciate it. I will work on both method. By the way "weird results" means different results from literature. Now, I'm pretty sure these results are&amp;nbsp; because of my design. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jun 2014 17:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/writing-formula/m-p/186871#M1911</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2014-06-09T17:27:16Z</dc:date>
    </item>
  </channel>
</rss>

