Opened 7 years ago
Closed 7 years ago
#11557 closed Bugs (fixed)
cdf error with non-central chi-squared with ncp = 0
| Reported by: | Owned by: | John Maddock | |
|---|---|---|---|
| Milestone: | Boost 1.60.0 | Component: | math |
| Version: | Boost 1.59.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
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.
Change History (4)
comment:1 by , 7 years ago
| Component: | None → math |
|---|---|
| Owner: | set to |
comment:2 by , 7 years ago
| Version: | Boost 1.57.0 → Boost 1.59.0 |
|---|
comment:3 by , 7 years ago
comment:4 by , 7 years ago
| Milestone: | To Be Determined → Boost 1.60.0 |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.

Will investigate, thanks for the report.