[Boost-bugs] [Boost C++ Libraries] #9393: quantile for hypergeometric distribution - precision/rounding issue

Subject: [Boost-bugs] [Boost C++ Libraries] #9393: quantile for hypergeometric distribution - precision/rounding issue
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-11-14 21:07:39


#9393: quantile for hypergeometric distribution - precision/rounding issue
-------------------------------------+-------------------------
 Reporter: anonymous | Owner: johnmaddock
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: math
  Version: Boost Development Trunk | Severity: Showstopper
 Keywords: |
-------------------------------------+-------------------------
 Hi (John),

 This is the same as Ticket #9183
 (https://svn.boost.org/trac/boost/ticket/9183) but applies to the
 hypergeometric distribution. For example,

 {{{
 #define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_up

 #include <cstdio>
 #include <boost/math/distributions/hypergeometric.hpp>

 int main()
 {
    unsigned int xmin = 71;
    unsigned int length = 9;

    boost::math::hypergeometric_distribution<> dist( 79u, 101u, 109u );

    for ( unsigned int i = 0; i < length; ++i )
    {
       double x = xmin + i;
       double y =
          boost::math::cdf( dist, x );
          // boost::math::cdf( boost::math::complement( dist, x ) );

       std::printf(
             " x = %g\tCDF(x) = %f\tinverse-CDF(CDF(x)) = %g\n",
             x, y, boost::math::quantile( dist, y ) );
    }

    return 0;
 }
 }}}

 returns

 {{{
  x = 71 CDF(x) = 0.068671 inverse-CDF(CDF(x)) = 72
  x = 72 CDF(x) = 0.297575 inverse-CDF(CDF(x)) = 72
  x = 73 CDF(x) = 0.615846 inverse-CDF(CDF(x)) = 73
  x = 74 CDF(x) = 0.856699 inverse-CDF(CDF(x)) = 74
  x = 75 CDF(x) = 0.965083 inverse-CDF(CDF(x)) = 75
  x = 76 CDF(x) = 0.994746 inverse-CDF(CDF(x)) = 77
  x = 77 CDF(x) = 0.999561 inverse-CDF(CDF(x)) = 77
  x = 78 CDF(x) = 0.999985 inverse-CDF(CDF(x)) = 78
  x = 79 CDF(x) = 1.000000 inverse-CDF(CDF(x)) = 79
 }}}

 I was hoping/expecting to obtain:

 {{{
        x y z
  [1,] 71 0.06867117 71
  [2,] 72 0.29757505 72
  [3,] 73 0.61584552 73
  [4,] 74 0.85669885 74
  [5,] 75 0.96508285 75
  [6,] 76 0.99474584 76
  [7,] 77 0.99956126 77
  [8,] 78 0.99998459 78
  [9,] 79 1.00000000 79
 }}}
 which I was used to on R.

 Thank you!

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9393>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:14 UTC