Subject: [Boost-bugs] [Boost C++ Libraries] #11557: cdf error with non-central chi-squared with ncp = 0
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-08-19 19:12:24
#11557: cdf error with non-central chi-squared with ncp = 0
------------------------------------+------------------------------
Reporter: Mark Abney <maabney@â¦> | Type: Bugs
Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.57.0
Severity: Problem | Keywords:
------------------------------------+------------------------------
The complement of the cdf of the non-central chi-squared distribution with
non-centrality parameter = 0 should return the same value as the standard
(i.e. central) chi-squared distribution. For ncp very small, this happens,
but when ncp = 0 it returns the negative of the (non-complement) cdf.
Example code:
{{{
#include <iostream>
#include <boost/math/distributions.hpp>
using std::cout;
using std::cin;
using std::endl;
using boost::math::chi_squared;
int main(int argc, char *argv[])
{
double df = 4, quantile = 12;
cout << "df = " << df << endl;
cout << "quantile = " << quantile << endl;
chi_squared chi(df);
cout << "chi.df = " << chi.degrees_of_freedom() << endl;
cout << "P(X <= " << quantile << ") = " << cdf(chi, quantile) << endl;
cout << "P(X > " << quantile << ") = " << cdf(complement(chi,
quantile)) << endl;
double ncp1 = 1e-300;
double ncp2 = 0;
boost::math::non_central_chi_squared nchi1(df, ncp1);
boost::math::non_central_chi_squared nchi2(df, ncp2);
cout << "nchi1.df = " << nchi1.degrees_of_freedom()
<< "; nchi1.ncp = " << nchi1.non_centrality() << endl;
cout << "P(X <= " << quantile << ") = " << cdf(nchi1, quantile) <<
endl;
cout << "P(X > " << quantile << ") = " << cdf(complement(nchi1,
quantile)) << endl;
cout << "nchi2.df = " << nchi2.degrees_of_freedom()
<< "; nchi2.ncp = " << nchi2.non_centrality() << endl;
cout << "P(X <= " << quantile << ") = " << cdf(nchi2, quantile) <<
endl;
cout << "P(X > " << quantile << ") = " << cdf(complement(nchi2,
quantile)) << endl;
return 0;
}
}}}
Note the output lines P(X > 12), which should all be equal. In the first
two cases this is correct, but in the last one P(X > 12) = - P(X <= 12),
which is necessarily wrong.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11557> 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:18 UTC