/// Error function erf(x). erf(x) = 2/sqrt(pi) * integral (0 to x) { exp(-t^2) dt } /// @param x input argument /// @return erf(x) double errorFunc(const double& x) throw(Exception) { if(x < 0) GPSTK_THROW(Exception("Negative first argument")); try { return (x < 0.0 ? -incompGamma(0.5,x*x) : incompGamma(0.5,x*x)); } catch(Exception& e) { GPSTK_RETHROW(e); } }
/// Error function erf(x). erf(x) = 2/sqrt(pi) * integral (0 to x) { exp(-t^2) dt } /// @param double x input argument /// @return erf(x) double errorFunc(const double& x) throw(Exception) { if(x < 0) { Exception e("Negative first argument in errorFunc()"); GPSTK_THROW(e); } try { return (x < 0.0 ? -incompGamma(0.5,x*x) : incompGamma(0.5,x*x)); } catch(Exception& e) { e.addText("Called by errorFunc()"); GPSTK_RETHROW(e); } }
/// Cumulative distribution function (CDF) of the Chi-square-distribution. /// Ref http://www.itl.nist.gov/div898/handbook/ 1.3.6.6.6 /// @param x input statistic value, the RSS of variances, X >= 0 /// @param n degrees of freedom of sample, n > 0 /// @return probability that the sample variance is less than X. double ChisqCDF(const double& x, const int& n) throw(Exception) { if(x < 0) GPSTK_THROW(Exception("Negative statistic")); if(n <= 0) GPSTK_THROW(Exception("Non-positive degrees of freedom")); try { // NB this incompGamma(n/2,x/2) == NIST's incompGamma(n/2,x/2)/Gamma(n/2) return incompGamma(double(n)/2.0,x/2.0); } catch(Exception& e) { GPSTK_RETHROW(e); } }
/// Chi-square probability function. ChisqProbability(xsq,n) is defined as the /// probability that the observed chi-squared for a correct model with n degrees /// of freedom should be less than the value xsq. /// @param double xsq input value for chi-squared, xsq > 0 /// @param int n input value for number of degrees of freedom, n > 0 /// @return Chi-squared probability (xsq,n) double ChisqProbability(const double& x, const int& n) throw(Exception) { if(x <= 0) { Exception e("Non-positive chi-sq argument in ChisqProbability()"); GPSTK_THROW(e); } if(n < 0) { Exception e("Non-positive degrees of freedom in ChisqProbability()"); GPSTK_THROW(e); } return incompGamma(double(n)/2.0,x/2.0); }