inline RealType quantile(const chi_squared_distribution<RealType, Policy>& dist, const RealType& p) { RealType degrees_of_freedom = dist.degrees_of_freedom(); static const char* function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)"; // Error check: RealType error_result; if(false == detail::check_df( function, degrees_of_freedom, &error_result, Policy()) && detail::check_probability( function, p, &error_result, Policy())) return error_result; return 2 * boost::math::gamma_p_inv(degrees_of_freedom / 2, p, Policy()); } // quantile
inline RealType cdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square) { RealType degrees_of_freedom = dist.degrees_of_freedom(); // Error check: RealType error_result; static const char* function = "lslboost::math::cdf(const chi_squared_distribution<%1%>&, %1%)"; if(false == detail::check_df( function, degrees_of_freedom, &error_result, Policy())) return error_result; if((chi_square < 0) || !(lslboost::math::isfinite)(chi_square)) { return policies::raise_domain_error<RealType>( function, "Chi Square parameter was %1%, but must be > 0 !", chi_square, Policy()); } return lslboost::math::gamma_p(degrees_of_freedom / 2, chi_square / 2, Policy()); } // cdf
RealType pdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square) { BOOST_MATH_STD_USING // for ADL of std functions RealType degrees_of_freedom = dist.degrees_of_freedom(); // Error check: RealType error_result; static const char* function = "lslboost::math::pdf(const chi_squared_distribution<%1%>&, %1%)"; if(false == detail::check_df( function, degrees_of_freedom, &error_result, Policy())) return error_result; if((chi_square < 0) || !(lslboost::math::isfinite)(chi_square)) { return policies::raise_domain_error<RealType>( function, "Chi Square parameter was %1%, but must be > 0 !", chi_square, Policy()); } if(chi_square == 0) { // Handle special cases: if(degrees_of_freedom < 2) { return policies::raise_overflow_error<RealType>( function, 0, Policy()); } else if(degrees_of_freedom == 2) { return 0.5f; } else { return 0; } } return gamma_p_derivative(degrees_of_freedom / 2, chi_square / 2, Policy()) / 2; } // pdf
inline RealType mode(const chi_squared_distribution<RealType, Policy>& dist) { RealType df = dist.degrees_of_freedom(); static const char* function = "lslboost::math::mode(const chi_squared_distribution<%1%>&)"; // Most sources only define mode for df >= 2, // but for 0 <= df <= 2, the pdf maximum actually occurs at random variate = 0; // So one could extend the definition of mode thus: //if(df < 0) //{ // return policies::raise_domain_error<RealType>( // function, // "Chi-Squared distribution only has a mode for degrees of freedom >= 0, but got degrees of freedom = %1%.", // df, Policy()); //} //return (df <= 2) ? 0 : df - 2; if(df < 2) return policies::raise_domain_error<RealType>( function, "Chi-Squared distribution only has a mode for degrees of freedom >= 2, but got degrees of freedom = %1%.", df, Policy()); return df - 2; }
inline RealType kurtosis_excess(const chi_squared_distribution<RealType, Policy>& dist) { RealType df = dist.degrees_of_freedom(); return 12 / df; }
inline RealType skewness(const chi_squared_distribution<RealType, Policy>& dist) { BOOST_MATH_STD_USING // For ADL RealType df = dist.degrees_of_freedom(); return sqrt (8 / df); // == 2 * sqrt(2 / df); }
inline RealType variance(const chi_squared_distribution<RealType, Policy>& dist) { // Variance of Chi-Squared distribution = 2v. return 2 * dist.degrees_of_freedom(); } // variance
inline RealType mean(const chi_squared_distribution<RealType, Policy>& dist) { // Mean of Chi-Squared distribution = v. return dist.degrees_of_freedom(); } // mean