<div dir="ltr">If I am not mistaken, in Iceland, there was substantial discussion amongst developers about what functions returned log-likelihood and which functions returned negative log-likelihood.<div>If I am not mistaken this hasn't been standardized; it is often different from R. </div><div> </div><div>The difference between the two versions of <span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;white-space:pre-wrap;background-color:rgb(252,253,251)">00075 appears to simply be a negative sign? </span></div><div><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;white-space:pre-wrap;background-color:rgb(252,253,251)">Is this a documentation failure or a bug?</span></div><div><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;white-space:pre-wrap;background-color:rgb(252,253,251)">Aaron</span></div><div><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;white-space:pre-wrap;background-color:rgb(252,253,251)"><br></span></div><div><div><div style="font-family:arial,sans-serif;font-size:13.3333330154419px"><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;background-color:rgb(252,253,251)">nll -= -k(i)*</span><a href="http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341" title="Description not yet available." target="_blank" style="color:rgb(70,101,162);font-family:monospace,fixed;font-size:9pt;line-height:15px;text-decoration:none">log</a><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;background-color:rgb(252,253,251)">(lambda(i))+lambda(i)+</span><a href="http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995" title="Log gamma function." target="_blank" style="color:rgb(70,101,162);font-family:monospace,fixed;font-size:9pt;line-height:15px;text-decoration:none">gammln</a><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;background-color:rgb(252,253,251)">(k(i)+1.);</span></div></div></div><div><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;background-color:rgb(252,253,251)">vs</span></div><div><pre style="white-space:pre-wrap;font-family:monospace,fixed;font-size:9pt;border:1px solid rgb(214,229,196);padding:4px 6px;margin:4px 8px 4px 2px;overflow:auto;word-wrap:break-word;line-height:15px;color:rgb(0,0,0);background-color:rgb(252,253,251)"> nll -= k(i)*<a href="http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341" title="Description not yet available." target="_blank" style="color:rgb(70,101,162);text-decoration:none">log</a>(lambda(i))+lambda(i)+<a href="http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995" title="Log gamma function." target="_blank" style="color:rgb(70,101,162);text-decoration:none">gammln</a>(k(i)+1.);</pre></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 30, 2014 at 6:57 PM, Carlos Martorell <span dir="ltr"><<a href="mailto:martorell@ciencias.unam.mx" target="_blank">martorell@ciencias.unam.mx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div>After checking the output of an ADMB run I believe that I have found a problem in (at least) a couple of the functions used to calculate the negative log-likelihoods in dpois and dnbinom functions in the statsLib.h library. When a vector of parameters (lambdas in the Poisson case) is provided, the code for the log-likelihood is</div><div><br></div><div><pre style="font-family:monospace,fixed;font-size:9pt;border:1px solid rgb(214,229,196);padding:4px 6px;margin:4px 8px 4px 2px;overflow:auto;word-wrap:break-word;line-height:15px;color:rgb(0,0,0);background-color:rgb(252,253,251)">00067 <a href="http://admb-project.org/documentation/api/classdvariable.html" title="Fundamental data type for reverse mode automatic differentiation." style="color:rgb(70,101,162);text-decoration:none" target="_blank">dvariable</a> <a href="http://admb-project.org/documentation/api/dpois_8cpp.html#a64d2001c40c90f8295bd86ea88ff6979" style="color:rgb(70,101,162);text-decoration:none" target="_blank">dpois</a>(<span style="color:rgb(0,128,0)">const</span> <a href="http://admb-project.org/documentation/api/classdvector.html" title="Vector of double precision numbers." style="color:rgb(70,101,162);text-decoration:none" target="_blank">dvector</a>& k, <span style="color:rgb(0,128,0)">const</span> <a href="http://admb-project.org/documentation/api/classdvar__vector.html" title="Description not yet available." style="color:rgb(70,101,162);text-decoration:none" target="_blank">dvar_vector</a>& lambda)
<a name="148ccdcf03885333_l00068" style="color:rgb(103,140,61)"></a>00068 {
<a name="148ccdcf03885333_l00069" style="color:rgb(103,140,61)"></a>00069 <a href="http://admb-project.org/documentation/api/group__RA.html#ga9616d0c80845da3942a30acbb1dbbfa9" title="Increments gradient_structure::RETURN_ARRAYS_PTR." style="color:rgb(70,101,162);text-decoration:none" target="_blank">RETURN_ARRAYS_INCREMENT</a>();
<a name="148ccdcf03885333_l00070" style="color:rgb(103,140,61)"></a>00070 <span style="color:rgb(96,64,32)">int</span> i;
<a name="148ccdcf03885333_l00071" style="color:rgb(103,140,61)"></a>00071 <span style="color:rgb(96,64,32)">int</span> n = <a href="http://admb-project.org/documentation/api/dsize_8cpp.html#aa42ba747b253f027435b478a7d747f52" title="Description not yet available." style="color:rgb(70,101,162);text-decoration:none" target="_blank">size_count</a>(k);
<a name="148ccdcf03885333_l00072" style="color:rgb(103,140,61)"></a>00072 <a href="http://admb-project.org/documentation/api/classdvariable.html" title="Fundamental data type for reverse mode automatic differentiation." style="color:rgb(70,101,162);text-decoration:none" target="_blank">dvariable</a> nll=0;
<a name="148ccdcf03885333_l00073" style="color:rgb(103,140,61)"></a>00073 <span style="color:rgb(224,128,0)">for</span>(i = 1; i <= n; i++)
<a name="148ccdcf03885333_l00074" style="color:rgb(103,140,61)"></a>00074 {
<a name="148ccdcf03885333_l00075" style="color:rgb(103,140,61)"></a>00075 nll -= k(i)*<a href="http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341" title="Description not yet available." style="color:rgb(70,101,162);text-decoration:none" target="_blank">log</a>(lambda(i))+lambda(i)+<a href="http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995" title="Log gamma function." style="color:rgb(70,101,162);text-decoration:none" target="_blank">gammln</a>(k(i)+1.);
<a name="148ccdcf03885333_l00076" style="color:rgb(103,140,61)"></a>00076 }
<a name="148ccdcf03885333_l00077" style="color:rgb(103,140,61)"></a>00077 <a href="http://admb-project.org/documentation/api/group__RA.html#ga780ea9f1c9038a5116c28140166d6e7e" title="Decrements gradient_structure::RETURN_ARRAYS_PTR." style="color:rgb(70,101,162);text-decoration:none" target="_blank">RETURN_ARRAYS_DECREMENT</a>();
<a name="148ccdcf03885333_l00078" style="color:rgb(103,140,61)"></a>00078 <span style="color:rgb(224,128,0)">return</span> nll;
<a name="148ccdcf03885333_l00079" style="color:rgb(103,140,61)"></a>00079 }</pre><div>I believe that the correct code for line 00075 should be</div><div> </div><div><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;background-color:rgb(252,253,251)">nll -= -k(i)*</span><a href="http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341" title="Description not yet available." style="font-family:monospace,fixed;font-size:9pt;line-height:15px;color:rgb(70,101,162);text-decoration:none" target="_blank">log</a><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;background-color:rgb(252,253,251)">(lambda(i))+lambda(i)+</span><a href="http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995" title="Log gamma function." style="font-family:monospace,fixed;font-size:9pt;line-height:15px;color:rgb(70,101,162);text-decoration:none" target="_blank">gammln</a><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;background-color:rgb(252,253,251)">(k(i)+1.);</span></div><div><span style="color:rgb(0,0,0);font-family:monospace,fixed;font-size:9pt;line-height:15px;background-color:rgb(252,253,251)"><br></span></div><div><font color="#000000" face="monospace, fixed"><span style="font-size:11.8181819915771px;line-height:15px;background-color:rgb(252,253,251)">This is evident in the same function when lambda is constant, e.g., </span></font></div><div><font color="#000000" face="monospace, fixed"><span style="font-size:11.8181819915771px;line-height:15px;background-color:rgb(252,253,251)"><br></span></font></div><div><pre style="font-family:monospace,fixed;font-size:9pt;border:1px solid rgb(214,229,196);padding:4px 6px;margin:4px 8px 4px 2px;overflow:auto;word-wrap:break-word;line-height:15px;color:rgb(0,0,0);background-color:rgb(252,253,251)"><a href="http://admb-project.org/documentation/api/statsLib_8h.html#a64d2001c40c90f8295bd86ea88ff6979" style="color:rgb(70,101,162);text-decoration:none" target="_blank">00035</a> <a href="http://admb-project.org/documentation/api/classdvariable.html" title="Fundamental data type for reverse mode automatic differentiation." style="color:rgb(70,101,162);text-decoration:none" target="_blank">dvariable</a> <a href="http://admb-project.org/documentation/api/dpois_8cpp.html#a64d2001c40c90f8295bd86ea88ff6979" style="color:rgb(70,101,162);text-decoration:none" target="_blank">dpois</a>(<span style="color:rgb(0,128,0)">const</span> <span style="color:rgb(96,64,32)">double</span>& k, <span style="color:rgb(0,128,0)">const</span> <a href="http://admb-project.org/documentation/api/classprevariable.html" title="Base class for dvariable." style="color:rgb(70,101,162);text-decoration:none" target="_blank">prevariable</a>& lambda)
<a name="148ccdcf03885333_l00036" style="color:rgb(103,140,61)"></a>00036 {
<a name="148ccdcf03885333_l00037" style="color:rgb(103,140,61)"></a>00037 <a href="http://admb-project.org/documentation/api/group__RA.html#ga9616d0c80845da3942a30acbb1dbbfa9" title="Increments gradient_structure::RETURN_ARRAYS_PTR." style="color:rgb(70,101,162);text-decoration:none" target="_blank">RETURN_ARRAYS_INCREMENT</a>();
<a name="148ccdcf03885333_l00038" style="color:rgb(103,140,61)"></a>00038 <a href="http://admb-project.org/documentation/api/classdvariable.html" title="Fundamental data type for reverse mode automatic differentiation." style="color:rgb(70,101,162);text-decoration:none" target="_blank">dvariable</a> tmp = -k*<a href="http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341" title="Description not yet available." style="color:rgb(70,101,162);text-decoration:none" target="_blank">log</a>(lambda)+lambda + <a href="http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995" title="Log gamma function." style="color:rgb(70,101,162);text-decoration:none" target="_blank">gammln</a>(k+1.);
<a name="148ccdcf03885333_l00039" style="color:rgb(103,140,61)"></a>00039 <a href="http://admb-project.org/documentation/api/group__RA.html#ga780ea9f1c9038a5116c28140166d6e7e" title="Decrements gradient_structure::RETURN_ARRAYS_PTR." style="color:rgb(70,101,162);text-decoration:none" target="_blank">RETURN_ARRAYS_DECREMENT</a>();
<a name="148ccdcf03885333_l00040" style="color:rgb(103,140,61)"></a>00040 <span style="color:rgb(224,128,0)">return</span> tmp;
<a name="148ccdcf03885333_l00041" style="color:rgb(103,140,61)"></a>00041 }</pre></div><div>I found these codes both in the ADMB version that I downloaded and in the package documentation (<a href="http://admb-project.org/documentation/api/dpois_8cpp_source.html" target="_blank">http://admb-project.org/documentation/api/dpois_8cpp_source.html</a>). After making the correction that I propose above and re-running ADMB, the program reports the correct log-likelihoods. The same problem can be found in dnbinom and maybe in other functions.</div><div>Given that the functions provided for the estimation of negative log-likelihoods are widely used, it would be important to check that their outputs are correct.</div><div>Best,</div><div><br></div><div><br></div><div><br></div>-- <br><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px"> I think [the island's] unusually sterile character gives it a grandeur <br> which more vegetation might have spoiled. </span><div><font face="Arial, Helvetica, sans-serif"> ----Ch. Darwin. El diario del Beagle </font><br><font face="Arial, Helvetica, sans-serif"> </font><br><font face="Arial, Helvetica, sans-serif">Dr. Carlos Martorell </font><br><font face="Arial, Helvetica, sans-serif"> </font><br><font face="Arial, Helvetica, sans-serif">Departamento de Ecología y Recursos Naturales </font><br><font face="Arial, Helvetica, sans-serif">Facultad de Ciencias-UNAM </font><br><font face="Arial, Helvetica, sans-serif">Circuito Exterior S/N, Cd. Universitaria </font><br><font face="Arial, Helvetica, sans-serif">04510 México D.F. </font><br><font face="Arial, Helvetica, sans-serif">Tel. (55) 5622 4835 Fax (55) 5622 4828 </font><br><font color="#0000ff" face="Arial, Helvetica, sans-serif"><a href="http://www.fciencias.unam.mx/investigacion/grupos/biologia/ecologia/ambientesl" target="_blank">http://www.fciencias.unam.mx/investigacion/grupos/biologia/ecologia/ambientesl</a></font></div>
</div></div>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@admb-project.org">Users@admb-project.org</a><br>
<a href="http://lists.admb-project.org/mailman/listinfo/users" target="_blank">http://lists.admb-project.org/mailman/listinfo/users</a><br>
<br></blockquote></div><br></div>