<?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: Jumping over an NLPNRA hurdle... in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156175#M1432</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If "eksi" can't be greater than 1, you should constrain it.&lt;BR /&gt;The expression&amp;nbsp; (1-eksi**2)**(n/2)&amp;nbsp; is undefined when eksi &amp;gt; 1 and n is odd.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My comment is that you should be very concerned about convergence. Computing an infinite summation by summing the first 20 terms is only going to work if the series converges very quickly. There are many examples in numerical analysis that show why truncating an infinite series can lead to large errors.&amp;nbsp; Along the same lines, using terms that involve tha GAMMA and FACT functions often lead to numerical errors, which is why I prefer the PDF calls..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another comment is that you are not taking advantage of the vector nature of SAS/IML. Perhaps you can compute with w2, rather than have a DO loop over the index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly, you can save some computational time if you list some of the statements out of the innermost loops. For example, the expression for 'negb' depends only on 'i', so you do not need to compute it at every iteration of k1 and k2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Apr 2014 15:18:38 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2014-04-01T15:18:38Z</dc:date>
    <item>
      <title>Jumping over an NLPNRA hurdle...</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156172#M1429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to fit a dataset to a self-derived distribution - trying to use nlpnra but no luck thusfar.&amp;nbsp; I think it is mainly a programming fault on how I program the likelihood, since the call runs, but does not seem to identify the function it should maximize.&amp;nbsp; The output that I get from the call simply says that the convergence criteria has been satisfied, but no iterations have been performed.&amp;nbsp; The initial values that I give the call is returned.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the density of the model:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG sad="" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because of the infinite summation, the likelihood function is obviously just the product of this density without any further simplification &lt;SPAN __jive_emoticon_name="_sad.gif'"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My approach is direct - by taking the product of the density across my data points, and by using do - loops for the infinite sums.&amp;nbsp; Suppose for now that just some threshold can be substituted for infinity; in this case, 30.&amp;nbsp; My code is given below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;proc iml;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;use sasuser.nebraskdry1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;read all into data1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;data1 = data1[3:nrow(data1),ncol(data1)-2:ncol(data1)];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;x1 = data1[,1]; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;x2 = data1[,2]; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;*y = x1 || x2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;w2 = x1/x2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;n = nrow(w2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;thres = 30;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;start logl(par) global(w2,thres,n);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt; eksi = par[1];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt; theta = par[2];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt; dens = j(n,1,0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt; do index = 1 to n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt; val = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp; do i = 0 to thres;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp; do k = 0 to thres;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; negb = (1-eksi**2)**(n/2) * eksi**(2*i) * gamma(n/2 + i) / (gamma(n/2)*fact(i));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; poiss = exp(-theta/2) * (theta/2)**k / fact(k)&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; betav = beta(n/2+i+k,n/2+i+k);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; betav = 1/betav;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; variab = w2[index,1]**(n/2+i+k-1) * (1 + w2[index,1])**(-1*(n+2*i+2*k));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = val + negb*betav*variab*poiss;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp; end; *k; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp; end; *i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp; dens[index,1] = val;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt; end; *index; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt; v = dens[#,];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt; return(v);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;finish logl;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;par={0.2 15}; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;optn = {1 1}; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;call nlpnra(rc,xr,"logl",par,optn);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;xr = n // xr`;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;row = {"n" "eksi hat" "theta hat"};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;if rc&amp;gt;0 then print xr[r=row label='ML Estimates for model:']; else print 'Algorithm does not converge';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;Can anyone possibly assist me in overcoming this obstacle?&amp;nbsp; I'd really, really appreciate it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;Kindest regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&lt;SPAN style="color: #000000;"&gt;Johan&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Mar 2014 17:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156172#M1429</guid>
      <dc:creator>johan_ferreira</dc:creator>
      <dc:date>2014-03-25T17:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Jumping over an NLPNRA hurdle...</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156173#M1430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Without your data, we can't run your program.&lt;/P&gt;&lt;P&gt;Did you check the SAS Log?&amp;nbsp; Is there an error or warning?&amp;nbsp; It seems like your "infinite product" has a high probability of overflowing during the optimization.&lt;/P&gt;&lt;P&gt;I assume that you can run&lt;/P&gt;&lt;P&gt;z = logl(par);&lt;/P&gt;&lt;P&gt;and it works without error?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can any of your computations be simplified by using the PDF functions that SAS supplies?&amp;nbsp; I recognize the beta distribution, and it looks like there is some neg.bin and poisson distributions in there as well?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Mar 2014 23:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156173#M1430</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-03-26T23:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Jumping over an NLPNRA hurdle...</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156174#M1431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rick, thanks for taking time to reply and look at it.&amp;nbsp; Your comments are greatly appreciated.&amp;nbsp; I took some time to consider your comments.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First off, here is my code again, and I attach the data now in a data step:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;data d;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;input w2 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.086206897&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;11&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.153846154&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.246575342&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.0125&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.15625&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.033333333&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.192982456&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;11&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;13&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;5.166666667&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.333333333&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;9&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.153846154&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.037037037&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.333333333&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.181818182&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.133333333&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;37&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.076923077&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.666666667&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;14&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1.666666667&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.142857143&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1.666666667&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;20&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.272727273&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.222222222&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.454545455&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.578947368&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.242424242&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;1.066666667&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.166666667&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.454545455&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.046511628&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;34&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;0.25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;proc iml;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;use d; read all into w2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;n = nrow(w2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;thres = 20;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;start logl(par) global(w2,thres,n);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;eksi = par[1];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;theta1 = par[2];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;theta2 = par[3];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;dens = j(n,1,0);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;/*eksisq = eksi**2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;nover2 = n/2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;poissonparameter1 = theta1/2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;poissonparameter2 = theta2/2; */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;do index = 1 to n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;val = 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;w2val = w2[index,1];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp; do i = 0 to thres;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp; do k1 = 0 to thres;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp; do k2 = 0 to thres;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; negb = (1-eksi**2)**(n/2) * eksi**(2*i) * gamma(n/2 + i) / (gamma(n/2)*fact(i));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *negb = pdf("negbinomial",i,eksisq,nover2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; poiss = exp(-theta1/2) * (theta1/2)**k1 / fact(k1) * exp(-theta2/2) * (theta2/2)**k2 / fact(k2)&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *poiss = pdf("poisson",k2,poissonparameter1) * pdf("poisson",k2,poissonparameter2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; betav = 1/beta(n/2+i+k1+k2,n/2+i+k1+k2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; variab = w2val**(n/2+i+k1+k2-1) * (1 + w2val)**(-1*(n+2*i+k1+k2));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = val + negb*betav*variab*poiss;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp; end; *k2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp;&amp;nbsp; end; *k1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp; end; *i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;&amp;nbsp; dens[index,1] = val;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;end; *index;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;v = dens[#,];&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;return(v);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;finish logl;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;*Calculate ML estimates;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;par={0.2 5 5}; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;z = logl(par);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;optn = {1 2}; &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;call nlpnms(rc,xr,"logl",par,optn);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;z = logl(par);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;print z;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;xr = n // xr`;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;row = {"n" "eksi hat" "theta1 hat" "theta2 hat"};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;if rc&amp;gt;0 then print xr[r=row label='ML Estimates for model:']; else print 'Algorithm does not converge';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff6600;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also added another Poisson factor to my density.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I spoke to a colleague regarding my use of NLPNRA and he suggested I also give NLPNMS a try since the latter does not rely so heavily on the second derivatives (i.e. Hessian matrix) being continuous.&amp;nbsp; Due to the nature of the model and the "brute force" attack, I tried it, and (sometimes...) it is successful.&amp;nbsp; Like you mentioned, the overflow is indeed reached quickly (which is mentioned in the log, and then the call does not execute further), and then I adjusted the "threshold" to a value such that the model will still give results, even though it is not very reliable.&amp;nbsp; I am mostly now aiming to just make sure my IML approach is correct and will consider the reliability of the estimates at a later stage.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can run z=logl(par), although it returns a value of 0 - why, I am not sure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As per your suggestion, I used built-in functions of the PDFs of SAS in this new attempt.&amp;nbsp; I added it here and is commented out for easy use when required.&amp;nbsp; A possible challenge in this regard is that the call seems to optimize the parameter "eksi" sometimes to be larger than 1, that results in the pdf function of the negative binomial to be undefined.&amp;nbsp; I kept the written out density in the code just in case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have any additional comments or suggestions I would greatly appreciate it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Johan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Mar 2014 13:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156174#M1431</guid>
      <dc:creator>johan_ferreira</dc:creator>
      <dc:date>2014-03-31T13:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: Jumping over an NLPNRA hurdle...</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156175#M1432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If "eksi" can't be greater than 1, you should constrain it.&lt;BR /&gt;The expression&amp;nbsp; (1-eksi**2)**(n/2)&amp;nbsp; is undefined when eksi &amp;gt; 1 and n is odd.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My comment is that you should be very concerned about convergence. Computing an infinite summation by summing the first 20 terms is only going to work if the series converges very quickly. There are many examples in numerical analysis that show why truncating an infinite series can lead to large errors.&amp;nbsp; Along the same lines, using terms that involve tha GAMMA and FACT functions often lead to numerical errors, which is why I prefer the PDF calls..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another comment is that you are not taking advantage of the vector nature of SAS/IML. Perhaps you can compute with w2, rather than have a DO loop over the index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lastly, you can save some computational time if you list some of the statements out of the innermost loops. For example, the expression for 'negb' depends only on 'i', so you do not need to compute it at every iteration of k1 and k2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Apr 2014 15:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Jumping-over-an-NLPNRA-hurdle/m-p/156175#M1432</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-04-01T15:18:38Z</dc:date>
    </item>
  </channel>
</rss>

