Boost C++ Libraries: Ticket #8308: Poisson Quantile function returns wrong results in certain cases https://svn.boost.org/trac10/ticket/8308 <p> Sample use case: </p> <pre class="wiki">main() { double pi = 3.1415927; boost::math::poisson poisson(pi); // std::cout &lt;&lt; quantile(poisson, 0.00) &lt;&lt; " "; std::cout &lt;&lt; quantile(poisson, 0.05) &lt;&lt; " "; std::cout &lt;&lt; quantile(poisson, 0.30) &lt;&lt; " "; std::cout &lt;&lt; quantile(poisson, pi/6) &lt;&lt; " "; std::cout &lt;&lt; quantile(poisson, 0.7) &lt;&lt; " "; std::cout &lt;&lt; quantile(poisson, 1-1e-10) &lt;&lt; " "; // std:: cout &lt;&lt; quantile(poisson, 1) &lt;&lt; std::endl; } </pre><p> Produces the results (error), 0, 1, 3, 4, 20, (error) </p> <p> Similar code in R or MATLAB results in: (0),1,2,3,4,20,(Inf) </p> <pre class="wiki">R&gt; qpois(c(0,0.05,0.3,pi/6,0.7,1-1e-10,1),pi) [1] 0 1 2 3 4 20 Inf MATLAB&gt; f := stats::poissonQuantile(PI): MATLAB&gt; f(0), f(1/20), f(0.3), f(PI/6), f(0.7), f(1-1/10^10), f(1) 0,1,2,3,4,20,Inf </pre><p> The errors on the edge cases are less troubling than the seemingly incorrect results at low probabilities. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8308 Trac 1.4.3 John Maddock Wed, 20 Mar 2013 18:47:08 GMT <link>https://svn.boost.org/trac10/ticket/8308#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8308#comment:1</guid> <description> <p> I'll look into the edge cases (0 and 1) shortly - the differences in the other values you see are intended behaviour, given: </p> <pre class="wiki">poisson pd(constants::pi&lt;double&gt;()); </pre><p> then the default behaviour of: </p> <pre class="wiki">quantile(pd, 0.05) </pre><p> is to return the largest integer i such that <code>cdf(pd, i) &lt;= 0.05</code>, which really is the value 0, not 1 as the other programs suggest. </p> <p> Whether that is actually the correct thing to do depends upon the actual test you are conducting (I assume R and Mathlab calculate the quantile as a real-value and then round to the nearest int). You can configure Boost.Math to do whatever you want here, see: <a href="http://www.boost.org/doc/libs/1_53_0/libs/math/doc/sf_and_dist/html/math_toolkit/policy/pol_tutorial/understand_dis_quant.html">http://www.boost.org/doc/libs/1_53_0/libs/math/doc/sf_and_dist/html/math_toolkit/policy/pol_tutorial/understand_dis_quant.html</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 21 Mar 2013 13:01:56 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8308#comment:2 https://svn.boost.org/trac10/ticket/8308#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/83512" title="Fix edge case in Halley iteration where the derivative is flatlining. ...">[83512]</a>) Fix edge case in Halley iteration where the derivative is flatlining. Fix edge cases in poisson distribution quantile. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8314" title="#8314: Bugs: ibeta error for fisher f distribution (closed: fixed)">#8314</a>. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8308" title="#8308: Bugs: Poisson Quantile function returns wrong results in certain cases (closed: fixed)">#8308</a>. Update and regenerate docs. </p> Ticket