Skip to content

Commit

Permalink
Fix case where non-centrality parameter for chi-squared is zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzmaddock committed Sep 4, 2015
1 parent 9d3d2e9 commit a0f0b96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ namespace boost
BOOST_MATH_STD_USING
value_type result;
if(l == 0)
result = cdf(boost::math::chi_squared_distribution<RealType, Policy>(k), x);
return invert == false ? cdf(boost::math::chi_squared_distribution<RealType, Policy>(k), x) : cdf(complement(boost::math::chi_squared_distribution<RealType, Policy>(k), x));
else if(x > k + l)
{
// Complement is the smaller of the two:
Expand Down
20 changes: 20 additions & 0 deletions test/test_chi_squared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using ::boost::math::concepts::real_concept;

#include <boost/math/distributions/chi_squared.hpp> // for chi_squared_distribution
#include <boost/math/distributions/non_central_chi_squared.hpp> // for chi_squared_distribution
using boost::math::chi_squared_distribution;
using boost::math::chi_squared;

Expand Down Expand Up @@ -70,6 +71,25 @@ void test_spot(
BOOST_CHECK_CLOSE(
quantile(complement(dist, Q)), cs, tol);
}

boost::math::non_central_chi_squared_distribution<RealType> dist2(df, 0);
BOOST_CHECK_CLOSE(
cdf(dist2, cs), P, tol);
BOOST_CHECK_CLOSE(
pdf(dist2, cs), naive_pdf(dist2.degrees_of_freedom(), cs), tol);
if((P < 0.99) && (Q < 0.99))
{
//
// We can only check this if P is not too close to 1,
// so that we can guarentee Q is free of error:
//
BOOST_CHECK_CLOSE(
cdf(complement(dist2, cs)), Q, tol);
BOOST_CHECK_CLOSE(
quantile(dist2, P), cs, tol);
BOOST_CHECK_CLOSE(
quantile(complement(dist2, Q)), cs, tol);
}
}

//
Expand Down

0 comments on commit a0f0b96

Please sign in to comment.