Boost C++ Libraries: Ticket #9834: Negative Binomial Distribution: degenerate cases https://svn.boost.org/trac10/ticket/9834 <p> In the following calculations (please see code included below), the 4 results cannot be all correct at the same time. </p> <p> Also, if one will to uncomment the last block of code, one would find that its calculation would fail. </p> <p> <strong>Thoughts:</strong> </p> <ul><li>Now when the probability of "success" p0 (you used p in your documentation) is 1, shouldn't the value of the corresponding random variable be simply 0? If so, shouldn't the quantiles at p=0 and p=1 be both at 0? </li></ul><ul><li>Similarly, when p0 is 0, I would think it is quite "natural" to set/define the corresponding random variable to be one with mass 1 at infinity ... no need to work so hard to search for the zero as the error to the final calculation shows. </li></ul><p> Thank you.<br /> HS </p> <p> P.S. Please copy the included code to a test.cpp and then build with g++ -o test test.cpp. </p> <p> P.ps. If the evaluation policy will to change to ignore the error, it <em>appears</em> that the calculation never complete. Can something be done to prevent this? Suggestions? </p> <pre class="wiki">#define BOOST_MATH_DOMAIN_ERROR_POLICY ignore_error #define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error // #define BOOST_MATH_EVALUATION_ERROR_POLICY ignore_error #define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_up #include &lt;cstdlib&gt; #include &lt;cstdio&gt; #include &lt;boost/math/distributions/negative_binomial.hpp&gt; int main() { double _r0 = 3.0; double _p0 = 1.0; boost::math::negative_binomial_distribution&lt;&gt; _dist( _r0, _p0 ); std::printf( "\n" " r = %g\n" " p = %g\n\n", _r0, _p0 ); std::printf( " Quantile(%g;upperTail=false) = %g\n", 1.0, boost::math::quantile( _dist, 1.0 ) ); std::printf( " Quantile(%g;upperTail=true) = %g\n\n", 1.0, boost::math::quantile( boost::math::complement( _dist, 1.0 ) ) ); std::printf( " Quantile(%g;upperTail=false) = %g\n", 0.0, boost::math::quantile( _dist, 0.0 ) ); std::printf( " Quantile(%g;upperTail=true) = %g\n\n", 0.0, boost::math::quantile( boost::math::complement( _dist, 0.0 ) ) ); /* { _p0 = 0.0; boost::math::negative_binomial_distribution&lt;&gt; _dist( _r0, _p0 ); std::printf( "\n" " r = %g\n" " p = %g\n\n", _r0, _p0 ); std::printf( " Quantile(%g;upperTail=false) = %g\n", 0.32, boost::math::quantile( _dist, 0.32 ) ); } */ return EXIT_SUCCESS; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9834 Trac 1.4.3 John Maddock Sun, 06 Apr 2014 11:02:45 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9834#comment:1 https://svn.boost.org/trac10/ticket/9834#comment:1 <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> See <a class="ext-link" href="https://github.com/boostorg/math/commit/0c01f682eb9c562d3cca6372c0aa8e68951decd1"><span class="icon">​</span>https://github.com/boostorg/math/commit/0c01f682eb9c562d3cca6372c0aa8e68951decd1</a> </p> <p> I haven't made the quantile for probability 1 zero in the corner case you gave: rather it's always at infinity. I think this is more consistent, though there are an infinite number of "correct" answers for this case ;-) </p> Ticket HS <tan@…> Mon, 07 Apr 2014 03:24:49 GMT <link>https://svn.boost.org/trac10/ticket/9834#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9834#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9834#comment:1" title="Comment 1">johnmaddock</a>: </p> <blockquote class="citation"> <p> See <a class="ext-link" href="https://github.com/boostorg/math/commit/0c01f682eb9c562d3cca6372c0aa8e68951decd1"><span class="icon">​</span>https://github.com/boostorg/math/commit/0c01f682eb9c562d3cca6372c0aa8e68951decd1</a> </p> <p> I haven't made the quantile for probability 1 zero in the corner case you gave: rather it's always at infinity. I think this is more consistent, though there are an infinite number of "correct" answers for this case ;-) </p> </blockquote> <p> <br /> Dear John, </p> <p> Thank you (and your team) for the great work! </p> <p> I will not quibble with you about this---it is an edge case which is generally not very interesting in the applied world. However, as a teacher (was) of probability classes, the inverse CDF (or quantile) at p of a distribution F, to us, is the infimum of all x such that F(x) &gt;= p; in this degenerate case of a discrete distribution, this is 0. And one will also find this is so on R too: </p> <pre class="wiki">&gt; qnbinom(1,3,1,lower.tail=FALSE) [1] 0 &gt; qnbinom(1,3,1,lower.tail=TRUE) [1] 0 &gt; qnbinom(0,3,1,lower.tail=FALSE) [1] 0 &gt; qnbinom(0,3,1,lower.tail=TRUE) [1] 0 </pre><p> Mathmatica 9, on the other hand, says the following: </p> <pre class="wiki">In[1]:= Quantile[NegativeBinomialDistribution[3,1],0] Out[1]= 0 In[2]:= Quantile[NegativeBinomialDistribution[3,1],1] Out[2]= Infinity </pre><p> But it is very easy for anyone to work around the decision here if he or she disagrees with it. :) </p> <p> With best regards,<br /> HS </p> </description> <category>Ticket</category> </item> </channel> </rss>