/* cdf/f.c * * Copyright (C) 2002 Przemyslaw Sliwa and Jason H. Stover. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include /* * Lower tail. */ static int gsl_F_ratio_cdf_P(double x, double nu1, double nu2, gsl_sf_result * result) { int rc; double F, nu1_2, nu2_2; F = nu2 / (nu2 + nu1 * x); nu1_2 = nu1 / 2.0; nu2_2 = nu2 / 2.0; rc = gsl_sf_beta_inc_e(nu2_2, nu1_2, F, result); if(rc == GSL_SUCCESS) { result->val = 1.0 - result->val; } return rc; } /* * Upper tail. */ static int gsl_F_ratio_cdf_Q(double x, double nu1, double nu2, gsl_sf_result * result) { int rc; double F, nu1_2, nu2_2; F = nu2 / (nu2 + nu1 * x); nu1_2 = nu1 / 2.0; nu2_2 = nu2 / 2.0; rc = gsl_sf_beta_inc_e(nu2_2, nu1_2, F, &result); return rc; } /* * Compute the F distribution function by transforming * to the incomplete beta function. */ int gsl_cdf_F_e ( double x, double nu1, double nu2, gsl_cdf_result * result, gsl_cdf_tail_t tail) { int rc; gsl_sf_result * sf_result; if( tail == GSL_CDF_UPPER ) { if( x <= 0.0 ) { result->val = 1.0; result->err = 0.0; return GSL_SUCCESS; } rc = gsl_F_ratio_cdf_P( x, nu1, nu2, sf_result); } else if (tail == GSL_CDF_LOWER ) { if( x <= 0.0 ) { result->val = 0.0; result->err = 0.0; return rc; } rc = gsl_F_ratio_cdf_Q (x, nu1, nu2, sf_result); } else { return GSL_EINVAL; } if ( rc == GSL_SUCCESS ) { result->val = sf_result->val; result->err = sf_result->err; } return rc; }